/** * Returns a predicated (validating) map backed by the given map. * <p> * Only objects that pass the tests in the given predicates can be added to the map. * Trying to add an invalid object results in an IllegalArgumentException. * Keys must pass the key predicate, values must pass the value predicate. * It is important not to use the original map after invoking this method, * as it is a backdoor for adding invalid objects. * * @param map the map to predicate, must not be null * @param keyPred the predicate for keys, null means no check * @param valuePred the predicate for values, null means no check * @return a predicated map backed by the given map * @throws IllegalArgumentException if the Map is null */ public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) { return PredicatedMap.decorate(map, keyPred, valuePred); }
/** * Factory method to create a predicated (validating) map. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param map the map to decorate, must not be null * @param keyPredicate the predicate to validate the keys, null means no check * @param valuePredicate the predicate to validate to values, null means no check * @throws IllegalArgumentException if the map is null */ public static Map decorate(Map map, Predicate keyPredicate, Predicate valuePredicate) { return new PredicatedMap(map, keyPredicate, valuePredicate); }
public Object put(Object key, Object value) { validate(key, value); return map.put(key, value); }
/** * Returns a predicated (validating) map backed by the given map. * <p> * Only objects that pass the tests in the given predicates can be added to the map. * Trying to add an invalid object results in an IllegalArgumentException. * Keys must pass the key predicate, values must pass the value predicate. * It is important not to use the original map after invoking this method, * as it is a backdoor for adding invalid objects. * * @param map the map to predicate, must not be null * @param keyPred the predicate for keys, null means no check * @param valuePred the predicate for values, null means no check * @return a predicated map backed by the given map * @throws IllegalArgumentException if the Map is null */ public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) { return PredicatedMap.decorate(map, keyPred, valuePred); }
public Object put(Object key, Object value) { validate(key, value); return map.put(key, value); }
/** * Factory method to create a predicated (validating) map. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param map the map to decorate, must not be null * @param keyPredicate the predicate to validate the keys, null means no check * @param valuePredicate the predicate to validate to values, null means no check * @throws IllegalArgumentException if the map is null */ public static Map decorate(Map map, Predicate keyPredicate, Predicate valuePredicate) { return new PredicatedMap(map, keyPredicate, valuePredicate); }
protected Map decorateMap(Map map, Predicate keyPredicate, Predicate valuePredicate) { return PredicatedMap.decorate(map, keyPredicate, valuePredicate); }
public void putAll(Map mapToCopy) { Iterator it = mapToCopy.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); validate(key, value); } map.putAll(mapToCopy); }
/** * Factory method to create a typed map. * <p> * If there are any elements already in the map being decorated, they * are validated. * * @param map the map to decorate, must not be null * @param keyType the type to allow as keys, must not be null * @param valueType the type to allow as values, must not be null * @throws IllegalArgumentException if list or type is null * @throws IllegalArgumentException if the list contains invalid elements */ public static Map decorate(Map map, Class keyType, Class valueType) { return new PredicatedMap( map, InstanceofPredicate.getInstance(keyType), InstanceofPredicate.getInstance(valueType) ); }
/** * Returns a predicated (validating) map backed by the given map. * <p> * Only objects that pass the tests in the given predicates can be added to the map. * Trying to add an invalid object results in an IllegalArgumentException. * Keys must pass the key predicate, values must pass the value predicate. * It is important not to use the original map after invoking this method, * as it is a backdoor for adding invalid objects. * * @param map the map to predicate, must not be null * @param keyPred the predicate for keys, null means no check * @param valuePred the predicate for values, null means no check * @return a predicated map backed by the given map * @throws IllegalArgumentException if the Map is null */ public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) { return PredicatedMap.decorate(map, keyPred, valuePred); }
public void putAll(Map mapToCopy) { Iterator it = mapToCopy.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); validate(key, value); } map.putAll(mapToCopy); }
/** * Factory method to create a typed map. * <p> * If there are any elements already in the map being decorated, they * are validated. * * @param map the map to decorate, must not be null * @param keyType the type to allow as keys, must not be null * @param valueType the type to allow as values, must not be null * @throws IllegalArgumentException if list or type is null * @throws IllegalArgumentException if the list contains invalid elements */ public static Map decorate(Map map, Class keyType, Class valueType) { return new PredicatedMap( map, InstanceofPredicate.getInstance(keyType), InstanceofPredicate.getInstance(valueType) ); }
/** * Returns a predicated (validating) map backed by the given map. * <p> * Only objects that pass the tests in the given predicates can be added to the map. * Trying to add an invalid object results in an IllegalArgumentException. * Keys must pass the key predicate, values must pass the value predicate. * It is important not to use the original map after invoking this method, * as it is a backdoor for adding invalid objects. * * @param map the map to predicate, must not be null * @param keyPred the predicate for keys, null means no check * @param valuePred the predicate for values, null means no check * @return a predicated map backed by the given map * @throws IllegalArgumentException if the Map is null */ public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) { return PredicatedMap.decorate(map, keyPred, valuePred); }
/** * Constructor that wraps (not copies). * * @param map the map to decorate, must not be null * @param keyPredicate the predicate to validate the keys, null means no check * @param valuePredicate the predicate to validate to values, null means no check * @throws IllegalArgumentException if the map is null */ protected PredicatedMap(Map map, Predicate keyPredicate, Predicate valuePredicate) { super(map); this.keyPredicate = keyPredicate; this.valuePredicate = valuePredicate; Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); validate(key, value); } }
/** * Factory method to create a predicated (validating) map. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param map the map to decorate, must not be null * @param keyPredicate the predicate to validate the keys, null means no check * @param valuePredicate the predicate to validate to values, null means no check * @throws IllegalArgumentException if the map is null */ public static Map decorate(Map map, Predicate keyPredicate, Predicate valuePredicate) { return new PredicatedMap(map, keyPredicate, valuePredicate); }
/** * Returns a predicated (validating) map backed by the given map. * <p> * Only objects that pass the tests in the given predicates can be added to the map. * Trying to add an invalid object results in an IllegalArgumentException. * Keys must pass the key predicate, values must pass the value predicate. * It is important not to use the original map after invoking this method, * as it is a backdoor for adding invalid objects. * * @param map the map to predicate, must not be null * @param keyPred the predicate for keys, null means no check * @param valuePred the predicate for values, null means no check * @return a predicated map backed by the given map * @throws IllegalArgumentException if the Map is null */ public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) { return PredicatedMap.decorate(map, keyPred, valuePred); }
/** * Constructor that wraps (not copies). * * @param map the map to decorate, must not be null * @param keyPredicate the predicate to validate the keys, null means no check * @param valuePredicate the predicate to validate to values, null means no check * @throws IllegalArgumentException if the map is null */ protected PredicatedMap(Map map, Predicate keyPredicate, Predicate valuePredicate) { super(map); this.keyPredicate = keyPredicate; this.valuePredicate = valuePredicate; Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); validate(key, value); } }
/** * Factory method to create a predicated (validating) map. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param map the map to decorate, must not be null * @param keyPredicate the predicate to validate the keys, null means no check * @param valuePredicate the predicate to validate to values, null means no check * @throws IllegalArgumentException if the map is null */ public static Map decorate(Map map, Predicate keyPredicate, Predicate valuePredicate) { return new PredicatedMap(map, keyPredicate, valuePredicate); }
/** * Returns a predicated (validating) map backed by the given map. * <p> * Only objects that pass the tests in the given predicates can be added to the map. * Trying to add an invalid object results in an IllegalArgumentException. * Keys must pass the key predicate, values must pass the value predicate. * It is important not to use the original map after invoking this method, * as it is a backdoor for adding invalid objects. * * @param map the map to predicate, must not be null * @param keyPred the predicate for keys, null means no check * @param valuePred the predicate for values, null means no check * @return a predicated map backed by the given map * @throws IllegalArgumentException if the Map is null */ public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) { return PredicatedMap.decorate(map, keyPred, valuePred); }
public Object put(Object key, Object value) { validate(key, value); return map.put(key, value); }