Package de.alpharogroup.collections
Class CollectionExtensions
- java.lang.Object
-
- de.alpharogroup.collections.CollectionExtensions
-
public final class CollectionExtensions extends java.lang.ObjectThe classCollectionExtensionsis an extension class for use withCollectionobjects.
-
-
Constructor Summary
Constructors Constructor Description CollectionExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voiddifference(java.util.Collection<T> one, java.util.Collection<T> other)Removes all of the first given collection's elements that are also contained in the second given collection.static <T> inthashCode(java.util.Collection<T[]> arrayObjects)Returns a hash code based on the contents of the collection that contains array objects.static <T> java.util.Collection<T>intersection(java.util.Collection<T>... toIntersect)Intersection of the given collections.static <T> booleanisEmpty(java.util.Collection<T> collection)Checks if the givenCollectionis null or empty.static <T> booleanisEqualCollection(java.util.Collection<T> one, java.util.Collection<T> other)Compare the given twoCollectionobjects in equality.static <T> booleanisNotEmpty(java.util.Collection<T> collection)Checks if the givenCollectionis not null or emptystatic <T> java.util.Collection<java.util.List<T>>partition(java.util.Collection<T> collection, int size)Groups the givenCollectionto parts from the specified size.static <T> java.util.Optional<java.lang.Boolean>preconditionOfEqualCollection(java.util.Collection<T> one, java.util.Collection<T> other)Checks the given twoCollectionobjects if there are null and return the appropriateOptionalboolean value
-
-
-
Method Detail
-
isEqualCollection
public static <T> boolean isEqualCollection(java.util.Collection<T> one, java.util.Collection<T> other)Compare the given twoCollectionobjects in equality.- Type Parameters:
T- the generic type of the elements- Parameters:
one- the oneother- the other- Returns:
- true, if the given two
Collectionobjects are equal otherwise false
-
preconditionOfEqualCollection
public static <T> java.util.Optional<java.lang.Boolean> preconditionOfEqualCollection(java.util.Collection<T> one, java.util.Collection<T> other)Checks the given twoCollectionobjects if there are null and return the appropriateOptionalboolean value- Type Parameters:
T- the generic type of the elements- Parameters:
one- the oneother- the other- Returns:
- the
Optionalboolean if value is true both are null, if value is false given twoCollectionobjects are not equal otherwise theOptionalis empty
-
difference
public static <T> void difference(java.util.Collection<T> one, java.util.Collection<T> other)Removes all of the first given collection's elements that are also contained in the second given collection.- Type Parameters:
T- the generic type- Parameters:
one- the collection where the element will be removed if any containing elements existsother- collection containing elements to be removed from the first given collection
-
intersection
@SafeVarargs public static <T> java.util.Collection<T> intersection(java.util.Collection<T>... toIntersect)
Intersection of the given collections. Internally this method uses theCollection.retainAll(Collection)for come to the result.- Type Parameters:
T- the generic type- Parameters:
toIntersect- the to intersect- Returns:
- the result of the intersection. This will be the first collection that contains the result.
-
isNotEmpty
public static <T> boolean isNotEmpty(java.util.Collection<T> collection)
Checks if the givenCollectionis not null or empty- Type Parameters:
T- the generic type- Parameters:
collection- The collection to check- Returns:
- true if the given
Collectionis null or empty otherwise false
-
isEmpty
public static <T> boolean isEmpty(java.util.Collection<T> collection)
Checks if the givenCollectionis null or empty.- Type Parameters:
T- the generic type- Parameters:
collection- The collection to check- Returns:
- true if the given
Collectionis null or empty otherwise false.
-
hashCode
public static <T> int hashCode(java.util.Collection<T[]> arrayObjects)
Returns a hash code based on the contents of the collection that contains array objects.- Type Parameters:
T- the generic type of the array objects- Parameters:
arrayObjects- the collection that contains array objects whose content-based hash code to compute- Returns:
- the content-based hash code for the given collection that contains array objects
-
partition
public static <T> java.util.Collection<java.util.List<T>> partition(java.util.Collection<T> collection, int size)Groups the givenCollectionto parts from the specified size.- Type Parameters:
T- the generic type- Parameters:
collection- the collectionsize- the size- Returns:
- the collection
-
-