- java.lang.Object
-
- org.logicng.util.CollectionHelper
-
public final class CollectionHelper extends Object
A class which contains utility methods forCollectionobjects.- Since:
- 2.0.0
- Version:
- 2.3.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,C extends Collection<T>>
Cdifference(Collection<T> col1, Collection<T> col2, Supplier<C> collectionFactory)Computes the difference of the given two collections.static <T,C extends Collection<T>>
Cintersection(Collection<? extends Collection<T>> collections, Supplier<C> collectionFactory)Computes the intersection of the given collections.static <T,C extends Collection<T>>
Cintersection(Collection<T> col1, Collection<T> col2, Supplier<C> collectionFactory)Computes the intersection of two collections.static <T> StringmkString(Collection<T> collection, String delimiter)Builds a string representation of a collection using a delimiter.static <T> StringmkString(Collection<T> collection, String prefix, String delimiter, String suffix)Builds a string representation of a collection using a prefix, delimiter and suffix.static <T> StringmkString(T[] array, String delimiter)Builds a string representation of an array using a delimiter.static <T> StringmkString(T[] array, String prefix, String delimiter, String suffix)Builds a string representation of an array using a prefix, delimiter and suffix.static <T> booleannullOrEmpty(Collection<T> collection)Tests if the given collection isnullor empty.static <T> Collection<T>nullSafe(Collection<T> collection)Null safe wrapper for collections.static <T,C extends Collection<T>>
CnullSafe(Supplier<C> collectionSupplier, Supplier<C> collectionFactory)Null safe wrapper for collections.static <T,C extends Collection<T>>
Cunion(Collection<? extends Collection<T>> collections, Supplier<C> collectionFactory)Computes the union of the given collections.static <T,C extends Collection<T>>
Cunion(Collection<T> col1, Collection<T> col2, Supplier<C> collectionFactory)Computes the union of two collections.
-
-
-
Method Detail
-
nullOrEmpty
public static <T> boolean nullOrEmpty(Collection<T> collection)
Tests if the given collection isnullor empty.- Type Parameters:
T- the type of the elements in the collection, may be arbitrary- Parameters:
collection- the collection, may benull- Returns:
trueif the collection isnullor empty, otherwisefalse
-
nullSafe
public static <T,C extends Collection<T>> C nullSafe(Supplier<C> collectionSupplier, Supplier<C> collectionFactory)
Null safe wrapper for collections. Returns an (unmodifiable!) empty list if the given collection isnull, otherwise returns the given list unchanged.- Type Parameters:
T- the type of the elements in the collection, may be arbitraryC- the type parameters of the collection- Parameters:
collectionSupplier- the collection, may benullcollectionFactory- the supplier for the collection- Returns:
- the collection itself, if it is not
null, otherwise an unmodifiable empty list
-
nullSafe
public static <T> Collection<T> nullSafe(Collection<T> collection)
Null safe wrapper for collections. Returns an (unmodifiable!) empty list if the given collection isnull, otherwise returns the given list unchanged.- Type Parameters:
T- the type of the elements in the collection, may be arbitrary- Parameters:
collection- the collection, may benull- Returns:
- the collection itself, if it is not
null, otherwise an unmodifiable empty list
-
intersection
public static <T,C extends Collection<T>> C intersection(Collection<? extends Collection<T>> collections, Supplier<C> collectionFactory)
Computes the intersection of the given collections. Each collection treated in a null-safe manner, i.e. if a collection isnullthe collection is considered to be an empty collection.- Type Parameters:
T- the type parameters of the elementsC- the type parameters of the collection- Parameters:
collections- the collections the intersection should be computed forcollectionFactory- the supplier for the collection- Returns:
- the intersection of the collections
-
intersection
public static <T,C extends Collection<T>> C intersection(Collection<T> col1, Collection<T> col2, Supplier<C> collectionFactory)
Computes the intersection of two collections. Each collection treated in a null-safe manner, i.e. if a collection isnullthe collection is considered to be an empty collection.- Type Parameters:
T- the type parameters of the elementsC- the type parameters of the collection- Parameters:
col1- the first collectioncol2- the second collectioncollectionFactory- the supplier for the collection- Returns:
- the intersection of the two collections
-
union
public static <T,C extends Collection<T>> C union(Collection<? extends Collection<T>> collections, Supplier<C> collectionFactory)
Computes the union of the given collections. Each collection is treated in a null-safe manner, i.e. if a collection isnullthe collection is considered to be an empty collection- Type Parameters:
T- the type parameters of the elementsC- the type parameters of the collection- Parameters:
collections- the collections the union should be computed forcollectionFactory- the supplier for the collection- Returns:
- the union of the collections
-
union
public static <T,C extends Collection<T>> C union(Collection<T> col1, Collection<T> col2, Supplier<C> collectionFactory)
Computes the union of two collections. Each collection treated in a null-safe manner, i.e. if a collection isnullthe collection is considered to be an empty collection.- Type Parameters:
T- the type parameters of the elementsC- the type parameters of the collection- Parameters:
col1- the first collectioncol2- the second collectioncollectionFactory- the supplier for the collection- Returns:
- the union of the two collections
-
difference
public static <T,C extends Collection<T>> C difference(Collection<T> col1, Collection<T> col2, Supplier<C> collectionFactory)
Computes the difference of the given two collections. The result contains all elements from the first collection that are not contained within the second collection. Each collection treated in a null-safe manner, i.e. if a collection isnullthe collection is considered to be an empty collection.- Type Parameters:
T- the type parameters of the elementsC- the type parameters of the collection- Parameters:
col1- the first collectioncol2- the second collectioncollectionFactory- the supplier for the collection- Returns:
- the union of the two collections
-
mkString
public static <T> String mkString(Collection<T> collection, String delimiter)
Builds a string representation of a collection using a delimiter.- Type Parameters:
T- the type parameter of the elements- Parameters:
collection- the collectiondelimiter- the delimiter- Returns:
- the string representation of the collection
-
mkString
public static <T> String mkString(Collection<T> collection, String prefix, String delimiter, String suffix)
Builds a string representation of a collection using a prefix, delimiter and suffix.- Type Parameters:
T- the type parameter of the elements- Parameters:
collection- the collectionprefix- the prefixdelimiter- the delimitersuffix- the suffix- Returns:
- the string representation of the collection
-
mkString
public static <T> String mkString(T[] array, String delimiter)
Builds a string representation of an array using a delimiter.- Type Parameters:
T- the type parameter of the elements- Parameters:
array- the arraydelimiter- the delimiter- Returns:
- the string representation of the collection
-
mkString
public static <T> String mkString(T[] array, String prefix, String delimiter, String suffix)
Builds a string representation of an array using a prefix, delimiter and suffix.- Type Parameters:
T- the type parameter of the elements- Parameters:
array- the arrayprefix- the prefixdelimiter- the delimitersuffix- the suffix- Returns:
- the string representation of the collection
-
-