001/* A class that compares two comparable objects.
002
003 Copyright (c) 2006-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026 */
027package ptolemy.actor.util;
028
029import java.util.Comparator;
030
031///////////////////////////////////////////////////////////////////
032//// GeneralComparator
033
034/**
035 This class compares two comparable objects, object_1 and object_2,
036 by calling <i>compare(object_1, object_2)</i>. A comparable object
037 implements the {@link java.lang.Comparable} interface. This method returns
038 -1, 0, or 1 if object_1 is less than, equal to, or bigger than object_2.
039
040 @author Haiyang Zheng
041 @version $Id$
042 @since Ptolemy II 5.2
043 @Pt.ProposedRating Green (hyzheng)
044 @Pt.AcceptedRating Green (hyzheng)
045 */
046public class GeneralComparator implements Comparator {
047    ///////////////////////////////////////////////////////////////////
048    ////                         public methods                    ////
049
050    /** Return -1, 0, or 1 if the first object is less than, equal to, or
051     *  bigger than the second object.
052     *
053     *  <p>If any of the argument is not a object of Comparable class, a
054     *  ClassCastException will be thrown.
055     *  @param first The first comparable object.
056     *  @param second The second comparable object.
057     *  @return The comparison result, -1, 0, or 1.
058     */
059    @Override
060    public int compare(Object first, Object second) {
061        return ((Comparable) first).compareTo(second);
062    }
063}