Package com.google.common.collect
Class Constraints
- java.lang.Object
-
- com.google.common.collect.Constraints
-
@GwtCompatible final class Constraints extends java.lang.Object
Factories and utilities pertaining to theConstraint
interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Constraints.ConstrainedCollection<E>
private static class
Constraints.ConstrainedList<E>
(package private) static class
Constraints.ConstrainedListIterator<E>
(package private) static class
Constraints.ConstrainedRandomAccessList<E>
(package private) static class
Constraints.ConstrainedSet<E>
private static class
Constraints.ConstrainedSortedSet<E>
-
Constructor Summary
Constructors Modifier Constructor Description private
Constraints()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <E> java.util.Collection<E>
checkElements(java.util.Collection<E> elements, Constraint<? super E> constraint)
static <E> java.util.Collection<E>
constrainedCollection(java.util.Collection<E> collection, Constraint<? super E> constraint)
Returns a constrained view of the specified collection, using the specified constraint.static <E> java.util.List<E>
constrainedList(java.util.List<E> list, Constraint<? super E> constraint)
Returns a constrained view of the specified list, using the specified constraint.private static <E> java.util.ListIterator<E>
constrainedListIterator(java.util.ListIterator<E> listIterator, Constraint<? super E> constraint)
Returns a constrained view of the specified list iterator, using the specified constraint.static <E> java.util.Set<E>
constrainedSet(java.util.Set<E> set, Constraint<? super E> constraint)
Returns a constrained view of the specified set, using the specified constraint.static <E> java.util.SortedSet<E>
constrainedSortedSet(java.util.SortedSet<E> sortedSet, Constraint<? super E> constraint)
Returns a constrained view of the specified sorted set, using the specified constraint.(package private) static <E> java.util.Collection<E>
constrainedTypePreservingCollection(java.util.Collection<E> collection, Constraint<E> constraint)
-
-
-
Method Detail
-
constrainedCollection
public static <E> java.util.Collection<E> constrainedCollection(java.util.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.The returned collection is not serializable.
- Parameters:
collection
- the collection to constrainconstraint
- the constraint that validates added elements- Returns:
- a constrained view of the collection
-
constrainedSet
public static <E> java.util.Set<E> constrainedSet(java.util.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.The returned set is not serializable.
- Parameters:
set
- the set to constrainconstraint
- the constraint that validates added elements- Returns:
- a constrained view of the set
-
constrainedSortedSet
public static <E> java.util.SortedSet<E> constrainedSortedSet(java.util.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.The returned set is not serializable.
- Parameters:
sortedSet
- the sorted set to constrainconstraint
- the constraint that validates added elements- Returns:
- a constrained view of the sorted set
-
constrainedList
public static <E> java.util.List<E> constrainedList(java.util.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
implementsRandomAccess
, so will the returned list. The returned list is not serializable.- Parameters:
list
- the list to constrainconstraint
- the constraint that validates added elements- Returns:
- a constrained view of the list
-
constrainedListIterator
private static <E> java.util.ListIterator<E> constrainedListIterator(java.util.ListIterator<E> listIterator, Constraint<? super E> constraint)
Returns a constrained view of the specified list iterator, using the specified constraint. Any operations that would add new elements to the underlying list will be verified by the constraint.- Parameters:
listIterator
- the iterator for which to return a constrained viewconstraint
- the constraint for elements in the list- Returns:
- a constrained view of the specified iterator
-
constrainedTypePreservingCollection
static <E> java.util.Collection<E> constrainedTypePreservingCollection(java.util.Collection<E> collection, Constraint<E> constraint)
-
checkElements
private static <E> java.util.Collection<E> checkElements(java.util.Collection<E> elements, Constraint<? super E> constraint)
-
-