I am asked to implement a java library module containing 1 method that is able to filter collections of arbitrary objects using a user-defined filter method and returns the object's identity hash code (unique hash code for the object generated by the JVM), preferably using Java 8 constructs. If multiple objects are found, the largest one should be returned. If the comparator does not sort them uniquely, the largest hash code should be returned. The method should follow the signature you can find below.
public <T> Optional<Integer> getIt(Collection<T> collection, Predicate<T> filter, Comparator<T> comparator)
So, I thought to filter first, using:
collection.removeIf(filter.negate());
But, what I couldn't get is, how you could get the largest arbitrary object?
Any help is appreciated, thanks