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

com.oracle.coherence.common.base.InverseComparator Maven / Gradle / Ivy

There is a newer version: 24.03
Show newest version
/*
 * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */
package com.oracle.coherence.common.base;

import java.util.Comparator;


/**
 * InverseComparator is a wrapper comparator which simply inverses the comparison result.
 *
 * @author mf  2014.08.28
 */
public class InverseComparator
    implements Comparator
    {
    /**
     * Construct an InverseComparator which inverts the specified comparator.
     *
     * @param comparator the comparator to invert
     */
    public InverseComparator(Comparator comparator)
        {
        f_comparator = comparator;
        }

    @Override
    public int compare(T o1, T o2)
        {
        return -f_comparator.compare(o1, o2);
        }


    // ----- data members ---------------------------------------------------

    /**
     * The comparator to invert.
     */
    protected final Comparator f_comparator;


    // ----- constants ------------------------------------------------------

    /**
     * InverseComparator singleton which inverts a Comparable objects natural comparison order.
     */
    public static final InverseComparator INSTANCE = new InverseComparator(NaturalComparator.INSTANCE);
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy