Class RMCollectionUtils
java.lang.Object
org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils
Various common helper methods for Collections. This class is probably only appropriate for use with relatively small collections as it has not been optimised for dealing with large collections.
- Since:
- 2.4.a
- Author:
- Neil Mc Erlean
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThis enum represents a change in an entry between 2 collections. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Serializable,LIST extends Serializable & List<T>>
LISTasSerializableList(T... elements) Returns a Serializable List containing all of the provided elements.static <T> HashSet<T>asSet(Collection<T> c) Returns a Set containing all of the elements in the provided collection.static <T> HashSet<T>asSet(T... elements) Returns a Set containing all of the provided elements.static <K,V> RMCollectionUtils.Difference Determines the change in a Map entry between two Maps.static <T> List<T>getDuplicateElements(List<T> l) Gets the list of duplicate elements contained within the specified list, if any.static <T> TReturns the head (element at index 0) of the provided List.static booleanisEmpty(Serializable value) Check if a property is null or an empty collection.static <T> List<T>Returns the tail of the provided List i.e. the sublist which contains all elements of the given list except thehead.static <T> com.google.common.collect.ImmutableSet<T>toImmutableSet(Collection<T> collection) Convert a collection to an immutable set.
-
Method Details
-
getDuplicateElements
Gets the list of duplicate elements contained within the specified list, if any.- Type Parameters:
T- the element type of the list.- Parameters:
l- the list in which to find duplicates.- Returns:
- a list of duplicate elements. If there are no duplicates, returns an empty list.
-
head
Returns the head (element at index 0) of the provided List.- Type Parameters:
T- the type of the List.- Parameters:
l- the list whose head is sought.- Returns:
- the head element or
nullfor the empty list. - Throws:
NullPointerException- if l isnull
-
tail
Returns the tail of the provided List i.e. the sublist which contains all elements of the given list except thehead.- Type Parameters:
T- the type of the List.- Parameters:
l- the list whose tail is sought.- Returns:
- the tail sublist, which will be an empty list if the provided list had only a single element.
- Throws:
NullPointerException- if l isnullUnsupportedOperationException- if the provided list was empty.
-
asSerializableList
@SafeVarargs public static <T extends Serializable,LIST extends Serializable & List<T>> LIST asSerializableList(T... elements) Returns a Serializable List containing all of the provided elements.- Type Parameters:
T- the element type.- Parameters:
elements- the elements to put in a list.- Returns:
- a Serializable List containing all the provided elements.
-
asSet
Returns a Set containing all of the provided elements. Duplicate elements will be removed as per theSetcontract.- Type Parameters:
T- the element type.- Parameters:
elements- the elements to put in a Set.- Returns:
- a Set containing all the provided elements (without duplicates).
-
asSet
Returns a Set containing all of the elements in the provided collection. Duplicate elements will be removed as per theSetcontract.- Type Parameters:
T- the element type.- Parameters:
c- the elements to put in a Set.- Returns:
- a Set containing all the provided elements (without duplicates).
-
diffKey
Determines the change in a Map entry between two Maps. Note that both maps must have the same types of key-value pair.- Type Parameters:
K- the type of the key.V- the type of the value.- Parameters:
from- the first collection.to- the second collection.key- the key identifying the entry.- Returns:
- the
RMCollectionUtils.Difference. - Throws:
IllegalArgumentException- ifkeyisnull.
-
toImmutableSet
public static <T> com.google.common.collect.ImmutableSet<T> toImmutableSet(Collection<T> collection) Convert a collection to an immutable set. Any instances of null in the original collection will be removed.- Type Parameters:
T- The type of the object in the collection.- Parameters:
collection- The original collection.- Returns:
- The immutable set.
-
isEmpty
Check if a property is null or an empty collection. Note that this is the same as {org.apache.commons.collections.CollectionUtils.isEmpty(Collection)}, except that it takes a Serializable rather than a Collection. This avoids awkward casting exceptions when working with properties.- Parameters:
value- The (probably Collection) value to check.- Returns:
- true if the supplied value is null or an empty collection.
-