public class CommonUtils extends Object
| Constructor and Description |
|---|
CommonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
compareVersion(String[] v1,
String[] v2)
Compares versions.
|
static int |
compareVersion(String v1,
String v2)
Compares software versions.
|
static DateFormat |
DATE_FORMATTER()
The formatter for dates (see
DateFormat.SHORT). |
static DateFormat |
DATE_TIME_FORMATTER()
The formatter for dates incl. times (see
DateFormat.SHORT). |
static String |
debugObject(Object o)
Recursively debugs objects.
|
static void |
debugObject(StringBuffer s,
Object o)
Recursively debugs objects and adds this in the string buffer.
|
static void |
debugObject(StringBuilder s,
Object o)
Recursively debugs objects and adds this in the string builder.
|
static void |
debugStackTrace(Logger log)
Dumps the stacktrace in DEBUG mode.
|
static boolean |
equals(Object o1,
Object o2)
Checks for equality null-safe
|
static void |
errorStackTrace(Logger log)
Dumps the stacktrace in ERROR mode.
|
static String |
getDisplay(Enum<?> e)
Returns the display string for the default locale.
|
static String |
getDisplay(Enum<?> e,
Locale locale)
Returns the display string for the given locale.
|
static String |
getDisplay(Object o) |
static String |
getDisplay(Object o,
Locale locale)
Returns the display string of an object.
|
static Enum<?> |
getEnum(Class<? extends Enum<?>> clazz,
String display)
Returns the enum constant for given display in default locale.
|
static Enum<?> |
getEnum(Class<? extends Enum<?>> clazz,
String display,
Locale locale)
Returns the enum constant for given display in given locale.
|
static List<Enum<?>> |
getOptionList(Class<? extends Enum<?>> clazz)
Returns a list of options from an enumeration class.
|
static String[] |
getOptions(Class<? extends Enum<?>> clazz)
Returns a list of options for display in default locale.
|
static String[] |
getOptions(Class<? extends Enum<?>> clazz,
Locale locale)
Returns a list of options for display in given locale.
|
static String |
getOS()
Returns the OS name.
|
static List<String> |
getStackTrace(int ignoreLines)
Returns the current stacktrace.
|
static long |
getUnixTimestamp()
Returns the current time as UNIX timestamp.
|
static long |
getUnixTimestamp(Date date)
Returns the given date as UNIX timestamp.
|
static long |
getUnixTimestamp(long time)
Returns the given Java time as UNIX timestamp.
|
static long |
getUnixTimestamp(RsDate date)
Returns the given date as UNIX timestamp.
|
static void |
infoStackTrace(Logger log)
Dumps the stacktrace in INFO mode.
|
static boolean |
isCompatibleVersion(String minVersion,
String maxVersion,
String version)
Returns true if version is in range of minVersion and maxVersion.
|
static boolean |
isEmpty(String s)
Returns true when the given string is null or - when trimmed - empty.
|
static boolean |
isEmpty(String s,
boolean trim)
Returns true when the given string is null empty.
|
static boolean |
isMac()
Tells whether runtime is a Mac system.
|
static boolean |
isSolaris()
Tells whether runtime is a Windows system.
|
static boolean |
isUnix()
Tells whether runtime is a Unix system.
|
static boolean |
isWindows()
Tells whether runtime is a Windows system.
|
static <T> Iterable<T> |
iterable(Iterator<T> iterator)
Returns an iterable for the given iterator.
|
static String |
join(String separator,
String[] parts)
Makes a join of a string array.
|
static String |
join(String separator,
String[] parts,
int startIndex)
Makes a join of a string array.
|
static String |
join(String separator,
String[] parts,
int startIndex,
int endIndex)
Makes a join of a string array.
|
static String |
loadContent(File f)
Loads the content of a file as a string.
|
static String |
loadContent(File f,
Charset charset)
Loads the content of a file as a string.
|
static String |
loadContent(InputStream in)
Loads the content of a stream as a string.
|
static String |
loadContent(InputStream in,
Charset charset)
Loads the content of a stream as a string.
|
static String |
loadContent(Reader reader)
Loads the content of a reader as a string.
|
static String |
loadContent(String name)
Loads the content of a file as a string.
|
static String |
loadContent(String name,
Charset charset)
Loads the content of a file as a string.
|
static String |
loadContent(URL url)
Loads the content of the URL as a string.
|
static String |
loadContent(URL url,
Charset charset)
Loads the content of the URL as a string.
|
static Properties |
loadProperties(File file)
Loads a property file.
|
static void |
loadProperties(Properties props,
File file)
Loads a property file.
|
static void |
loadProperties(Properties props,
String file)
Loads a property file.
|
static Properties |
loadProperties(String file)
Loads a property file.
|
static void |
printStackTrace(PrintStream out,
int ignoreLines)
Dumps the stacktrace into the print stream.
|
static URL |
setAnchor(URL url,
String anchor)
Set the anchor id for at the given URL.
|
static NumberFormat |
SIMPLE_INT_FORMATTER()
Formatter for integers.
|
static NumberFormat |
SIMPLE_NUMBER_FORMATTER()
Formatter for real numbers.
|
static void |
stderrStackTrace()
Dumps the stacktrace so stderr.
|
static void |
stdoutStackTrace()
Dumps the stacktrace so stdout.
|
static void |
storeProperties(Properties props,
File file)
Stores a property file.
|
static void |
storeProperties(Properties props,
String file)
Stores a property file.
|
static String |
toString(byte[] b)
Generates a string presentation of the given bytes.
|
static String |
toString(float amount)
Formats the money value.
|
static String |
toString(Object[] o)
Generates a string presentation of the given objects.
|
static String |
toString(RsDate date)
Formats the given date.
|
static String |
toString(RsDay day)
Formats the given day.
|
static String |
toString(RsMonth month)
Formats the given month (1st day of month).
|
static String |
toString(RsYear year)
Formats the given year.
|
static String |
toString(String o)
Formats the string for display.
|
static void |
traceStackTrace(Logger log)
Dumps the stacktrace in TRACE mode.
|
static void |
writeContent(File f,
String content)
Writes the string to a file.
|
static void |
writeContent(File f,
String content,
Charset charset)
Writes the string to a file.
|
static void |
writeContent(OutputStream out,
String content)
Writes the string to a stream.
|
static void |
writeContent(OutputStream out,
String content,
Charset charset)
Writes the string to a stream.
|
static void |
writeContent(String name,
String content)
Writes the string to a file.
|
static void |
writeContent(String name,
String content,
Charset charset)
Writes the string to a file.
|
static void |
writeContent(Writer writer,
String content)
Writes the string to a writer.
|
public static DateFormat DATE_FORMATTER()
DateFormat.SHORT).public static DateFormat DATE_TIME_FORMATTER()
DateFormat.SHORT).public static NumberFormat SIMPLE_NUMBER_FORMATTER()
public static NumberFormat SIMPLE_INT_FORMATTER()
public static String toString(String o)
o - the categorypublic static String toString(float amount)
amount - amount to be formattedpublic static String toString(RsDate date)
date - date to formatDATE_TIME_FORMATTER())public static String toString(RsDay day)
day - day to formatDATE_FORMATTER())public static String toString(RsYear year)
year - year to formatpublic static String toString(RsMonth month)
month - date to formatDATE_FORMATTER())public static String toString(byte[] b)
b - byte arraypublic static String toString(Object[] o)
o - object arraypublic static boolean equals(Object o1, Object o2)
o1 - object 1o2 - object 2public static boolean isEmpty(String s)
s - the string to be checkedpublic static boolean isEmpty(String s, boolean trim)
s - the string to be checkedtrim - whether whitespaces shall be trimmed firstpublic static String[] getOptions(Class<? extends Enum<?>> clazz)
clazz - enum classpublic static String[] getOptions(Class<? extends Enum<?>> clazz, Locale locale)
clazz - enum classlocale - localepublic static List<Enum<?>> getOptionList(Class<? extends Enum<?>> clazz)
clazz - enum classpublic static String getDisplay(Enum<?> e)
e - enum valuepublic static String getDisplay(Enum<?> e, Locale locale)
e - enum valuelocale - localepublic static Enum<?> getEnum(Class<? extends Enum<?>> clazz, String display)
clazz - enum classdisplay - display of enumpublic static Enum<?> getEnum(Class<? extends Enum<?>> clazz, String display, Locale locale)
clazz - enum classdisplay - display of enumlocale - localepublic static boolean isCompatibleVersion(String minVersion, String maxVersion, String version)
minVersion - - minimum required version (can be null)maxVersion - - maximum required version (can be null)version - - version to checkpublic static int compareVersion(String v1, String v2)
v1 - - version 1v2 - - version 2public static int compareVersion(String[] v1, String[] v2)
v1 - - version 1 divided into separate partsv2 - - version 2 divided into separate partspublic static String join(String separator, String[] parts)
separator - - the string to be used inbetween partsparts - - the parts to joinpublic static String join(String separator, String[] parts, int startIndex)
separator - - the string to be used inbetween partsparts - - the parts to joinstartIndex - - starting index (negative values not allowed)public static String join(String separator, String[] parts, int startIndex, int endIndex)
separator - - the string to be used inbetween partsparts - - the parts to joinstartIndex - - starting index (negative values not allowed)endIndex - - endIndex (bigger values than number or array elements have no effect)public static String debugObject(Object o)
o - object to debugpublic static void debugObject(StringBuffer s, Object o)
s - string buffer to enhanceo - object to debugpublic static void debugObject(StringBuilder s, Object o)
s - string builder to enhanceo - object to debugpublic static long getUnixTimestamp()
public static long getUnixTimestamp(Date date)
date - date object.public static long getUnixTimestamp(RsDate date)
date - date object.public static long getUnixTimestamp(long time)
time - Java timestamppublic static <T> Iterable<T> iterable(Iterator<T> iterator)
iterator - the iterator to be wrappedpublic static List<String> getStackTrace(int ignoreLines)
ignoreLines - the number of lines to be ignored at the top of the tracepublic static void stdoutStackTrace()
public static void stderrStackTrace()
public static void printStackTrace(PrintStream out, int ignoreLines)
out - the stream to be usedpublic static void errorStackTrace(Logger log)
log - the logger to be usedpublic static void infoStackTrace(Logger log)
log - the logger to be usedpublic static void debugStackTrace(Logger log)
log - the logger to be usedpublic static void traceStackTrace(Logger log)
log - the logger to be usedpublic static Properties loadProperties(File file) throws IOException
file - the file to loadIOExceptionpublic static Properties loadProperties(String file) throws IOException
file - the file to loadIOExceptionpublic static void loadProperties(Properties props, File file) throws IOException
props - the properties objectfile - the file to loadIOExceptionpublic static void loadProperties(Properties props, String file) throws IOException
props - the properties objectfile - the file to loadIOExceptionpublic static void storeProperties(Properties props, File file) throws IOException
props - the properties objectfile - the file to loadIOExceptionpublic static void storeProperties(Properties props, String file) throws IOException
props - the properties objectfile - the file to loadIOExceptionpublic static String loadContent(URL url) throws IOException
url - URL to be loadedIOException - when content of URL cannot be loadedpublic static String loadContent(URL url, Charset charset) throws IOException
url - URL to be loadedcharset - the charset of the content (null for default charset)IOException - when content of URL cannot be loadedpublic static String loadContent(String name) throws IOException
name - name of file to be loadedIOException - when content of file cannot be loadedpublic static String loadContent(String name, Charset charset) throws IOException
name - name of file to be loadedcharset - the charset of the content (null for default charset)IOException - when content of file cannot be loadedpublic static String loadContent(File f) throws IOException
f - file to be loadedIOException - when content of file cannot be loadedpublic static String loadContent(File f, Charset charset) throws IOException
f - file to be loadedcharset - the charset of the content (null for default charset)IOException - when content of file cannot be loadedpublic static String loadContent(InputStream in) throws IOException
in - stream to be loadedIOException - when content of stream cannot be loadedpublic static String loadContent(InputStream in, Charset charset) throws IOException
in - stream to be loadedcharset - the charset of the content (null for default charset)IOException - when content of stream cannot be loadedpublic static String loadContent(Reader reader) throws IOException
reader - reader to be loadedIOException - when content of reader cannot be loadedpublic static void writeContent(String name, String content) throws IOException
name - name of file to be written tocontent - the content to be writtenIOException - when content cannot be writtenpublic static void writeContent(String name, String content, Charset charset) throws IOException
name - name of file to be written tocontent - the content to be writtencharset - the charset of the content (null for default charset)IOException - when content cannot be writtenpublic static void writeContent(File f, String content) throws IOException
f - file to be written tocontent - the content to be writtenIOException - when content cannot be writtenpublic static void writeContent(File f, String content, Charset charset) throws IOException
f - file to be written tocontent - the content to be writtencharset - the charset of the content (null for default charset)IOException - when content cannot be writtenpublic static void writeContent(OutputStream out, String content) throws IOException
out - stream to be written tocontent - the content to be writtenIOException - when content cannot be writtenpublic static void writeContent(OutputStream out, String content, Charset charset) throws IOException
out - stream to be written tocontent - the content to be writtencharset - the charset of the content (null for default charset)IOException - when content cannot be writtenpublic static void writeContent(Writer writer, String content) throws IOException
writer - writer to be written tocontent - the content to be writtenIOException - when content cannot be writtenpublic static boolean isWindows()
true when OS is a Windows systempublic static boolean isMac()
true when OS is a Mac systempublic static boolean isUnix()
true when OS is a Unix systempublic static boolean isSolaris()
true when OS is a Windows systempublic static String getOS()
System.getProperty("os.name")public static String getDisplay(Object o, Locale locale)
IDisplayable, IDisplayProvider and NamedObject.o - locale - Locale to be used for IDisplayableCopyright © 2014. All rights reserved.