|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.kuka.common.CommonUtil
public final class CommonUtil
Utility class with some helper methods.
| Field Summary | |
|---|---|
static double |
EPSILON
Epsilon for equality check in doubles. |
static String |
LOGSERVICE_SURFIX
Surfix of the log service. |
static String |
USERTASK_PACKAGENAME
Name of the user task package. |
| Method Summary | |
|---|---|
static URI |
appendToURI(URI uri,
String pathSuffix)
Returns a new URI with the given path suffix appended. |
static boolean |
areNearlyEqual(double[] value1,
double[] value2)
|
static boolean |
areNearlyEqual(double[] value1,
double[] value2,
double epsilon)
Checks if the two double arrays are nearly equal. |
static boolean |
areNearlyEqual(double value1,
double value2)
|
static boolean |
areNearlyEqual(double value1,
double value2,
double epsilon)
Checks if the two double values are nearly equal. |
static boolean |
areNearlyEqual(long value1,
long value2,
long epsilon)
Checks if the two long values are nearly equal. |
static int |
booleanToInt(boolean value)
Converts a boolean value into an integer value. |
static String |
capitalize(String string)
Capitalizes the given string. |
static boolean |
close(Closeable closeable)
Closes the given Closeable. |
static void |
close(MulticastSocket socket)
Closes the given socket. |
static void |
close(ServerSocket socket)
Closes the given socket. |
static void |
close(Socket socket)
Closes the given socket. |
static Date |
convertSunriseTime(int[] time)
Converts the timestamp received from Sunrise Framework to a Date object. |
static String |
decapitalize(String string)
Decapitalizes the given string. |
static Logger |
getConsoleLogger(Class<?> clazz)
Deprecated. |
static Logger |
getConsoleLogger(String className)
Deprecated. |
static Logger |
getLogger(Class<?> loggerClass)
Deprecated. Please use 'LoggerFactory.getLogger(Class> loggerClass)' |
static Logger |
getLogger(String loggerName)
Deprecated. Please use 'LoggerFactory.getLogger(String loggerName)' |
static boolean |
hasSameData(Collection<? extends IDataEquatable> one,
Collection<? extends IDataEquatable> other)
Compares all elements in the committed containers. |
static boolean |
isNullOrEmpty(String str)
Checks if the given string is null or empty. |
static void |
milliSleep(long millis)
Deprecated. use ThreadUtil.milliSleep(long) instead |
static boolean |
numberToBoolean(Number value)
Converts an integer into a boolean value. |
static boolean |
objectEquals(Object o1,
Object o2)
Check two objects for equality regarding that the references could be null. |
static int |
objectHashCode(Object obj)
Return the hash code of an object regarding that the reference could be null. |
static void |
printHexDump(PrintWriter pw,
byte[] data)
Prints the given data in a pretty-printed hex dump format. |
static void |
printHexDump(PrintWriter pw,
byte[] data,
int offset,
int length)
Prints the given data in a pretty-printed hex dump format. |
static void |
reverse(byte[] array)
Reverses the given byte array and stores the result in the same array. object. |
static String |
stringJoin(Collection<? extends Object> items,
String separator)
Joins the String.valueOf() representation of the items in the collections separated by the given separator into a new string. |
static String |
trim(String original)
Returns a copy of the string, with leading and trailing whitespace omitted. |
static URI |
urlToURI(URL url)
Returns a URI equivalent to the given URL. |
static boolean |
waitOnLatch(CountDownLatch latch,
long timeout,
TimeUnit unit)
Waits on a latch for a specified time. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final double EPSILON
public static final String USERTASK_PACKAGENAME
public static final String LOGSERVICE_SURFIX
| Method Detail |
|---|
public static boolean areNearlyEqual(double value1,
double value2,
double epsilon)
A small epsilon check is performed. Epsilon is 10^-5.
value1 - The first value.value2 - The second value.epsilon - The epsilon.
public static boolean areNearlyEqual(double value1,
double value2)
value1 - The first value.value2 - The second value.
areNearlyEqual(double, double, double)
public static boolean areNearlyEqual(double[] value1,
double[] value2,
double epsilon)
A small epsilon check is performed.
value1 - The first value. May not be null.value2 - The second value. May not be null.epsilon - The epsilon.
public static boolean areNearlyEqual(double[] value1,
double[] value2)
value1 - The first value. May not be null.value2 - The second value. May not be null.
areNearlyEqual(double[], double[], double)
public static boolean areNearlyEqual(long value1,
long value2,
long epsilon)
A small epsilon check is performed.
value1 - The first value.value2 - The second value.epsilon - The epsilon.
public static boolean objectEquals(Object o1,
Object o2)
o1 - the first objecto2 - the second object
public static int objectHashCode(Object obj)
obj - The object to retrieve the hash code
@Deprecated public static void milliSleep(long millis)
ThreadUtil.milliSleep(long) instead
Catches the interrupted exception, 'reinterrupts' the thread so that it's isInterrupted method returns true and
throws a ThreadInterruptedException.
millis - The milliseconds to sleep. If negative or 0, the method returns immediately.
ThreadInterruptedException - if the sleep was interrupted.public static boolean numberToBoolean(Number value)
value - the integer value
public static int booleanToInt(boolean value)
value - the boolean value
public static boolean close(Closeable closeable)
Closeable. Ignores any Throwable.
closeable - The item to close. Can be null.
Closeable was closed successful.public static void close(MulticastSocket socket)
socket - The socket. Can be null.public static void close(Socket socket)
socket - The socket. Can be null.public static void close(ServerSocket socket)
socket - The socket. Can be null.public static boolean isNullOrEmpty(String str)
str - The string.
@Deprecated public static Logger getConsoleLogger(Class<?> clazz)
clazz - The given class
@Deprecated public static Logger getConsoleLogger(String className)
className - The given class name
public static boolean waitOnLatch(CountDownLatch latch,
long timeout,
TimeUnit unit)
latch - The latch on which waiting shoud occur.timeout - The timeout value.unit - The timeout unit.
public static boolean hasSameData(Collection<? extends IDataEquatable> one,
Collection<? extends IDataEquatable> other)
one - The first container that should be comparedother - The second container that should be compared
@Deprecated public static Logger getLogger(Class<?> loggerClass)
loggerClass - The class that uses the logger
@Deprecated public static Logger getLogger(String loggerName)
loggerName - The class that uses the logger
public static String stringJoin(Collection<? extends Object> items,
String separator)
items - The collection of items. Can be empty or contain null values.separator - separator to put in between the items
public static URI urlToURI(URL url)
throws URISyntaxException
URI equivalent to the given URL. This method can handle special characters like spaces
where URL.toURI() would throw an URISyntaxException.
url - the URL to be converted.
URISyntaxException - if this URL is not formatted strictly according to to RFC2396 and cannot be converted to a URI.
public static URI appendToURI(URI uri,
String pathSuffix)
throws URISyntaxException
URI with the given path suffix appended. This method can handle special characters
like spaces where URI(String) would throw an URISyntaxException.
uri - the base URI.pathSuffix - the partial path to be appended to the scheme specific path of the base URI
URISyntaxException - if this URL is not formatted strictly according to to RFC2396 and cannot be converted to a URI.public static Date convertSunriseTime(int[] time)
time - Sunrise Framework time. Array size must be two. The first integer contains the number of the seconds
since 1970. The second integer contains the number of nanoseconds.
public static String trim(String original)
original - the original string
public static void reverse(byte[] array)
array - the array to reverse.
public static void printHexDump(PrintWriter pw,
byte[] data)
printHexDump(pw,data)is
equivalent to printHexDump(pw, data, 0, data.length).
pw - a PrintWriter to which the hex dump will be printeddata - data bytes to be dumpedprintHexDump(PrintWriter, byte[], int, int)
public static void printHexDump(PrintWriter pw,
byte[] data,
int offset,
int length)
PrintWriter pw = new PrintWriter(System.out); CommonUtil.printHexDump(pw, data, offset, length);The hex dump of
"Hello World, nice to meet you!\n".getBytes() will look like this:
0000 48 65 6c 6c 6f 20 57 6f 72 6c 64 2c 20 6e 69 63 Hello Wo rld, nic 0010 65 20 74 6f 20 6d 65 65 74 20 79 6f 75 21 0a e to mee t you!.
pw - a PrintWriter to which the hex dump will be printeddata - data bytes to be dumpedoffset - the offset in the array at which to start the dumplength - total number of bytes to dump. The dump will stop with the last byte in the array if the given offset
and length exceed the array bounds.
ArrayIndexOutOfBoundsException - if offset is negative, or greater or equal data.lengthpublic static String capitalize(String string)
string -
public static String decapitalize(String string)
string -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||