/*
 * Jakelib2 - General purpose C++ library
 * Copyright (C) 2001 Florian Wolff  (florian@donuz.de)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: Comparator.h,v 1.9 2003/01/25 15:56:00 florian Exp $
 */

#ifndef INCLUDE_JAKELIB2_UTIL_COMPARATOR_H
# define INCLUDE_JAKELIB2_UTIL_COMPARATOR_H

namespace jakelib {
  namespace util {

    /**
     * @class Comparator
     * @version $Id: Comparator.h,v 1.9 2003/01/25 15:56:00 florian Exp $
     * @author Florian 'Overflo' Wolff (florian@donuz.de)
     */
    class Comparator : public jakelib::lang::Interface
      {
      public:

        /**
         * Return an integer that is negative, zero or positive depending on whether
         * the first argument is less than, equal to or greater than the second
         * according to this ordering. This method should obey the following
         * contract:
         *   - if compare(a, b) &lt; 0 then compare(b, a) &gt; 0
         *   - if compare(a, b) throws an exception, so does compare(b, a)
         *   - if compare(a, b) &lt; 0 and compare(b, c) &lt; 0 then compare(a, c)
         *       &lt; 0
         *   - if compare(a, b) == 0 then compare(a, c) and compare(b, c) must
         *       have the same sign
         *
         * To be consistent with equals, the following additional constraint is
         * in place:
         *   - if a.equals(b) or both a and b are null, then
         *       compare(a, b) == 0.
         *
         * Although it is permissible for a comparator to provide an order
         * inconsistent with equals, that should be documented.
         *
         * @param a the first object
         * @param b the second object
         * @return the comparison
         * @throw ClassCastException if the elements are not of types that can be
         *         compared by this ordering.
         */
	virtual int compare(jakelib::lang::Object* a, jakelib::lang::Object* b) = 0;

        JAKELIB_DECLARE_INTERFACE(Comparator);
      };
    
  }
}


#endif

