com.softicar.platform.common.container.comparator.ReverseComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.comparator;
import java.util.Comparator;
/**
* Reverses the order direction of a given comparator.
*
* @param
* the type of the compared values
* @author Oliver Richers
*/
public class ReverseComparator implements Comparator {
private final Comparator originalComparator;
/**
* Creates a reverse comparator based on {@link Comparable}.
*
* @return new reverse comparator
*/
public static > ReverseComparator create() {
return new ReverseComparator<>(T::compareTo);
}
public ReverseComparator(Comparator originalComparator) {
this.originalComparator = originalComparator;
}
@Override
public int compare(T a, T b) {
return originalComparator.compare(b, a);
}
}