Class MapConstraints


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

      Constructors 
      Modifier Constructor Description
      private MapConstraints()
      Deprecated.
       
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      private static <K,​V>
      java.util.Map<K,​V>
      checkMap​(java.util.Map<? extends K,​? extends V> map, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
       
      private static <K,​V>
      java.util.Collection<V>
      checkValues​(K key, java.lang.Iterable<? extends V> values, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
       
      private static <K,​V>
      java.util.Set<java.util.Map.Entry<K,​java.util.Collection<V>>>
      constrainedAsMapEntries​(java.util.Set<java.util.Map.Entry<K,​java.util.Collection<V>>> entries, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
      Returns a constrained view of the specified set of asMap entries, using the specified constraint.
      private static <K,​V>
      java.util.Map.Entry<K,​java.util.Collection<V>>
      constrainedAsMapEntry​(java.util.Map.Entry<K,​java.util.Collection<V>> entry, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
      Returns a constrained view of the specified asMap entry, using the specified constraint.
      private static <K,​V>
      java.util.Collection<java.util.Map.Entry<K,​V>>
      constrainedEntries​(java.util.Collection<java.util.Map.Entry<K,​V>> entries, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
      Returns a constrained view of the specified collection (or set) of entries, using the specified constraint.
      private static <K,​V>
      java.util.Map.Entry<K,​V>
      constrainedEntry​(java.util.Map.Entry<K,​V> entry, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
      Returns a constrained view of the specified entry, using the specified constraint.
      private static <K,​V>
      java.util.Set<java.util.Map.Entry<K,​V>>
      constrainedEntrySet​(java.util.Set<java.util.Map.Entry<K,​V>> entries, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
      Returns a constrained view of the specified set of entries, using the specified constraint.
      static <K,​V>
      ListMultimap<K,​V>
      constrainedListMultimap​(ListMultimap<K,​V> multimap, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
      Returns a constrained view of the specified list multimap, using the specified constraint.
      static <K,​V>
      java.util.Map<K,​V>
      constrainedMap​(java.util.Map<K,​V> map, MapConstraint<? super K,​? super V> constraint)
      Deprecated.
      Returns a constrained view of the specified map, using the specified constraint.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MapConstraints

        private MapConstraints()
        Deprecated.
    • Method Detail

      • constrainedMap

        public static <K,​V> java.util.Map<K,​V> constrainedMap​(java.util.Map<K,​V> map,
                                                                          MapConstraint<? super K,​? super V> constraint)
        Deprecated.
        Returns a constrained view of the specified map, using the specified constraint. Any operations that add new mappings will call the provided constraint. However, this method does not verify that existing mappings satisfy the constraint.

        The returned map is not serializable.

        Parameters:
        map - the map to constrain
        constraint - the constraint that validates added entries
        Returns:
        a constrained view of the specified map
      • constrainedListMultimap

        public static <K,​V> ListMultimap<K,​V> constrainedListMultimap​(ListMultimap<K,​V> multimap,
                                                                                  MapConstraint<? super K,​? super V> constraint)
        Deprecated.
        Returns a constrained view of the specified list multimap, using the specified constraint. Any operations that add new mappings will call the provided constraint. However, this method does not verify that existing mappings satisfy the constraint.

        Note that the generated multimap's Multimap.removeAll(java.lang.Object) and Multimap.replaceValues(K, java.lang.Iterable<? extends V>) methods return collections that are not constrained.

        The returned multimap is not serializable.

        Parameters:
        multimap - the multimap to constrain
        constraint - the constraint that validates added entries
        Returns:
        a constrained view of the specified multimap
      • constrainedEntry

        private static <K,​V> java.util.Map.Entry<K,​V> constrainedEntry​(java.util.Map.Entry<K,​V> entry,
                                                                                   MapConstraint<? super K,​? super V> constraint)
        Deprecated.
        Returns a constrained view of the specified entry, using the specified constraint. The Map.Entry.setValue(V) operation will be verified with the constraint.
        Parameters:
        entry - the entry to constrain
        constraint - the constraint for the entry
        Returns:
        a constrained view of the specified entry
      • constrainedAsMapEntry

        private static <K,​V> java.util.Map.Entry<K,​java.util.Collection<V>> constrainedAsMapEntry​(java.util.Map.Entry<K,​java.util.Collection<V>> entry,
                                                                                                              MapConstraint<? super K,​? super V> constraint)
        Deprecated.
        Returns a constrained view of the specified asMap entry, using the specified constraint. The Map.Entry.setValue(V) operation will be verified with the constraint, and the collection returned by Map.Entry.getValue() will be similarly constrained.
        Parameters:
        entry - the asMap entry to constrain
        constraint - the constraint for the entry
        Returns:
        a constrained view of the specified entry
      • constrainedAsMapEntries

        private static <K,​V> java.util.Set<java.util.Map.Entry<K,​java.util.Collection<V>>> constrainedAsMapEntries​(java.util.Set<java.util.Map.Entry<K,​java.util.Collection<V>>> entries,
                                                                                                                               MapConstraint<? super K,​? super V> constraint)
        Deprecated.
        Returns a constrained view of the specified set of asMap entries, using the specified constraint. The Map.Entry.setValue(V) operation will be verified with the constraint, and the collection returned by Map.Entry.getValue() will be similarly constrained. The add and addAll operations simply forward to the underlying set, which throws an UnsupportedOperationException per the multimap specification.
        Parameters:
        entries - the entries to constrain
        constraint - the constraint for the entries
        Returns:
        a constrained view of the entries
      • constrainedEntries

        private static <K,​V> java.util.Collection<java.util.Map.Entry<K,​V>> constrainedEntries​(java.util.Collection<java.util.Map.Entry<K,​V>> entries,
                                                                                                           MapConstraint<? super K,​? super V> constraint)
        Deprecated.
        Returns a constrained view of the specified collection (or set) of entries, using the specified constraint. The Map.Entry.setValue(V) operation will be verified with the constraint, along with add operations on the returned collection. The add and addAll operations simply forward to the underlying collection, which throws an UnsupportedOperationException per the map and multimap specification.
        Parameters:
        entries - the entries to constrain
        constraint - the constraint for the entries
        Returns:
        a constrained view of the specified entries
      • constrainedEntrySet

        private static <K,​V> java.util.Set<java.util.Map.Entry<K,​V>> constrainedEntrySet​(java.util.Set<java.util.Map.Entry<K,​V>> entries,
                                                                                                     MapConstraint<? super K,​? super V> constraint)
        Deprecated.
        Returns a constrained view of the specified set of entries, using the specified constraint. The Map.Entry.setValue(V) operation will be verified with the constraint, along with add operations on the returned set. The add and addAll operations simply forward to the underlying set, which throws an UnsupportedOperationException per the map and multimap specification.

        The returned multimap is not serializable.

        Parameters:
        entries - the entries to constrain
        constraint - the constraint for the entries
        Returns:
        a constrained view of the specified entries
      • checkValues

        private static <K,​V> java.util.Collection<V> checkValues​(K key,
                                                                       java.lang.Iterable<? extends V> values,
                                                                       MapConstraint<? super K,​? super V> constraint)
        Deprecated.
      • checkMap

        private static <K,​V> java.util.Map<K,​V> checkMap​(java.util.Map<? extends K,​? extends V> map,
                                                                     MapConstraint<? super K,​? super V> constraint)
        Deprecated.