|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jminor.common.model.Util
public final class Util
A static utility class.
Nested Class Summary | |
---|---|
static interface |
Util.HashKeyProvider<K,V>
Provides objects of type K, derived from a value of type V, for hashing said value via .hashCode(). |
Field Summary | |
---|---|
static String |
CONFIGURATION_FILE
Specifies the configuration file name to search for and parse at startup, relative to user.dir, this is done last, so that settings in the configuration file override settings gotten via runtime parameters Value type: String Default value: null |
static String |
PREF_DEFAULT_USERNAME
|
static String |
VERSION_FILE
|
Method Summary | ||
---|---|---|
static void |
closeSilently(Closeable... closeables)
|
|
static void |
closeSilently(ResultSet... resultSets)
|
|
static void |
closeSilently(Statement... statements)
|
|
static void |
collate(List<?> values)
|
|
static String |
createRandomString(int minLength,
int maxLength)
|
|
static List<Object> |
deserializeFromFile(File file)
|
|
static boolean |
equal(Object one,
Object two)
True if the given objects are equal. |
|
static long |
getAllocatedMemory()
|
|
static String |
getArrayContentsAsString(Object[] items,
boolean onePerLine)
|
|
static byte[] |
getBytesFromFile(File file)
|
|
static String |
getCollectionContentsAsString(Collection<?> collection,
boolean onePerLine)
|
|
static String |
getDefaultUserName(String applicationIdentifier,
String defaultName)
|
|
static String |
getDelimitedString(String[][] headers,
String[][] data,
String delimiter)
|
|
static Double |
getDouble(String text)
|
|
static long |
getFreeMemory()
|
|
static Integer |
getInt(String text)
|
|
static Long |
getLong(String text)
|
|
static long |
getMaxMemory()
|
|
static String |
getMemoryUsageString()
|
|
static Registry |
getRegistry()
|
|
static String |
getSystemProperties()
|
|
static String |
getTextFileContents(Class resourceClass,
String resourceName)
Fetch the entire contents of a resource textfile, and return it in a String, using the default Charset. |
|
static String |
getTextFileContents(Class resourceClass,
String resourceName,
Charset charset)
Fetch the entire contents of a resource textfile, and return it in a String. |
|
static String |
getTextFileContents(InputStream inputStream,
Charset charset)
|
|
static String |
getTextFileContents(String filename,
Charset charset)
|
|
static ThreadLocal<Collator> |
getThreadLocalCollator()
|
|
static Class<?> |
getTypeClass(int sqlType)
|
|
static URI |
getURI(String urlOrPath)
|
|
static Collection<URI> |
getURIs(Collection<String> urlsOrPaths)
|
|
static long |
getUsedMemory()
|
|
static String |
getUserPreference(String key,
String defaultValue)
|
|
static String |
getVersion()
|
|
static String |
getVersionAndBuildNumber()
|
|
static
|
initializeProxy(Class<T> clazz,
InvocationHandler invocationHandler)
|
|
static void |
initializeRegistry()
Initializes a Registry if one is not running |
|
static boolean |
isHostReachable(String host,
int timeout)
Returns true if the given host is reachable, false if it is not or an exception is thrown while trying |
|
static
|
map(Collection<V> values,
Util.HashKeyProvider<K,V> keyProvider)
Maps the given values according to the keys provided by the given key provider. |
|
static boolean |
notNull(Object... objects)
Checks if any of the given objects is null |
|
static boolean |
nullOrEmpty(String... strings)
|
|
static boolean |
onClasspath(String classname)
|
|
static String |
padString(String string,
int length,
char padChar,
boolean left)
|
|
static void |
parseConfigurationFile()
Parses the configuration file specified by the CONFIGURATION_FILE property |
|
static void |
printArrayContents(Object[] objects)
|
|
static void |
printArrayContents(Object[] objects,
boolean onePerLine)
|
|
static void |
printListContents(List<?> list)
|
|
static void |
printMemoryUsage(long interval)
|
|
static void |
putUserPreference(String key,
String value)
|
|
static
|
rejectNullValue(T value,
String valueName)
Throws an IllegalArgumentException complaining about valueName being null |
|
static void |
require(String propertyName,
String value)
|
|
static double |
roundDouble(double d,
int places)
|
|
static void |
serializeToFile(Collection objects,
File file)
|
|
static void |
setClipboard(String string)
|
|
static void |
setDefaultUserName(String applicationClassName,
String username)
|
|
static Exception |
unwrapAndLog(Exception exception,
Class<? extends Exception> wrappingExceptionClass,
org.slf4j.Logger logger)
|
|
static Exception |
unwrapAndLog(Exception exception,
Class<? extends Exception> wrappingExceptionClass,
org.slf4j.Logger logger,
Class<? extends Exception>... dontLog)
|
|
static void |
writeDelimitedFile(String[][] headers,
String[][] data,
String delimiter,
File file)
|
|
static void |
writeFile(String contents,
File file)
|
|
static void |
writeFile(String contents,
File file,
boolean append)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String VERSION_FILE
public static final String PREF_DEFAULT_USERNAME
public static final String CONFIGURATION_FILE
Method Detail |
---|
public static boolean isHostReachable(String host, int timeout)
host
- the hostnametimeout
- the timeout in milliseconds
public static String getUserPreference(String key, String defaultValue)
public static void putUserPreference(String key, String value)
public static String getDefaultUserName(String applicationIdentifier, String defaultName)
public static void setDefaultUserName(String applicationClassName, String username)
public static String padString(String string, int length, char padChar, boolean left)
public static Integer getInt(String text)
public static Double getDouble(String text)
public static Long getLong(String text)
public static void printListContents(List<?> list)
public static void printArrayContents(Object[] objects)
public static void printArrayContents(Object[] objects, boolean onePerLine)
public static String getCollectionContentsAsString(Collection<?> collection, boolean onePerLine)
public static String getArrayContentsAsString(Object[] items, boolean onePerLine)
public static void printMemoryUsage(long interval)
public static long getAllocatedMemory()
public static long getFreeMemory()
public static long getMaxMemory()
public static long getUsedMemory()
public static String getMemoryUsageString()
public static String getTextFileContents(Class resourceClass, String resourceName) throws IOException
resourceClass
- the resource classresourceName
- the name of the resource to retrieve
IOException
- in case an IOException occurspublic static String getTextFileContents(Class resourceClass, String resourceName, Charset charset) throws IOException
resourceClass
- the resource classresourceName
- the name of the resource to retrievecharset
- the Charset to use when reading the file contents
IOException
- in case an IOException occurspublic static String getTextFileContents(String filename, Charset charset) throws IOException
IOException
public static String getTextFileContents(InputStream inputStream, Charset charset) throws IOException
IOException
public static String getSystemProperties()
public static void setClipboard(String string)
public static String getDelimitedString(String[][] headers, String[][] data, String delimiter)
public static void writeDelimitedFile(String[][] headers, String[][] data, String delimiter, File file)
public static void writeFile(String contents, File file)
public static void writeFile(String contents, File file, boolean append)
public static List<Object> deserializeFromFile(File file)
public static void serializeToFile(Collection objects, File file)
public static boolean equal(Object one, Object two)
one
- the first objecttwo
- the second object
public static String getVersion()
public static String getVersionAndBuildNumber()
public static double roundDouble(double d, int places)
public static boolean notNull(Object... objects)
objects
- the objects to check
public static byte[] getBytesFromFile(File file) throws IOException
IOException
public static String createRandomString(int minLength, int maxLength)
public static void collate(List<?> values)
public static URI getURI(String urlOrPath) throws URISyntaxException
URISyntaxException
public static Collection<URI> getURIs(Collection<String> urlsOrPaths) throws URISyntaxException
URISyntaxException
public static ThreadLocal<Collator> getThreadLocalCollator()
public static <T> T rejectNullValue(T value, String valueName)
valueName
being null
value
- the value to checkvalueName
- the name of the value being checked
IllegalArgumentException
- if value is nullpublic static void closeSilently(ResultSet... resultSets)
public static void closeSilently(Statement... statements)
public static void closeSilently(Closeable... closeables)
public static <K,V> Map<K,Collection<V>> map(Collection<V> values, Util.HashKeyProvider<K,V> keyProvider)
class Person {
String name;
Integer age;
...
}
List persons = ...;
HashKeyProvider ageKeyProvider = new HashKeyProvider() {
public Integer getKey(Person person) {
return person.getAge();
}
};
Map> personsByAge = Util.map(persons, ageKeyProvider);
K
- the key typeV
- the value typevalues
- the values to mapkeyProvider
- the object providing keys to use when hashing the values
public static boolean onClasspath(String classname)
public static void require(String propertyName, String value)
public static boolean nullOrEmpty(String... strings)
public static Class<?> getTypeClass(int sqlType)
sqlType
- the type
public static void parseConfigurationFile()
CONFIGURATION_FILE
public static void initializeRegistry() throws RemoteException
RemoteException
- in case of an exceptionpublic static Registry getRegistry() throws RemoteException
RemoteException
- in case of an exceptionpublic static <T> T initializeProxy(Class<T> clazz, InvocationHandler invocationHandler)
public static Exception unwrapAndLog(Exception exception, Class<? extends Exception> wrappingExceptionClass, org.slf4j.Logger logger)
public static Exception unwrapAndLog(Exception exception, Class<? extends Exception> wrappingExceptionClass, org.slf4j.Logger logger, Class<? extends Exception>... dontLog)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |