Package it.unive.lisa.util.collections
Class CollectionUtilities
- java.lang.Object
-
- it.unive.lisa.util.collections.CollectionUtilities
-
public final class CollectionUtilities extends java.lang.ObjectUtility methods for operations onCollections.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.Collection<T>collect(T... objs)Stores the given objects into a collection and returns it.static <T,C extends java.util.Collection<T>>
booleanequals(C first, C second, java.util.function.BiPredicate<T,T> equalityTest)Tests if two collections contain the same elements, using a custom equality test to determine if two elements are to be considered equals.static <T,C extends java.util.Collection<T>>
voidjoin(C first, C second, C result, java.util.function.BiPredicate<T,T> equalityTest, java.util.function.BinaryOperator<T> joiner)Joins (union) two collections, using a custom equality test to determine if two elements are to be considered equals and thus joined together through the givenjoiner.static <T> intnullSafeCompare(boolean nullFirst, T left, T right, java.util.Comparator<T> comparator)Anull-safe comparison callback that invokes the given comparator only if the given objects are both non-null.
-
-
-
Method Detail
-
nullSafeCompare
public static <T> int nullSafeCompare(boolean nullFirst, T left, T right, java.util.Comparator<T> comparator)Anull-safe comparison callback that invokes the given comparator only if the given objects are both non-null.- Type Parameters:
T- the type of compared objects- Parameters:
nullFirst- iftrue,nullvalues will be treated as objects that appear before all non-nullobjects. This means thatnullSafeCompare(true, null, obj, ...)returns-1. Iffalse, the same invocation returns1.left- the first element to compareright- the second element to comparecomparator- the comparator to use if both objects are non-null- Returns:
- an integer value determined by the ordering relation between
objects, as in
Comparator.compare(Object, Object)
-
equals
public static <T,C extends java.util.Collection<T>> boolean equals(C first, C second, java.util.function.BiPredicate<T,T> equalityTest)Tests if two collections contain the same elements, using a custom equality test to determine if two elements are to be considered equals. The two input collections are compared in an order-insensitive fashion.- Type Parameters:
T- the type of elements in the collectionsC- the type of the collections to test- Parameters:
first- the first collectionsecond- the second collectionequalityTest- the tester for equality of the objects within the collections- Returns:
trueonly if the collections contain exactly the same set of elements (order-insensitive)
-
join
public static <T,C extends java.util.Collection<T>> void join(C first, C second, C result, java.util.function.BiPredicate<T,T> equalityTest, java.util.function.BinaryOperator<T> joiner)Joins (union) two collections, using a custom equality test to determine if two elements are to be considered equals and thus joined together through the givenjoiner. All elements that, according to the givenequalityTestare contained only in one of the input collections, will be added to the result as-is.- Type Parameters:
T- the type of elements in the collectionsC- the type of the collections to join- Parameters:
first- the first collectionsecond- the second collectionresult- the collection to be used as result, where joined elements will be addedequalityTest- the tester for equality of the objects within the collectionsjoiner- the function that computes the join of two equal elements
-
collect
@SafeVarargs public static <T> java.util.Collection<T> collect(T... objs)
Stores the given objects into a collection and returns it.- Type Parameters:
T- the type of objects- Parameters:
objs- the objects to store- Returns:
- a (modifiable) collection containing the given objects
-
-