commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brent Worden (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (COLLECTIONS-532) MapUtils.predicatedMap(map, keypredicate,valuepredicate) is not working as expected
Date Sat, 21 Jun 2014 14:35:24 GMT

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

Brent Worden updated COLLECTIONS-532:
-------------------------------------

    Description: 
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)

  was:
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)


> 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.2#6252)

Mime
View raw message