public final class ObjectUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
concat(java.util.Collection<?> c,
java.lang.String sep)
Concatenates a collections of anything into a string, using the provided
separator.
|
static java.lang.String |
concat(java.lang.Object[] arr,
java.lang.String sep)
Concatenates a array of anything into a string, using the provided
separator.
|
static <T> T |
createInstance(java.lang.String className,
java.lang.Class<T> type)
Creates a new instance of a class whose classname is provided as argument
to this method.
|
static <T> T |
createInstance(java.lang.String className,
java.lang.Class<T> type,
java.lang.ClassLoader classLoader) |
static java.lang.Object |
deserialize(java.lang.String b64)
De-serializes a base64 string into a Java object.
|
static <T> int |
indexOf(T[] arr,
T value)
Returns the index of an item within an array.
|
static boolean |
isHavingClass(java.lang.String className)
Checks if the specified class exists on the specified package.
|
static boolean |
isHavingMethod(java.lang.String className,
java.lang.String methodName)
Checks if the specified method exists on the specified class.
|
static boolean |
isHavingMethodWithArgCount(java.lang.String className,
java.lang.String methodName,
int argCount)
This method safely checks if a class with the provided name has a method
signature of the specified name taking the specified number of arguments.
|
static <T> T |
npeSafeCast(java.lang.Object obj) |
static java.lang.String |
serialize(java.io.Serializable s)
Serializes an object and encode the generated byte array with base64
encoder.
|
static <T> java.util.Enumeration<T> |
toEnumeration(T object)
Creates an
Enumeration containing the given object. |
static <T extends java.lang.Enum<T>> |
valueOf(java.lang.Class<T> type,
java.lang.String name,
T defaultValue)
This method provides a safer way to return an enum constant than using
Enum.valueOf . |
public static <T extends java.lang.Enum<T>> T valueOf(java.lang.Class<T> type, java.lang.String name, T defaultValue)
Enum.valueOf
.
The name is converted to upper-case, and space or dash chars are converted to under-score before we look-up the enum constant.
This method will not throw any exception.
type
- The enum typename
- The name of the enum constantdefaultValue
- The default value to returnpublic static <T> T npeSafeCast(java.lang.Object obj)
obj
- The object to castpublic static java.lang.String concat(java.lang.Object[] arr, java.lang.String sep)
arr
- The array of objects.sep
- The separatorpublic static java.lang.String concat(java.util.Collection<?> c, java.lang.String sep)
c
- The collectionsep
- The separatorpublic static java.lang.String serialize(java.io.Serializable s)
s
- The Serializable
object. if null, then null is returned.public static java.lang.Object deserialize(java.lang.String b64)
b64
- The string containing the base64 data.public static <T> int indexOf(T[] arr, T value)
We use the equals
method on the object to check the
equality.
arr
- The array of items. May be null.value
- The value itself. May be null.public static <T> T createInstance(java.lang.String className, java.lang.Class<T> type)
The class name argument can contain arguments that are passed to the constructor. Example:
className = com.acme.foo.MyClass('string arg',true,2,3);
This will result in that the constructor that takes 4 arguments (string, boolean, integer, integer) is used when creating the instance.
T
- The type of class to instantiate.className
- The class name or the classname including additional
arguments.type
- The type of class that is expectedpublic static <T> T createInstance(java.lang.String className, java.lang.Class<T> type, java.lang.ClassLoader classLoader)
T
- The type of class to instantiate.className
- The class name or the classname including additional
arguments.type
- The type of class that is expectedclassLoader
- The class loader to use when loading the class. If
null, the class loader used to load this class will be used.public static boolean isHavingMethodWithArgCount(java.lang.String className, java.lang.String methodName, int argCount)
This method catches all exceptions so you can safely use this method against a class that doesn't exist at runtime etc.
className
- The name of the class to look intomethodName
- The name of the method to search forargCount
- The number of arguments to look forpublic static boolean isHavingMethod(java.lang.String className, java.lang.String methodName)
className
- The name of the class to checkmethodName
- The name of the method to look for.public static boolean isHavingClass(java.lang.String className)
className
- The name of the class to checkpublic static <T> java.util.Enumeration<T> toEnumeration(T object)
Enumeration
containing the given object.object
- The object to Enumerate over.Copyright © Technia AB. All Rights Reserved.