public final class IterableUtil extends GroupFormatUtil
DEFAULT_END, DEFAULT_START, ELEMENT_SEPARATOR, ELEMENT_SEPARATOR_WITH_NEWLINE, INDENTATION_AFTER_NEWLINE, INDENTATION_FOR_SINGLE_LINE, maxLengthForSingleLineDescription
Modifier | Constructor and Description |
---|---|
private |
IterableUtil() |
Modifier and Type | Method and Description |
---|---|
private static boolean |
doesDescriptionFitOnSingleLine(java.lang.String singleLineDescription) |
private static java.lang.String |
format(Representation representation,
java.lang.Iterable<?> iterable,
java.lang.String start,
java.lang.String end,
java.lang.String elementSeparator,
java.lang.String indentation) |
static boolean |
isNullOrEmpty(java.lang.Iterable<?> iterable)
Indicates whether the given
Iterable is null or empty. |
static java.lang.String |
multiLineFormat(Representation representation,
java.lang.Iterable<?> iterable) |
private static <T> T[] |
newArray(java.lang.Class<T> type,
int length) |
static <T> java.util.List<T> |
nonNullElementsIn(java.lang.Iterable<? extends T> i)
Returns all the non-
null elements in the given Iterable . |
static java.lang.String |
singleLineFormat(Representation representation,
java.lang.Iterable<?> iterable,
java.lang.String start,
java.lang.String end) |
static int |
sizeOf(java.lang.Iterable<?> iterable)
Returns the size of the given
Iterable . |
static java.lang.String |
smartFormat(Representation representation,
java.lang.Iterable<?> iterable)
Returns the
String representation of the given Iterable , or null if the given
Iterable is null . |
static <T> T[] |
toArray(java.lang.Iterable<? extends T> iterable)
Create an array from an
Iterable . |
static <T> T[] |
toArray(java.lang.Iterable<? extends T> iterable,
java.lang.Class<T> type)
Create an typed array from an
Iterable . |
private static <T> java.util.Collection<T> |
toCollection(java.lang.Iterable<T> iterable) |
setMaxLengthForSingleLineDescription
public static boolean isNullOrEmpty(java.lang.Iterable<?> iterable)
Iterable
is null
or empty.iterable
- the given Iterable
to check.true
if the given Iterable
is null
or empty, otherwise false
.public static int sizeOf(java.lang.Iterable<?> iterable)
Iterable
.iterable
- the Iterable
to get size.Iterable
.java.lang.NullPointerException
- if given Iterable
is null.public static <T> java.util.List<T> nonNullElementsIn(java.lang.Iterable<? extends T> i)
null
elements in the given Iterable
.T
- the type of elements of the Iterable
.i
- the given Iterable
.null
elements in the given Iterable
. An empty list is returned if the given
Iterable
is null
.public static <T> T[] toArray(java.lang.Iterable<? extends T> iterable)
Iterable
.
Note: this method will return Object[]. If you require a typed array please use toArray(Iterable, Class)
.
It's main usage is to keep the generic type for chaining call like in:
public S containsOnlyElementsOf(Iterable extends T> iterable) {
return containsOnly(toArray(iterable));
}
T
- the type of elements of the Iterable
.iterable
- an Iterable
to translate in an array.Iterable
in an array. null
if given Iterable
is
null.public static <T> T[] toArray(java.lang.Iterable<? extends T> iterable, java.lang.Class<T> type)
Iterable
.T
- the type of elements of the Iterable
.iterable
- an Iterable
to translate in an array.type
- the type of the resulting array.Iterable
in an array. null
if given Iterable
is
null.private static <T> java.util.Collection<T> toCollection(java.lang.Iterable<T> iterable)
private static <T> T[] newArray(java.lang.Class<T> type, int length)
public static java.lang.String smartFormat(Representation representation, java.lang.Iterable<?> iterable)
String
representation of the given Iterable
, or null
if the given
Iterable
is null
.
The Iterable
will be formatted to a single line if it does not exceed 100 char, otherwise each elements
will be formatted on a new line with 4 space indentation.
representation
- iterable
- the Iterable
to format.String
representation of the given Iterable
.public static java.lang.String singleLineFormat(Representation representation, java.lang.Iterable<?> iterable, java.lang.String start, java.lang.String end)
public static java.lang.String multiLineFormat(Representation representation, java.lang.Iterable<?> iterable)
private static boolean doesDescriptionFitOnSingleLine(java.lang.String singleLineDescription)
private static java.lang.String format(Representation representation, java.lang.Iterable<?> iterable, java.lang.String start, java.lang.String end, java.lang.String elementSeparator, java.lang.String indentation)