com.google.common.collect
Class Constraints

java.lang.Object
  extended by com.google.common.collect.Constraints

public final class Constraints
extends Object

Factory and utilities pertaining to the Constraint interface.

Constraint and Collection instances returned by this class are serializable.

Author:
Mike Bostock
See Also:
MapConstraints

Field Summary
static Constraint<Object> NOT_NULL
          A constraint that verifies that the element is not null.
 
Method Summary
static
<E> Collection<E>
constrainedCollection(Collection<E> collection, Constraint<? super E> constraint)
          Returns a constrained view of the specified collection, using the specified constraint.
static
<E> List<E>
constrainedList(List<E> list, Constraint<? super E> constraint)
          Returns a constrained view of the specified list, using the specified constraint.
static
<E> Multiset<E>
constrainedMultiset(Multiset<E> multiset, Constraint<? super E> constraint)
          Returns a constrained view of the specified multiset, using the specified constraint.
static
<E> Set<E>
constrainedSet(Set<E> set, Constraint<? super E> constraint)
          Returns a constrained view of the specified set, using the specified constraint.
static
<E> SortedSet<E>
constrainedSortedSet(SortedSet<E> sortedSet, Constraint<? super E> constraint)
          Returns a constrained view of the specified sorted set, using the specified constraint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_NULL

public static final Constraint<Object> NOT_NULL
A constraint that verifies that the element is not null. If the element is null, a NullPointerException is thrown.

Method Detail

constrainedCollection

public static <E> Collection<E> constrainedCollection(Collection<E> collection,
                                                      Constraint<? super E> constraint)
Returns a constrained view of the specified collection, using the specified constraint. Any operations that would add new elements to the collection will be verified by the constraint.

Parameters:
collection - the collection for which to return a constrained view
constraint - the constraint for elements in the collection
Returns:
a constrained view of the specified collection

constrainedSet

public static <E> Set<E> constrainedSet(Set<E> set,
                                        Constraint<? super E> constraint)
Returns a constrained view of the specified set, using the specified constraint. Any operations that would add new elements to the set will be verified by the constraint.

Parameters:
set - the set for which to return a constrained view
constraint - the constraint for elements in the set
Returns:
a constrained view of the specified set

constrainedSortedSet

public static <E> SortedSet<E> constrainedSortedSet(SortedSet<E> sortedSet,
                                                    Constraint<? super E> constraint)
Returns a constrained view of the specified sorted set, using the specified constraint. Any operations that would add new elements to the sorted set will be verified by the constraint.

Parameters:
sortedSet - the sorted set for which to return a constrained view
constraint - the constraint for elements in the sorted set
Returns:
a constrained view of the specified sorted set

constrainedList

public static <E> List<E> constrainedList(List<E> list,
                                          Constraint<? super E> constraint)
Returns a constrained view of the specified list, using the specified constraint. Any operations that would add new elements to the list will be verified by the constraint.

If list implements RandomAccess, so will the returned list.

Parameters:
list - the list for which to return a constrained view
constraint - the constraint for elements in the list
Returns:
a constrained view of the list

constrainedMultiset

public static <E> Multiset<E> constrainedMultiset(Multiset<E> multiset,
                                                  Constraint<? super E> constraint)
Returns a constrained view of the specified multiset, using the specified constraint. Any operations that would add new elements to the underlying multiset will be verified by the constraint.

Parameters:
multiset - the multiset for which to return a constrained view
constraint - the constraint for elements in the multiset
Returns:
a constrained view of the specified multiset