Class CollectionsExpressionVariable
- java.lang.Object
-
- com.broadleafcommerce.rulesengine.expression.util.CollectionsExpressionVariable
-
- All Implemented Interfaces:
ExpressionVariable
public class CollectionsExpressionVariable extends Object implements ExpressionVariable
Common, null-safe, collection operations
An instance of this class will usually be accessible as a variable within an expression via
#collections. This is partly a wrapper aroundCollectionUtilsto provide a layer of abstraction and because CollectionUtils employs static methods. Note that not all methods ofCollectionUtilshave been implemented just those that seemed most relevant for expression evaluation.- Author:
- Nathan Moore (nathandmoore)
-
-
Constructor Summary
Constructors Constructor Description CollectionsExpressionVariable()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> booleancontains(T value, Collection<T> collection)booleancontainsAll(Collection<?> coll2, Collection<?> coll1)Whether the second collection contains all of the elements from the first.booleancontainsAny(Collection<?> coll2, Collection<?> coll1)Whether the second collection contains any elements from the first.booleancontainsNone(Collection<?> coll2, Collection<?> coll1)Whether the second collections contains none of the elements form the first.booleanequals(Collection<?> coll2, Collection<?> coll1)Performs a deep equals on the 2 collections.StringgetName()booleanisEmpty(Collection<?> collection)Whether the collection is empty or null.<T> booleannotContains(Collection<T> value, Collection<T> collection)Whether the collection defined byvalueis not contained by the collection.<T> booleannotContains(T[] value, Collection<T> collection)Whether the array defined byvalueis not contained by the collection.<T> booleannotContains(T value, Collection<T> collection)Whether the value is not contained by the collection.
-
-
-
Field Detail
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public String getName()
- Specified by:
getNamein interfaceExpressionVariable- Returns:
- Name of the variable, must not be null
-
isEmpty
public boolean isEmpty(@Nullable Collection<?> collection)Whether the collection is empty or null.
-
equals
public boolean equals(@Nullable Collection<?> coll2, @Nullable Collection<?> coll1)Performs a deep equals on the 2 collections.
-
contains
public <T> boolean contains(@Nullable T value, @Nullable Collection<T> collection)Whether thevalueis found within thecollectionusingCollection.contains(Object). This method is dynamic and will work slightly differently when given an array or a collection to validate against. In that scenario, the contents ofvalueare traversed to see if all of the elements are contained withincollection. Ifvalueis null, then thecollectionmust contain a null value- Parameters:
value- what to check for, which can also be an array or collectioncollection- collection to check- Returns:
- whether or not everything defined by
valueis contained withincollection
-
notContains
public <T> boolean notContains(@Nullable T value, @Nullable Collection<T> collection)Whether the value is not contained by the collection.
-
notContains
public <T> boolean notContains(@Nullable Collection<T> value, @Nullable Collection<T> collection)Whether the collection defined byvalueis not contained by the collection.
-
notContains
public <T> boolean notContains(@Nullable T[] value, @Nullable Collection<T> collection)Whether the array defined byvalueis not contained by the collection.
-
containsAny
public boolean containsAny(@Nullable Collection<?> coll2, @Nullable Collection<?> coll1)Whether the second collection contains any elements from the first. If either is null, returns false.
-
containsAll
public boolean containsAll(@Nullable Collection<?> coll2, @Nullable Collection<?> coll1)Whether the second collection contains all of the elements from the first. If both are empty or null, returns true
-
containsNone
public boolean containsNone(@Nullable Collection<?> coll2, @Nullable Collection<?> coll1)Whether the second collections contains none of the elements form the first. If either is null, returns true.
-
-