public class CommonMethods extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
arrayToCommaSeparatedString(String[] arr)
Converts array of strings to comma-separated string.
|
static String |
arrayToSeparatedString(String[] arr,
char separator)
Converts array of strings to string separated with specified character.
|
static String |
bytesToHex(byte[] bytes) |
static <B,D> D |
cast(B b,
Class<D> cls)
Casts an object to the class or interface represented by the specified
Class object.
|
static String |
collectionToCommaSeparatedString(Collection<String> elementCollection) |
static <T> T[] |
concat(T[] left,
T[] right)
Concatenates two Java arrays.
|
static Serializable |
deserializeObject(byte[] bytes)
Deserializes an object instance.
|
static String |
duplicateStringWithDelimiter(String arg,
char separator,
int numberOfDuplications) |
static String |
getResourcesPath(String resourceName) |
static String |
getStackTrace(Throwable t) |
static boolean |
isEmpty(byte[] byteArray)
Checks whether the given Object is empty.
|
static boolean |
isEmpty(Collection<?> collection)
Checks whether the given collection is empty.
|
static boolean |
isEmpty(Map<?,?> map)
Checks whether the given map is empty.
|
static boolean |
isEmpty(Object obj)
Checks whether the given Object is empty.
|
static boolean |
isEmpty(Object[] array)
Checks whether the given Java array is empty.
|
static boolean |
isEmpty(String str)
Checks whether the given String is empty.
|
static boolean |
isEqualObject(Object obj1,
Object obj2) |
static <T> List<T> |
iteratorToList(Iterable<T> iter) |
static String |
listToSeparatedString(List<String> list,
char separator)
Converts array of strings to string separated with specified character.
|
static <T> T |
newInstance(Class<T> cls) |
static Object |
newInstance(String classname) |
static <T> T |
newInstance(String classname,
Class<T> cls) |
static String |
nextUUID()
Gets an universally unique identifier (UUID).
|
static String |
printStackTrace() |
static byte[] |
serializeObject(Serializable object)
Serializes an object instance into byte array.
|
static <T> T[] |
toArray(Collection<? extends T> col,
Class<T> type)
Converts a collection to Java array.
|
static long[] |
toPrimitive(Long[] array)
Converts the array with Long elements to the array with long (primitive
type)
|
static <T> Set<T> |
toSingleElementSet(T element) |
public static byte[] serializeObject(Serializable object)
object - An instance to be serialized.deserializeObject(byte[])public static Serializable deserializeObject(byte[] bytes)
bytes - Java array of bytes.serializeObject(Serializable)public static boolean isEmpty(Object obj)
obj - Object to be checked.public static boolean isEmpty(byte[] byteArray)
byteArray - Object to be checked.public static boolean isEmpty(String str)
str - String object to be checked.public static boolean isEmpty(Object[] array)
array - Java array to be checked.public static boolean isEmpty(Collection<?> collection)
collection - A collection to be checked.public static boolean isEmpty(Map<?,?> map)
map - A map to be checked.public static long[] toPrimitive(Long[] array)
array - input array with Long elementspublic static <T> T[] toArray(Collection<? extends T> col, Class<T> type)
T - Java type of the collection element.col - Collection to be converted to arraytype - Java type of collection/array elementpublic static String nextUUID()
public static <T> T[] concat(T[] left,
T[] right)
T - left+rightleft - Elements of this array will be copied to positions from 0 to left.length -
1 in the target array.right - Elements of this array will be copied to positions from left.length to
left.length + right.lengthpublic static <B,D> D cast(B b,
Class<D> cls)
B - origin instanceD - casted instanceb - An object instance to be casted to the specified Java type.cls - Target Java type.ClassCastException - In case which is the given object is not instance of the specified
Java type.public static <T> T newInstance(Class<T> cls)
public static String printStackTrace()
public static String arrayToCommaSeparatedString(String[] arr)
arr - array of stringspublic static String collectionToCommaSeparatedString(Collection<String> elementCollection)
public static String arrayToSeparatedString(String[] arr, char separator)
arr - array of stringsseparator - separatorpublic static String listToSeparatedString(List<String> list, char separator)
list - array of stringsseparator - separatorpublic static String duplicateStringWithDelimiter(String arg, char separator, int numberOfDuplications)
public static String bytesToHex(byte[] bytes)
public static <T> Set<T> toSingleElementSet(T element)
T - the class of the objects in the setelement - the single element to be contained in the returned SetCopyright © 2018. All rights reserved.