You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2015/11/27 22:48:12 UTC

[jira] [Closed] (COLLECTIONS-532) MapUtils.predicatedMap(map, keypredicate,valuepredicate) is not working as expected

     [ https://issues.apache.org/jira/browse/COLLECTIONS-532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Neidhart closed COLLECTIONS-532.
---------------------------------------

> 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: New Feature
>          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. {code}
> 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");
>         }
>     }
> {code}
>  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.3.4#6332)