public final class Utils extends Object
Modifier and Type | Method and Description |
---|---|
static IOException |
close(Closeable resource)
Check if the given resource is not
null and then close it, whereby any caught IOException
is been returned instead of thrown, so that the caller can if necessary handle (log) or just ignore it without
the need to put another try-catch. |
static <T> T |
coalesce(T... objects)
Returns the first non-
null object of the argument list, or null if there is no such
element. |
static boolean |
isEmpty(Collection<?> collection)
Returns true if the given collection is null or is empty.
|
static boolean |
isEmpty(Object value)
Returns true if the given value is null or is empty.
|
static boolean |
isEmpty(Object[] array)
Returns true if the given array is null or is empty.
|
static boolean |
isEmpty(String string)
Returns true if the given string is null or is empty.
|
static <T> boolean |
isOneOf(T object,
T... objects)
Returns
true if the given object equals one of the given objects. |
static long |
stream(InputStream input,
OutputStream output)
Stream the given input to the given output by NIO
ByteBuffer . |
static <T> Set<T> |
unmodifiableSet(Object... values)
Creates an unmodifiable set based on the given values.
|
public static boolean isEmpty(String string)
string
- The string to be checked on emptiness.public static boolean isEmpty(Object[] array)
array
- The array to be checked on emptiness.public static boolean isEmpty(Collection<?> collection)
collection
- The collection to be checked on emptiness.public static boolean isEmpty(Object value)
value
- The value to be checked on emptiness.public static <T> T coalesce(T... objects)
null
object of the argument list, or null
if there is no such
element.T
- The generic object type.objects
- The argument list of objects to be tested for non-null
.null
object of the argument list, or null
if there is no such
element.public static <T> boolean isOneOf(T object, T... objects)
true
if the given object equals one of the given objects.T
- The generic object type.object
- The object to be checked if it equals one of the given objects.objects
- The argument list of objects to be tested for equality.true
if the given object equals one of the given objects.public static long stream(InputStream input, OutputStream output) throws IOException
ByteBuffer
. Both the input and output streams will
implicitly be closed after streaming, regardless of whether an exception is been thrown or not.input
- The input stream.output
- The output stream.IOException
- When an I/O error occurs.public static IOException close(Closeable resource)
null
and then close it, whereby any caught IOException
is been returned instead of thrown, so that the caller can if necessary handle (log) or just ignore it without
the need to put another try-catch.resource
- The closeable resource to be closed.IOException
, or null
if none is been thrown.public static <T> Set<T> unmodifiableSet(Object... values)
ClassCastException
.values
- The values to create an unmodifiable set for.ClassCastException
- When one of the values or one of the arrays or collections is of wrong type.