You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Caleb Cushing (Jira)" <ji...@apache.org> on 2024/01/03 21:41:00 UTC
[jira] [Commented] (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:comment-tabpanel&focusedCommentId=17802333#comment-17802333 ]
Caleb Cushing commented on COLLECTIONS-532:
-------------------------------------------
I came here to say this, this is not functional code, imho, I hope that this could be fixed in a version 5. I realize it would change the behavior but it absolutely makes this useless to me.
> 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
> Priority: Major
>
> 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
(v8.20.10#820010)