|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface MapConstraint<K,V>
Interface for defining a constraint on the types of keys and values that are
allowed to be added to a Map or Multimap. For example, to
enforce that a map contains no null keys or values, you might say:
public void checkKeyValue(Object key, Object value) {
if (key == null) {
throw new NullPointerException();
}
if (value == null) {
throw new NullPointerException();
}
}
Then use MapConstraints.constrainedMap(java.util.Map, com.google.common.collect.MapConstraint super K, ? super V>) to enforce the constraint.
This example is contrived; to check for null use MapConstraints.NOT_NULL.
See Constraint for an important comment regarding determinism,
thread-safety and mutability when implementing constraints.
MapConstraints,
Constraint| Method Summary | |
|---|---|
void |
checkKeyValue(K key,
V value)
Implement this method to throw a suitable RuntimeException if the
specified key or value is illegal. |
| Method Detail |
|---|
void checkKeyValue(@Nullable
K key,
@Nullable
V value)
RuntimeException if the
specified key or value is illegal. Typically this is either a NullPointerException, an IllegalArgumentException, or a ClassCastException, though a more application-specific exception class may
be used as appropriate.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||