com.google.common.collect
Class MapConstraints

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

public final class MapConstraints
extends Object

Factory and utilities pertaining to the MapConstraint interface.

MapConstraint, Map and Multimap instances returned by this class are serializable.

Author:
Mike Bostock
See Also:
Constraints

Field Summary
static MapConstraint<Object,Object> NOT_NULL
          A constraint that verifies that neither the key nor the value is null.
 
Method Summary
static
<K,V> BiMap<K,V>
constrainedBiMap(BiMap<K,V> map, MapConstraint<? super K,? super V> constraint)
          Returns a constrained view of the specified bimap, using the specified constraint.
static
<K,V> ListMultimap<K,V>
constrainedListMultimap(ListMultimap<K,V> multimap, MapConstraint<? super K,? super V> constraint)
          Returns a constrained view of the specified list multimap, using the specified constraint.
static
<K,V> Map<K,V>
constrainedMap(Map<K,V> map, MapConstraint<? super K,? super V> constraint)
          Returns a constrained view of the specified map, using the specified constraint.
static
<K,V> Multimap<K,V>
constrainedMultimap(Multimap<K,V> multimap, MapConstraint<? super K,? super V> constraint)
          Returns a constrained view of the specified multimap, using the specified constraint.
static
<K,V> SetMultimap<K,V>
constrainedSetMultimap(SetMultimap<K,V> multimap, MapConstraint<? super K,? super V> constraint)
          Returns a constrained view of the specified set multimap, using the specified constraint.
static
<K,V> SortedSetMultimap<K,V>
constrainedSortedSetMultimap(SortedSetMultimap<K,V> multimap, MapConstraint<? super K,? super V> constraint)
          Returns a constrained view of the specified sorted-set multimap, 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 MapConstraint<Object,Object> NOT_NULL
A constraint that verifies that neither the key nor the value is null. If either is null, a NullPointerException is thrown.

Method Detail

constrainedMap

public static <K,V> Map<K,V> constrainedMap(Map<K,V> map,
                                            MapConstraint<? super K,? super V> constraint)
Returns a constrained view of the specified map, using the specified constraint. Any operations that modify the map will have the associated keys and values verified with the constraint.

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

constrainedMultimap

public static <K,V> Multimap<K,V> constrainedMultimap(Multimap<K,V> multimap,
                                                      MapConstraint<? super K,? super V> constraint)
Returns a constrained view of the specified multimap, using the specified constraint. Any operations that modify the multimap will have the associated keys and values verified with the constraint.

Parameters:
multimap - the multimap for which to return a constrained view
constraint - the constraint for entries in the multimap
Returns:
a constrained view of the multimap

constrainedListMultimap

public static <K,V> ListMultimap<K,V> constrainedListMultimap(ListMultimap<K,V> multimap,
                                                              MapConstraint<? super K,? super V> constraint)
Returns a constrained view of the specified list multimap, using the specified constraint. Any operations that modify the multimap will have the associated keys and values verified with the constraint.

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

constrainedSetMultimap

public static <K,V> SetMultimap<K,V> constrainedSetMultimap(SetMultimap<K,V> multimap,
                                                            MapConstraint<? super K,? super V> constraint)
Returns a constrained view of the specified set multimap, using the specified constraint. Any operations that modify the multimap will have the associated keys and values verified with the constraint.

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

constrainedSortedSetMultimap

public static <K,V> SortedSetMultimap<K,V> constrainedSortedSetMultimap(SortedSetMultimap<K,V> multimap,
                                                                        MapConstraint<? super K,? super V> constraint)
Returns a constrained view of the specified sorted-set multimap, using the specified constraint. Any operations that modify the multimap will have the associated keys and values verified with the constraint.

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

constrainedBiMap

public static <K,V> BiMap<K,V> constrainedBiMap(BiMap<K,V> map,
                                                MapConstraint<? super K,? super V> constraint)
Returns a constrained view of the specified bimap, using the specified constraint. Any operations that modify the bimap will have the associated keys and values verified with the constraint.

Parameters:
map - the bimap for which to return a constrained view
constraint - the constraint for entries in the bimap
Returns:
a constrained view of the specified map