org.apache.commons.collections.map
Class PredicatedMap

java.lang.Object
  |
  +--org.apache.commons.collections.map.AbstractMapDecorator
        |
        +--org.apache.commons.collections.map.AbstractInputCheckedMapDecorator
              |
              +--org.apache.commons.collections.map.PredicatedMap
All Implemented Interfaces:
java.util.Map, java.io.Serializable
Direct Known Subclasses:
PredicatedSortedMap

public class PredicatedMap
extends org.apache.commons.collections.map.AbstractInputCheckedMapDecorator
implements java.io.Serializable

Decorates another Map to validate that additions match a specified predicate.

This map exists to provide validation for the decorated map. It is normally created to decorate an empty map. If an object cannot be added to the map, an IllegalArgumentException is thrown.

One usage would be to ensure that no null keys are added to the map.

Map map = PredicatedSet.decorate(new HashMap(), NotNullPredicate.INSTANCE, null);

This class is Serializable from Commons Collections 3.1.

Since:
Commons Collections 3.0
Version:
$Revision: 1.14 $ $Date: 2004/06/07 22:14:42 $
Author:
Stephen Colebourne, Paul Jack
See Also:
Serialized Form

Method Summary
static java.util.Map decorate(java.util.Map map, Predicate keyPredicate, Predicate valuePredicate)
          Factory method to create a predicated (validating) map.
 java.util.Set entrySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map mapToCopy)
           
 
Methods inherited from class org.apache.commons.collections.map.AbstractMapDecorator
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, remove, size, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

decorate

public static java.util.Map decorate(java.util.Map map,
                                     Predicate keyPredicate,
                                     Predicate valuePredicate)
Factory method to create a predicated (validating) map.

If there are any elements already in the list being decorated, they are validated.

Parameters:
map - the map to decorate, must not be null
keyPredicate - the predicate to validate the keys, null means no check
valuePredicate - the predicate to validate to values, null means no check
Throws:
java.lang.IllegalArgumentException - if the map is null

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
Overrides:
put in class AbstractMapDecorator

putAll

public void putAll(java.util.Map mapToCopy)
Specified by:
putAll in interface java.util.Map
Overrides:
putAll in class AbstractMapDecorator

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map
Overrides:
entrySet in class AbstractMapDecorator


Copyright © 2001-2004 The Apache Software Foundation. All Rights Reserved.