edu.isi.nlp.EquivalenceUtils Maven / Gradle / Ivy
The newest version!
package edu.isi.nlp;
import com.google.common.base.Equivalence;
import com.google.common.base.Equivalence.Wrapper;
import com.google.common.base.Function;
/**
* Utilities for Guava {@link Equivalence}s.
*
* @author Ryan Gabbard
*/
public final class EquivalenceUtils {
private EquivalenceUtils() {
throw new UnsupportedOperationException();
}
public static Function> wrapFunction(
final Equivalence equivalence) {
return new Function>() {
@Override
public Equivalence.Wrapper apply(final T item) {
return equivalence.wrap(item);
}
};
}
public static Function, T> unwrapFunction() {
return new Function, T>() {
@Override
public T apply(final Equivalence.Wrapper x) {
return x.get();
}
};
}
public static Function, String> toStringThroughWrapperFunction() {
return new Function, String>() {
@Override
public String apply(final Wrapper wrapped) {
return wrapped.get().toString();
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy