[
https://issues.apache.org/jira/browse/COLLECTIONS-503?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13830944#comment-13830944
]
Thomas Neidhart commented on COLLECTIONS-503:
---------------------------------------------
Hi Josh,
thanks for your contribution, looks good except for missing unit tests.
On a second thought, there is already a SwitchTransformer which is a more
generalized version of an IfTransformer. What do you think of just updating the
SwitchTransformer to more easily create on for the your use-case: if else?
This would require only one additional factory method:
{noformat}
public static <I, O> Transformer<I, O> switchTransformer(final Predicate<?
super I> predicate,
final Transformer<? super I, ? extends O> trueTransformers,
final Transformer<? super I, ? extends O> falseTransformer) {
....
}
{noformat}
> IfTransformer
> -------------
>
> Key: COLLECTIONS-503
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-503
> Project: Commons Collections
> Issue Type: New Feature
> Components: Functor
> Reporter: Josh Cain
> Priority: Trivial
> Fix For: 4.0.1
>
> Attachments: ifTransformer.patch
>
>
> Just thought a basic ifTransformer that performs operations based on a
> predicate would be useful. I know this functionality can be accomplished via
> a switchTransformer, but sometimes it would just be easier and more clear to
> have an ifTransformer.
> I attached a draft of what it could look like. Let me know if this is
> something that should be included and I can polish it and write some tests.
--
This message was sent by Atlassian JIRA
(v6.1#6144)