public class Utils extends Object
| Modifier and Type | Field and Description |
|---|---|
static com.google.common.base.Predicate<String> |
NOT_EMPTY
Predicate that accepts a string and returns
true if given string is not null and is not composed of
only 0 or many spaces. |
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Collection<T> |
checkEmpty(String name,
Collection<T> collection)
A facility method that checks collection on null and emptiness and throws
IllegalArgumentException if it
is. |
static String |
checkNull(String name,
String value)
A facility method that checks object to be null and throws the
IllegalArgumentException if it is. |
static <T> T |
checkNull(String name,
T value)
A facility method that checks object to be null and throws the
IllegalArgumentException if it is. |
static <T> T |
checkNullState(String message,
T value)
A facility method that checks object to be null and throws the
IllegalStateException if it is. |
static <T> List<T> |
drainQueue(Queue<T> queue)
Drains the queue to a new List
|
static String |
getStackTrace(Throwable throwable)
Prints exception stack into a string and returns it.
|
static <T> T |
getUnique(Collection<T> collection)
Returns the only element in the given collection.
|
static boolean |
hasCause(Throwable exception,
Class<? extends Throwable> causeClass)
Walks the exception cause list and checks if any of them are of the give type.
|
static <T> String |
join(Iterable<T> sequence,
String delimiter)
Join string representation of the elements of the given collection separated with the given delimiter.
|
static double |
round(double value,
int power)
Relaxes precision up to the given power of 2.
|
public static com.google.common.base.Predicate<String> NOT_EMPTY
true if given string is not null and is not composed of
only 0 or many spaces.public static <T> T checkNull(String name, T value)
IllegalArgumentException if it is. This
method can be chained as it returns the value in case of success.T - Type of the checked and returned value.name - The object's name.value - The object.public static String checkNull(String name, String value)
IllegalArgumentException if it is. This
method can be chained as it returns the value in case of success.name - The object's name.value - The object.public static <T> Collection<T> checkEmpty(String name, Collection<T> collection)
IllegalArgumentException if it
is. This method can be chained as it returns the value in case of success.T - The collection element type.name - The collection's namecollection - The collection.public static boolean hasCause(Throwable exception, Class<? extends Throwable> causeClass)
exception - The exception that holds the list of causes.causeClass - The searched exception cause class type, exception itself is also checked.public static <T> T checkNullState(String message, T value)
IllegalStateException if it is.message - The object's name.value - The object.public static double round(double value,
int power)
Note: After applying this method you might still have digits on positions further then requested! This method doesn't guarantee zeroes there, but it makes sure that if there is any difference in the original numbers that is less than pow(2,power) it will be discarded.
value - The value to round.power - Powers of 2 yielding the cutoff value.public static <T> String join(Iterable<T> sequence, String delimiter)
sequence - The items to be converted into string.delimiter - The delimiter to be used between distinct items of the collection.public static <T> List<T> drainQueue(Queue<T> queue)
T - The type of elements in the queue.queue - The Queue to be drained.public static <T> T getUnique(Collection<T> collection)
collection - The collection of elements that is expected to be of size 1.IllegalStateException - If the collection size is different from 1.Copyright © 2013 CERN, The European Organization for Nuclear Research. All Rights Reserved.