All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.container.comparator.ReverseComparator Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy