com.google.common.collect
Class Constraints

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

public final class Constraints
extends Object

Factories and utilities pertaining to the Constraint interface.

Constraints and collections 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 add new elements to the collection will call the provided constraint. However, this method does not verify that existing elements satisfy the constraint.

Parameters:
collection - the collection to constrain
constraint - the constraint that validates added elements
Returns:
a constrained view of the 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 add new elements to the set will call the provided constraint. However, this method does not verify that existing elements satisfy the constraint.

Parameters:
set - the set to constrain
constraint - the constraint that validates added elements
Returns:
a constrained view of the 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 add new elements to the sorted set will call the provided constraint. However, this method does not verify that existing elements satisfy the constraint.

Parameters:
sortedSet - the sorted set to constrain
constraint - the constraint that validates added elements
Returns:
a constrained view of the 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 add new elements to the list will call the provided constraint. However, this method does not verify that existing elements satisfy the constraint.

If list implements RandomAccess, so will the returned list.

Parameters:
list - the list to constrain
constraint - the constraint that validates added elements
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 add new elements to the multiset will call the provided constraint. However, this method does not verify that existing elements satisfy the constraint.

Parameters:
multiset - the multiset to constrain
constraint - the constraint that validates added elements
Returns:
a constrained view of the multiset