Package com.rometools.utils
Class Lists
- java.lang.Object
-
- com.rometools.utils.Lists
-
public final class Lists extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> List<T>create(T item)Creates a new List with the given item as the first entry.static <T> List<T>createWhenNull(List<T> list)Returns the list when it is not null.static <T> List<T>emptyToNull(List<T> list)Returns null, when the given list is empty or nullstatic <T> TfirstEntry(List<T> list)Extracts the first entry of the list when it is not null and contains values.static booleanisEmpty(List<?> list)Checks whether the list is null or empty.static booleanisNotEmpty(List<?> list)Checks whether the list is not null and not empty.static booleansizeIs(List<?> list, int size)Checks whether the list has the given size.
-
-
-
Method Detail
-
createWhenNull
public static <T> List<T> createWhenNull(List<T> list)
Returns the list when it is not null. Returns a new list otherwise.- Parameters:
list- The list to process, can be null- Returns:
- The input list when it is not null, a new list otherwise
-
create
public static <T> List<T> create(T item)
Creates a new List with the given item as the first entry.- Parameters:
item- The item to add to the new list- Returns:
- List containing the given item
-
firstEntry
public static <T> T firstEntry(List<T> list)
Extracts the first entry of the list when it is not null and contains values.- Parameters:
list- The list to extract the first entry from, can be null- Returns:
- The first entry of the list when it is not null or empty, null otherwise
-
isEmpty
public static boolean isEmpty(List<?> list)
Checks whether the list is null or empty.- Parameters:
list- The list to check- Returns:
- true when the list is null or empty, false otherwise
-
isNotEmpty
public static boolean isNotEmpty(List<?> list)
Checks whether the list is not null and not empty.- Parameters:
list- The list to check- Returns:
- true when the list is not null and not empty
-
sizeIs
public static boolean sizeIs(List<?> list, int size)
Checks whether the list has the given size. A null list is treated like a list without entries.- Parameters:
list- The list to checksize- The size to check- Returns:
- true when the list has the given size or when size = 0 and the list is null, false otherwise
-
-