com.bbn.bue.common.OrderingUtils Maven / Gradle / Ivy
The newest version!
package com.bbn.bue.common;
import com.google.common.base.Function;
import com.google.common.collect.Ordering;
public final class OrderingUtils {
private OrderingUtils() {
throw new UnsupportedOperationException();
}
/**
* Gets a function which maps any iterable to its minimum according to the supplied {@link
* com.google.common.collect.Ordering}. If no such minimum exists for an input, it will throw an
* exception as specified in {@link Ordering#min(Iterable)}.
*/
public static Function, T> minFunction(final Ordering ordering) {
return new Function, T>() {
@Override
public T apply(Iterable input) {
return ordering.min(input);
}
};
}
/**
* Gets a function which maps any iterable to its maximum according to the supplied {@link
* com.google.common.collect.Ordering}. If no such maximum exists for an input, it will throw an
* exception as specified in {@link Ordering#max(Iterable)}.
*/
public static Function, T> maxFunction(final Ordering ordering) {
return new Function, T>() {
@Override
public T apply(Iterable input) {
return ordering.max(input);
}
};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy