Class Constraints


  • @Beta
    @Deprecated
    @GwtCompatible
    public final class Constraints
    extends java.lang.Object
    Deprecated.
    Use Preconditions for basic checks. In place of constrained collections, we encourage you to check your preconditions explicitly instead of leaving that work to the collection implementation. For the specific case of rejecting null, consider the immutable collections. This class is scheduled for removal in Guava 16.0.
    Factories and utilities pertaining to the Constraint interface.
    Since:
    3.0
    See Also:
    MapConstraints
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static <E> java.util.Collection<E> constrainedCollection​(java.util.Collection<E> collection, Constraint<? super E> constraint)
      Deprecated.
      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)
      Deprecated.
      Returns a constrained view of the specified list, using the specified constraint.
      static <E> Multiset<E> constrainedMultiset​(Multiset<E> multiset, Constraint<? super E> constraint)
      Deprecated.
      Returns a constrained view of the specified multiset, using the specified constraint.
      static <E> java.util.Set<E> constrainedSet​(java.util.Set<E> set, Constraint<? super E> constraint)
      Deprecated.
      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)
      Deprecated.
      Returns a constrained view of the specified sorted set, using the specified constraint.
      static <E> Constraint<E> notNull()
      Deprecated.
      Returns a constraint that verifies that the element is not null.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • notNull

        public static <E> Constraint<E> notNull()
        Deprecated.
        Returns a constraint that verifies that the element is not null. If the element is null, a NullPointerException is thrown.
      • constrainedCollection

        public static <E> java.util.Collection<E> constrainedCollection​(java.util.Collection<E> collection,
                                                                        Constraint<? super E> constraint)
        Deprecated.
        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 constrain
        constraint - 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)
        Deprecated.
        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 constrain
        constraint - 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)
        Deprecated.
        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 constrain
        constraint - 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)
        Deprecated.
        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. The returned list is not serializable.

        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)
        Deprecated.
        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.

        The returned multiset is not serializable.

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