javaslang.collection.Comparators Maven / Gradle / Ivy
/* / \____ _ _ ____ ______ / \ ____ __ _______
* / / \/ \ / \/ \ / /\__\/ // \/ \ // /\__\ JΛVΛSLΛNG
* _/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \ /__\ \ Copyright 2014-2016 Javaslang, http://javaslang.io
* /___/\_/ \_/\____/\_/ \_/\__\/__/\__\_/ \_// \__/\_____/ Licensed under the Apache License, Version 2.0
*/
package javaslang.collection;
import java.io.Serializable;
import java.util.Comparator;
/**
* INTERNAL API - This class is subject to change.
*/
final class Comparators {
private Comparators() {
}
/**
* Returns the natural comparator for type U, i.e. treating it as {@code Comparable super U>}.
* The returned comparator is also {@code java.io.Serializable}.
*
* Please note that this will lead to runtime exceptions, if U is not Comparable.
*
* @param The type
* @return The natural Comparator of type U
*/
@SuppressWarnings("unchecked")
static SerializableComparator naturalComparator() {
return (o1, o2) -> ((Comparable) o1).compareTo(o2);
}
/**
* Needed for serialization of sortable collections which internally need a comparator.
*
* In general the comparator may be
*
* - a concrete class
* - a lambda
* - a method reference
*
*
* @param the type of objects that may be compared by this comparator
*/
@FunctionalInterface
interface SerializableComparator extends Comparator, Serializable {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy