[collections] Question on the signature of the Transformed Predicate Transformer

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[collections] Question on the signature of the Transformed Predicate Transformer

Steven Geens
I noticed the signature:
public static <T> Predicate<T> transformedPredicate(Transformer<? super T,? extends T> transformer, Predicate<? super T> predicate)

I was actually expecting to see the following:
public static <T,O> Predicate<T> transformedPredicate(Transformer<? super T,? extends O> transformer, Predicate<? super O> predicate)

I do not see why the type of the output of the transformer should be in any way related to T, the type of input for the transformer.
It seems to artificially limit the possible types of the transformer and the given predicate to types related with T.

I've added an example java file with my expected behaviour.
Most important excerpt:
    public Collection<Seat> seatsToAvoid(Collection<Seat> seats, Transformer<Seat, Passenger> seatingArrangement,
            Predicate<Passenger> hasEatenBeans) {
        Predicate<Seat> badSeat1 = PredicateUtils.transformedPredicate(seatingArrangement, hasEatenBeans);
        Predicate<Seat> badSeat2 = expectedTransformedPredicate(seatingArrangement, hasEatenBeans);
        return CollectionUtils.select(seats, badSeat2);
    }

The line with badseat1 does not compile.

Could you clarify why this predicate should have this signature and why my expected behaviour is incorrect?

Steven


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Example.java (1K) Download Attachment