Package snap.util
Class ListUtils
java.lang.Object
snap.util.ListUtils
Utility methods for use with Java.util.List.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>
Adds an object to the given list and returns list (creates list if missing).static <T> void
addAllUnique
(List<T> aList, int anIndex, T... theObjects) Adds all object from second list to first list (creates first list if missing).static <T> void
addAllUnique
(List<T> aList, T... theObjects) Adds all object from second list to first list (creates first list if missing).static <T> void
Adds an object to the given list if object is absent (creates list if missing).static <T> void
addUniqueId
(List<T> aList, T anObj) Adds an object to the given list if identical object is missing (creates list if missing).static <T> List<T>
Returns a copy of the given list.static boolean
Returns whether list contains given object (accepts null list).static boolean
containsId
(List<?> aList, Object anObj) Returns whether list contains identical given object (accepts null list).static boolean
Returns whether lists have same objects in them.static <T> List<T>
filter
(Collection<T> aList, Predicate<? super T> pred) Returns a filtered array for given original and Predicate.static <T,
R> R[] filterToArray
(Collection<T> aList, Predicate<? super T> pred, Class<R> aClass) Returns a filtered array for given original and Predicate.static <T> T
findMatch
(Collection<T> aList, Predicate<? super T> aPred) Returns the first item in collection that matches given predicate (or null).static <T> int
findMatchIndex
(List<T> aList, Predicate<? super T> aPred) Returns the index of first item in list that matches given predicate (or -1).static <T> T
Returns the object at the given index (returns null object for null list or invalid index).static <T> List<T>
getFiltered
(Collection<T> aList, Predicate<? super T> pred) Returns a list of derived items for given collection of original items.static <T> T
Returns the last object in the given list.static <T> T
getMax
(List<T> aList, Comparator<T> aComparator) Returns the max value of a given list using given comparator function.static <T> T
getMin
(List<T> aList, Comparator<T> aComparator) Returns the min value of a given list using given comparator function.static <T> List<T>
getReverse
(List<T> aList) Returns the reversed list.static <T> boolean
hasMatch
(Collection<T> aList, Predicate<? super T> aPred) Returns whether given collection has match for given predicate.static int
Returns index of identical given object in given list.static String
joinStrings
(List<?> aList, String aString) Returns a string by concatenating strings in given list separated by given string.static <T,
R> List<R> map
(Collection<T> aList, Function<? super T, ? extends R> aFunction) Returns a mapped array for given original and Function.static <T,
R> R[] mapNonNullToArray
(Collection<T> aList, Function<? super T, ? extends R> aFunction, Class<R> aClass) Returns a mapped array for given original list and Function, removing nulls.static <T,
R> R[] mapToArray
(Collection<T> aList, Function<? super T, ? extends R> aFunction, Class<R> aClass) Returns a mapped array for given original and Function.static <T> String
mapToStringsAndJoin
(List<T> aList, Function<T, String> aFunc, String aDelim) Maps a list of items to strings using given function, then joins them by given delimiter.static <T> void
moveToFront
(List<T> aList, int anIndex) Moves the object at the given index to the front of the list.static <T> void
moveToFront
(List<T> aList, T anObj) Move the given object to the front of the list.static int
Removes the object identical to the given object from list.static <T> T
removeLast
(List<T> aList) Removes the last object from given list.static void
Reverses the items in the given list.static int
Returns the size of a list (accepts null list).static <T> void
Adds object from list 2 to list 1, unless they are already present (then removes them).
-
Constructor Details
-
ListUtils
public ListUtils()
-
-
Method Details
-
size
Returns the size of a list (accepts null list). -
get
Returns the object at the given index (returns null object for null list or invalid index). -
getLast
Returns the last object in the given list. -
contains
Returns whether list contains given object (accepts null list). -
containsId
Returns whether list contains identical given object (accepts null list). -
indexOfId
Returns index of identical given object in given list. -
add
Adds an object to the given list and returns list (creates list if missing). -
addUnique
Adds an object to the given list if object is absent (creates list if missing). -
addUniqueId
Adds an object to the given list if identical object is missing (creates list if missing). -
addAllUnique
Adds all object from second list to first list (creates first list if missing). -
addAllUnique
Adds all object from second list to first list (creates first list if missing). -
removeLast
Removes the last object from given list. -
removeId
Removes the object identical to the given object from list. -
reverse
Reverses the items in the given list. -
getReverse
Returns the reversed list. -
joinStrings
Returns a string by concatenating strings in given list separated by given string. -
xor
Adds object from list 2 to list 1, unless they are already present (then removes them). -
moveToFront
Moves the object at the given index to the front of the list. -
moveToFront
Move the given object to the front of the list. -
equalsId
Returns whether lists have same objects in them. -
clone
Returns a copy of the given list. -
getFiltered
Returns a list of derived items for given collection of original items. -
filter
Returns a filtered array for given original and Predicate. -
filterToArray
public static <T,R> R[] filterToArray(Collection<T> aList, Predicate<? super T> pred, Class<R> aClass) Returns a filtered array for given original and Predicate. -
map
Returns a mapped array for given original and Function. -
mapToArray
public static <T,R> R[] mapToArray(Collection<T> aList, Function<? super T, ? extends R> aFunction, Class<R> aClass) Returns a mapped array for given original and Function. -
mapNonNullToArray
public static <T,R> R[] mapNonNullToArray(Collection<T> aList, Function<? super T, ? extends R> aFunction, Class<R> aClass) Returns a mapped array for given original list and Function, removing nulls. -
hasMatch
Returns whether given collection has match for given predicate. -
findMatch
Returns the first item in collection that matches given predicate (or null). -
findMatchIndex
Returns the index of first item in list that matches given predicate (or -1). -
mapToStringsAndJoin
public static <T> String mapToStringsAndJoin(List<T> aList, Function<T, String> aFunc, String aDelim) Maps a list of items to strings using given function, then joins them by given delimiter. -
getMin
Returns the min value of a given list using given comparator function. -
getMax
Returns the max value of a given list using given comparator function.
-