public final class Converters
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <E> java.util.List<E> |
iterableToList(java.lang.Iterable<E> iterable)
Converts a
Iterable<E> to a List<E> . |
static <E> javax.faces.model.DataModel<E> |
iterableToModel(java.lang.Iterable<E> iterable)
Converts an
Iterable<E> to a DataModel<E> . |
static java.lang.String |
joinArray(java.lang.Object array,
java.lang.String separator)
Joins all elements of the given array to a single string, separated by the given separator.
|
static <E> java.lang.String |
joinCollection(java.util.Collection<E> collection,
java.lang.String separator)
Joins all elements of the given collection to a single string, separated by the given separator.
|
static <K,V> java.lang.String |
joinMap(java.util.Map<K,V> map,
java.lang.String pairSeparator,
java.lang.String entrySeparator)
Joins all elements of the given map to a single string, separated by the given key-value pair separator and
entry separator.
|
static <K,V> java.util.List<java.util.Map.Entry<K,V>> |
mapToList(java.util.Map<K,V> map)
Converts a
Map<K, V> to a List<Map.Entry<K, V>> . |
static java.lang.String |
printStackTrace(java.lang.Throwable exception)
Print the stack trace of the given exception.
|
static <E> java.util.List<E> |
setToList(java.util.Set<E> set)
Converts a
Set<E> to a List<E> . |
static java.lang.Object[][] |
splitArray(java.lang.Object array,
int fragmentSize)
Splits the given array into an array of subarrays of the given fragment size.
|
static <T> java.util.List<java.util.List<T>> |
splitList(java.util.List<T> list,
int fragmentSize)
Splits the given list into a list of sublists of the given fragment size.
|
static java.lang.String |
toJson(java.lang.Object object)
Encode given object as JSON.
|
public static <E> java.util.List<E> setToList(java.util.Set<E> set)
Set<E>
to a List<E>
. Useful when you want to iterate over a
Set
in for example <ui:repeat>
.set
- The set to be converted to list of its entries.public static <K,V> java.util.List<java.util.Map.Entry<K,V>> mapToList(java.util.Map<K,V> map)
Map<K, V>
to a List<Map.Entry<K, V>>
. Useful when you want
to iterate over a Map
in for example <ui:repeat>
. Each of the entries has the
usual getKey()
and getValue()
methods.map
- The map to be converted to list of its entries.public static <E> java.util.List<E> iterableToList(java.lang.Iterable<E> iterable)
Iterable<E>
to a List<E>
. Useful when you want to iterate over an
Iterable
, which includes any type of Collection
(which includes e.g. a Set
)
in for example <ui:repeat>
and <h:dataTable>
.
When iterating specifically over a Set using the above mentioned components setToList(Set)
is
an alternative to this.
iterable
- The Iterable to be converted to a List.public static <E> javax.faces.model.DataModel<E> iterableToModel(java.lang.Iterable<E> iterable)
Iterable<E>
to a DataModel<E>
. Useful when you want to iterate over an
Iterable
, which includes any type of Collection
(which includes e.g. a Set
)
in for example <ui:repeat>
and <h:dataTable>
.
When iterating specifically over a Set using the above mentioned components setToList(Set)
is
an alternative to this. Use this for more general cases or when the exact collection type is unknown.
For those same components iterableToList(Iterable)
is another alternative. Use this when
a DataModel is specifically needed.
iterable
- The Iterable to be converted to a DataModel.public static java.lang.String joinArray(java.lang.Object array, java.lang.String separator)
array
- The array to be joined.separator
- The separator to be used. If null, then it defaults to empty string.java.lang.IllegalArgumentException
- When the given array is not an array at all.public static <E> java.lang.String joinCollection(java.util.Collection<E> collection, java.lang.String separator)
collection
- The collection to be joined.separator
- The separator to be used. If null, then it defaults to empty string.public static <K,V> java.lang.String joinMap(java.util.Map<K,V> map, java.lang.String pairSeparator, java.lang.String entrySeparator)
map
- The map to be joined.pairSeparator
- The key-value pair separator to be used. If null, then it defaults to empty string.entrySeparator
- The entry separator to be used. If null, then it defaults to empty string.public static java.lang.Object[][] splitArray(java.lang.Object array, int fragmentSize)
<ui:repeat>
structures, for example, when positioning a list of items into a grid based
layout system such as Twitter Bootstrap.array
- The array to be split.fragmentSize
- The size of each subarray.java.lang.IllegalArgumentException
- When the fragment size is less than 1.public static <T> java.util.List<java.util.List<T>> splitList(java.util.List<T> list, int fragmentSize)
<ui:repeat>
structures, for example, when positioning a list of items into a grid based
layout system such as Twitter Bootstrap.list
- The list to be split.fragmentSize
- The size of each sublist.java.lang.IllegalArgumentException
- When the fragment size is less than 1.public static java.lang.String toJson(java.lang.Object object)
Json.encode(Object)
.object
- Object to be encoded as JSON.Json.encode(Object)
public static java.lang.String printStackTrace(java.lang.Throwable exception)
exception
- The exception to print the stack trace for.