Menu

#29 ComparatorUtils.transformedComparator incorrect generics

open
nobody
None
5
2010-05-13
2010-05-13
No

In ComparatorUtils,
public static <I,O> Comparator<O> transformedComparator(Comparator<I> comparator, Transformer<I, O> transformer)
is incorrect.

JavaDoc states:
Gets a Comparator that passes transformed objects to the given comparator.
Objects passed to the returned comparator will first be transformed by the given transformer before they are compared by the given comparator.

i.e. I already have a Comparator<A>. I also have a Transformer<B,A>. This util method should return me a Comparator<B> which uses my Transformer to convert Bs to As before delegating to my Comparator<A>.

This should give us the signature
<A,B> Comparator<B> transformedComparator(Comparator<A> comparator, Transformer<B, A> transformer)
whereas we currently have
<A,B> Comparator<B> transformedComparator(Comparator<A> comparator, Transformer<A, B> transformer)
which is clearly wrong. The type placeholders I and O are ambiguous in this case - there's no clear 'input' or 'output'.

Unfortunately there are no unit tests for this method which is presumably why this bug slipped through.

Is anyone maintaining this project? I'd happily supply a patch and amend the test cases if I thought it would get incorporated.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB