Bhanupavansingh created COLLECTIONS-532:
-------------------------------------------

             Summary: MapUtils.predicatedMap(map, keypredicate,valuepredicate) 
is not working as expected
                 Key: COLLECTIONS-532
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-532
             Project: Commons Collections
          Issue Type: Bug
          Components: Collection, Map
    Affects Versions: 4.0
         Environment: ubuntu/java8
            Reporter: Bhanupavansingh


I expected that MapUtils.predicatedMap() includes those entries of the 
specified map that match the specified key-predicate and specified 
value-predicate.I expected that entries that do not match either of the 
predicates not included i the returned map. 
But in as per the code of org.apache.commons.collections4.map. 
PredicatedMap.validate()
 protected void validate(final K key, final V value) {
        if (keyPredicate != null && keyPredicate.evaluate(key) == false) {
            throw new IllegalArgumentException("Cannot add key - Predicate 
rejected it");
        }
        if (valuePredicate != null && valuePredicate.evaluate(value) == false) {
            throw new IllegalArgumentException("Cannot add value - Predicate 
rejected it");
        }
    }
 if evaluation of key or value predicate fails an IllegalArgumentException is 
thrown.

Predicates are passed to input map to test if an entry is to be included or 
not. If the evaluation of this predicate itself throws an exception based on 
result of predicate, then this method is useless and cannot be used to filter 
entries of a map(using predicates)



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to