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

net.jqwik.vavr.NaturalComparator Maven / Gradle / Ivy

package net.jqwik.vavr;

import java.io.Serializable;
import java.util.Comparator;

/**
 * see {@code io.vavr.collection.NaturalComparator}
 *
 * @author Benno Müller
 */
public class NaturalComparator implements Comparator, Serializable {

    private static final long serialVersionUID = 1L;

    private static final NaturalComparator INSTANCE = new NaturalComparator<>();

    private NaturalComparator() {
    }

    @SuppressWarnings("unchecked")
    public static  NaturalComparator instance() {
        return (NaturalComparator) INSTANCE;
    }

    @SuppressWarnings("unchecked")
    @Override
    public int compare(final T o1, final T o2) {
        return ((Comparable) o1).compareTo(o2);
    }

    /**
     * @see Comparator#equals(Object)
     */
    @Override
    public boolean equals(final Object obj) {
        return obj instanceof NaturalComparator;
    }

    @Override
    public int hashCode() {
        return 1;
    }

    /**
     * Instance control for object serialization.
     *
     * @return The singleton instance of NaturalComparator.
     * @see java.io.Serializable
     */
    private Object readResolve() {
        return INSTANCE;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy