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)
Bytes to hex string.
|
static <B,D> D |
cast(B b1,
Class<D> cls)
Casts an object to the class or interface represented by the specified
Class object.
|
static String |
collectionToCommaSeparatedString(Collection<String> elementCollection)
Collection to comma separated string string.
|
static <T> T[] |
concat(T[] left,
T[] right)
Concatenates two Java arrays.
|
static byte[] |
decode(byte[] ascii)
Decodes ASCII byte stream into binary format.
|
static Serializable |
deserializeObject(byte[] bytes)
Deserializes an object instance.
|
static String |
duplicateStringWithDelimiter(String arg,
char separator,
int numberOfDuplications)
Duplicate string with delimiter string.
|
static byte[] |
encode(byte[] binary)
Encodes binary byte stream to ASCII format.
|
static String |
getResourcesPath(String resourceName)
Gets resources path.
|
static String |
getStackTrace(Throwable throwable)
Gets stack trace.
|
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)
Is equal object boolean.
|
static String |
listToSeparatedString(List<String> list,
char separator)
Converts array of strings to string separated with specified character.
|
static <T,S> void |
mergeEntryInList(T key,
S value,
List<Map<T,S>> target)
Merge entry in list.
|
static <T> List<T> |
mergeLists(List<T> target,
List<T> source)
Merge lists list.
|
static <T,S> List<Map<T,S>> |
mergeListsOfMap(List<Map<T,S>> target,
List<Map<T,S>> source)
Merge lists of map list.
|
static <T,S> Map<T,S> |
mergeMaps(Map<T,S> target,
Map<T,S> source)
Merge maps map.
|
static <T> T |
newInstance(Class<T> cls)
New instance t.
|
static Object |
newInstance(String classname)
New instance object.
|
static <T> T |
newInstance(String classname,
Class<T> cls)
New instance t.
|
static String |
nextUuId()
Gets an universally unique identifier (UUID).
|
static String |
printStackTrace()
Print stack trace string.
|
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)
To single element set set.
|
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 byte[] encode(byte[] binary)
binary
- An Java array of bytes in binary format.#decode(byte[])
public static byte[] decode(byte[] ascii)
ascii
- An Java array of bytes in ASCII format.#encode(byte[])
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
- the type parameterleft
- 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 b1, Class<D> cls)
B
- the type parameterD
- the type parameterb1
- 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 Object newInstance(String classname)
classname
- the classnamepublic static <T> T newInstance(String classname, Class<T> cls)
T
- the type parameterclassname
- the classnamecls
- the clspublic static <T> T newInstance(Class<T> cls)
T
- the type parametercls
- the clspublic static String getResourcesPath(String resourceName)
resourceName
- the resource namepublic static String getStackTrace(Throwable throwable)
throwable
- the throwablepublic static String printStackTrace()
public static boolean isEqualObject(Object obj1, Object obj2)
obj1
- the obj 1obj2
- the obj 2public static String arrayToCommaSeparatedString(String[] arr)
arr
- array of stringspublic static String collectionToCommaSeparatedString(Collection<String> elementCollection)
elementCollection
- the element collectionpublic static String arrayToSeparatedString(String[] arr, char separator)
arr
- array of stringsseparator
- the separatorpublic static String listToSeparatedString(List<String> list, char separator)
list
- array of stringsseparator
- the separatorpublic static String duplicateStringWithDelimiter(String arg, char separator, int numberOfDuplications)
arg
- the argseparator
- the separatornumberOfDuplications
- the number of duplicationspublic static String bytesToHex(byte[] bytes)
bytes
- the bytespublic 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 Setpublic static <T,S> List<Map<T,S>> mergeListsOfMap(List<Map<T,S>> target, List<Map<T,S>> source)
T
- the type parameterS
- the type parametertarget
- the targetsource
- the sourcepublic static <T> List<T> mergeLists(List<T> target, List<T> source)
T
- the type parametertarget
- the targetsource
- the sourcepublic static <T,S> void mergeEntryInList(T key, S value, List<Map<T,S>> target)
T
- the type parameterS
- the type parameterkey
- the keyvalue
- the valuetarget
- the targetCopyright © 2017. All rights reserved.