public final class Util
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Util.MapKeyProvider<K,V>
Provides objects of type K, derived from a value of type V, for hashing said value via .hashCode().
|
static interface |
Util.PropertyWriter
Writes a property value
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FILE_SEPARATOR
The file separator for the current system
|
static java.lang.String |
LINE_SEPARATOR
The line separator for the current system
|
static java.lang.String |
PATH_SEPARATOR
The path separator for the current system
|
Modifier and Type | Method and Description |
---|---|
static void |
closeSilently(java.io.Closeable... closeables)
Closes the given Closeable instances, swallowing any Exceptions that occur
|
static <T> T |
deserialize(byte[] bytes)
Deserializes the given byte array into a T, null or an empty byte array result in a null return value
|
static long |
getAllocatedMemory() |
static long |
getFreeMemory() |
static java.lang.reflect.Method |
getGetMethod(java.lang.Class valueType,
java.lang.String property,
java.lang.Class ownerClass) |
static java.lang.reflect.Method |
getGetMethod(java.lang.Class valueType,
java.lang.String property,
java.lang.Object valueOwner) |
static long |
getMaxMemory() |
static java.lang.String |
getMemoryUsageString() |
static java.lang.reflect.Method |
getSetMethod(java.lang.Class valueType,
java.lang.String property,
java.lang.Class ownerClass) |
static java.lang.reflect.Method |
getSetMethod(java.lang.Class valueType,
java.lang.String property,
java.lang.Object valueOwner) |
static java.lang.String |
getSystemProperties() |
static java.lang.String |
getSystemProperties(Util.PropertyWriter propertyWriter) |
static long |
getUsedMemory() |
static <T> T |
initializeProxy(java.lang.Class<T> clazz,
java.lang.reflect.InvocationHandler invocationHandler)
Initializes a proxy instance for the given class, using the class loader of that class
|
static <K,V> java.util.LinkedHashMap<K,java.util.List<V>> |
map(java.util.Collection<V> values,
Util.MapKeyProvider<K,V> keyProvider)
Maps the given values according to the keys provided by the given key provider,
keeping the iteration order of the given collection.
|
static boolean |
notNull(java.lang.Object... objects)
Checks if any of the given objects is null
|
static boolean |
nullOrEmpty(java.util.Collection... collections) |
static boolean |
nullOrEmpty(java.util.Collection collection) |
static boolean |
nullOrEmpty(java.util.Map... maps) |
static boolean |
nullOrEmpty(java.util.Map map) |
static boolean |
nullOrEmpty(java.lang.String... strings) |
static boolean |
onClasspath(java.lang.String className) |
static java.lang.String |
rejectNullOrEmpty(java.lang.String value,
java.lang.String valueName)
Throws an IllegalArgumentException if the given string value is null or empty
|
static double |
roundDouble(double d,
int places)
Rounds the given double to
places decimal places |
static byte[] |
serialize(java.lang.Object object)
Serializes the given Object, null object results in an empty byte array
|
public static final java.lang.String LINE_SEPARATOR
public static final java.lang.String FILE_SEPARATOR
public static final java.lang.String PATH_SEPARATOR
public static boolean nullOrEmpty(java.lang.String... strings)
strings
- the strings to checkpublic static boolean notNull(java.lang.Object... objects)
objects
- the objects to checkpublic static <K,V> java.util.LinkedHashMap<K,java.util.List<V>> map(java.util.Collection<V> values, Util.MapKeyProvider<K,V> keyProvider)
class Person {
String name;
Integer age;
...
}
List<Person> persons = ...;
MapKeyProvider ageKeyProvider = new MapKeyProvider<Integer, Person>() {
public Integer getKey(Person person) {
return person.getAge();
}
};
Map<Integer, List<Person>> personsByAge = Util.map(persons, ageKeyProvider);
K
- the key typeV
- the value typevalues
- the values to mapkeyProvider
- the object providing keys for valuespublic static boolean onClasspath(java.lang.String className)
className
- the name of the class to search forpublic static boolean nullOrEmpty(java.util.Map... maps)
maps
- the maps to checkpublic static boolean nullOrEmpty(java.util.Map map)
map
- the map to checkpublic static boolean nullOrEmpty(java.util.Collection... collections)
collections
- the collections to checkpublic static boolean nullOrEmpty(java.util.Collection collection)
collection
- the collection to checkpublic static java.lang.String rejectNullOrEmpty(java.lang.String value, java.lang.String valueName)
value
- the string valuevalueName
- the name of the value to include in the error messagepublic static double roundDouble(double d, int places)
places
decimal placesd
- the double to roundplaces
- the number of decimal placespublic static void closeSilently(java.io.Closeable... closeables)
closeables
- the closeables to closepublic static java.lang.String getSystemProperties()
public static java.lang.String getSystemProperties(Util.PropertyWriter propertyWriter)
propertyWriter
- for specific property formatting or exclusionspublic static <T> T initializeProxy(java.lang.Class<T> clazz, java.lang.reflect.InvocationHandler invocationHandler)
T
- the typeclazz
- the class to proxyinvocationHandler
- the invocation handler to usepublic static byte[] serialize(java.lang.Object object) throws java.io.IOException
object
- the objectjava.io.IOException
- in case of an exceptionpublic static <T> T deserialize(byte[] bytes) throws java.io.IOException, java.lang.ClassNotFoundException
T
- the type of the object represented in the byte arraybytes
- a byte array representing the serialized objectjava.io.IOException
- in case of an exceptionjava.lang.ClassNotFoundException
- in case the deserialized class is not foundpublic static long getAllocatedMemory()
public static long getFreeMemory()
public static long getMaxMemory()
public static long getUsedMemory()
public static java.lang.String getMemoryUsageString()
public static java.lang.reflect.Method getSetMethod(java.lang.Class valueType, java.lang.String property, java.lang.Object valueOwner) throws java.lang.NoSuchMethodException
valueType
- the class of the value for the given propertyproperty
- the name of the property for which to retrieve the set methodvalueOwner
- an instancejava.lang.NoSuchMethodException
- if the method does not exist in the owner classpublic static java.lang.reflect.Method getSetMethod(java.lang.Class valueType, java.lang.String property, java.lang.Class ownerClass) throws java.lang.NoSuchMethodException
valueType
- the class of the value for the given propertyproperty
- the name of the property for which to retrieve the set methodownerClass
- the classjava.lang.NoSuchMethodException
- if the method does not exist in the owner classpublic static java.lang.reflect.Method getGetMethod(java.lang.Class valueType, java.lang.String property, java.lang.Object valueOwner) throws java.lang.NoSuchMethodException
valueType
- the class of the value for the given propertyproperty
- the name of the property for which to retrieve the get methodvalueOwner
- an instancejava.lang.NoSuchMethodException
- if the method does not exist in the owner classpublic static java.lang.reflect.Method getGetMethod(java.lang.Class valueType, java.lang.String property, java.lang.Class ownerClass) throws java.lang.NoSuchMethodException
valueType
- the class of the value for the given propertyproperty
- the name of the property for which to retrieve the get methodownerClass
- the classjava.lang.NoSuchMethodException
- if the method does not exist in the owner class