com.google.common.collect
Class MapConstraints

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

@Beta
@GwtCompatible
public final class MapConstraints
extends Object

Factory and utilities pertaining to the MapConstraint interface.

Since:
3.0
Author:
Mike Bostock
See Also:
Constraints

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.
static MapConstraint<Object,Object> notNull()
          Returns a constraint that verifies that neither the key nor the value is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

notNull

public static MapConstraint<Object,Object> notNull()
Returns a constraint that verifies that neither the key nor the value is null. If either is null, a NullPointerException is thrown.


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 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

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

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

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

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.

The returned bimap is not serializable.

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


Copyright © 2010-2012. All Rights Reserved.