|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.omnifaces.util.Utils
public final class Utils
Collection of general utility methods that do not fit in one of the more specific classes.
Method Summary | ||
---|---|---|
static java.io.IOException |
close(java.io.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
|
coalesce(T... objects)
Returns the first non- null object of the argument list, or null if there is no such
element. |
|
static java.util.List<java.lang.String> |
csvToList(java.lang.String values)
Converts comma separated values in a string into a list with those values. |
|
static java.util.List<java.lang.String> |
csvToList(java.lang.String values,
java.lang.String delimiter)
Converts comma separated values in a string into a list with those values. |
|
static java.lang.String |
decodeURL(java.lang.String string)
URL-decode the given string using UTF-8. |
|
static java.lang.String |
encodeURL(java.lang.String string)
URL-encode the given string using UTF-8. |
|
static java.lang.String |
formatRFC1123(java.util.Date date)
Formats the given Date to a string in RFC1123 format. |
|
static boolean |
isEmpty(java.util.Collection<?> collection)
Returns true if the given collection is null or is empty. |
|
static boolean |
isEmpty(java.util.Map<?,?> map)
Returns true if the given map is null or is empty. |
|
static boolean |
isEmpty(java.lang.Object value)
Returns true if the given value is null or is empty. |
|
static boolean |
isEmpty(java.lang.Object[] array)
Returns true if the given array is null or is empty. |
|
static boolean |
isEmpty(java.lang.String string)
Returns true if the given string is null or is empty. |
|
static
|
isOneOf(T object,
T... objects)
Returns true if the given object equals one of the given objects. |
|
static java.util.Date |
parseRFC1123(java.lang.String string)
Parses the given string in RFC1123 format to a Date object. |
|
static
|
reverse(java.util.Map<T,T> source)
Returns a new map that contains the reverse of the given map. |
|
static java.lang.String |
serializeURLSafe(java.lang.String string)
Serialize the given string to the short possible unique URL-safe representation. |
|
static boolean |
startsWithOneOf(java.lang.String string,
java.lang.String... prefixes)
Returns true if the given string starts with one of the given prefixes. |
|
static long |
stream(java.io.InputStream input,
java.io.OutputStream output)
Stream the given input to the given output by NIO ByteBuffer . |
|
static
|
unmodifiableSet(java.lang.Object... values)
Creates an unmodifiable set based on the given values. |
|
static java.lang.String |
unserializeURLSafe(java.lang.String string)
Unserialize the given serialized URL-safe string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean isEmpty(java.lang.String string)
string
- The string to be checked on emptiness.
public static boolean isEmpty(java.lang.Object[] array)
array
- The array to be checked on emptiness.
public static boolean isEmpty(java.util.Collection<?> collection)
collection
- The collection to be checked on emptiness.
public static boolean isEmpty(java.util.Map<?,?> map)
map
- The map to be checked on emptiness.
public static boolean isEmpty(java.lang.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 boolean startsWithOneOf(java.lang.String string, java.lang.String... prefixes)
true
if the given string starts with one of the given prefixes.
string
- The object to be checked if it starts with one of the given prefixes.prefixes
- The argument list of prefixes to be checked
true
if the given string starts with one of the given prefixes.public static long stream(java.io.InputStream input, java.io.OutputStream output) throws java.io.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.
java.io.IOException
- When an I/O error occurs.public static java.io.IOException close(java.io.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> java.util.Set<T> unmodifiableSet(java.lang.Object... values)
ClassCastException
.
values
- The values to create an unmodifiable set for.
java.lang.ClassCastException
- When one of the values or one of the arrays or collections is of wrong type.public static java.util.List<java.lang.String> csvToList(java.lang.String values)
E.g. a string with "foo, bar, kaz" will be converted into a List
with values:
","
) as delimiter. See csvToList(String, String)
for when
a different delimiter is needed.
values
- string with comma separated values
values
argument, can be the empty list.public static java.util.List<java.lang.String> csvToList(java.lang.String values, java.lang.String delimiter)
E.g. a string with "foo, bar, kaz" will be converted into a List
with values:
values
- string with comma separated valuesdelimiter
- the delimiter used to separate the actual values in the values
parameter.
values
argument, can be the empty list.public static <T> java.util.Map<T,T> reverse(java.util.Map<T,T> source)
The reverse of a map means that every value X becomes a key X' with as corresponding value Y' the key Y that was originally associated with the value X.
source
- the map that is to be reversed
public static java.lang.String formatRFC1123(java.util.Date date)
Date
to a string in RFC1123 format. This format is used in HTTP headers and in
JavaScript Date
constructor.
date
- The Date
to be formatted to a string in RFC1123 format.
public static java.util.Date parseRFC1123(java.lang.String string) throws java.text.ParseException
Date
object.
string
- The string in RFC1123 format to be parsed to a Date
object.
Date
.
java.text.ParseException
- When the given string is not in RFC1123 format.public static java.lang.String serializeURLSafe(java.lang.String string)
/
, +
and
=
are been replaced by respectively ~
, -
and _
to make it
URL-safe (so that no platform-sensitive URL-encoding needs to be done when used in URLs).
string
- The string to be serialized.
null
when the given string is itself null
.public static java.lang.String unserializeURLSafe(java.lang.String string)
serializeURLSafe(String)
.
string
- The serialized URL-safe string to be unserialized.
null
when the given string is by itself null
.
java.lang.IllegalArgumentException
- When the given serialized URL-safe string is not in valid format as returned by
serializeURLSafe(String)
.public static java.lang.String encodeURL(java.lang.String string)
string
- The string to be URL-encoded using UTF-8.
null
if null
was given.
java.lang.UnsupportedOperationException
- When UTF-8 is not supported.public static java.lang.String decodeURL(java.lang.String string)
string
- The string to be URL-decode using UTF-8.
null
if null
was given.
java.lang.UnsupportedOperationException
- When UTF-8 is not supported.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |