Source for org.jfree.data.KeyedValueComparatorType

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
   6:  *
   7:  * Project Info:  http://www.jfree.org/jfreechart/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it 
  10:  * under the terms of the GNU Lesser General Public License as published by 
  11:  * the Free Software Foundation; either version 2.1 of the License, or 
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but 
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  *
  27:  * -----------------------------
  28:  * KeyedValueComparatorType.java
  29:  * -----------------------------
  30:  * (C) Copyright 2003-2005, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: KeyedValueComparatorType.java,v 1.3.2.1 2005/10/25 21:29:13 mungady Exp $
  36:  *
  37:  * Changes:
  38:  * --------
  39:  * 05-Mar-2003 : Version 1 (DG);
  40:  *
  41:  */
  42: 
  43: package org.jfree.data;
  44: 
  45: 
  46: /**
  47:  * Used to indicate the type of a {@link KeyedValueComparator} : 'by key' or 
  48:  * 'by value'.
  49:  */
  50: public final class KeyedValueComparatorType {
  51: 
  52:     /** An object representing 'by key' sorting. */
  53:     public static final KeyedValueComparatorType BY_KEY
  54:         = new KeyedValueComparatorType("KeyedValueComparatorType.BY_KEY");
  55: 
  56:     /** An object representing 'by value' sorting. */
  57:     public static final KeyedValueComparatorType BY_VALUE
  58:         = new KeyedValueComparatorType("KeyedValueComparatorType.BY_VALUE");
  59: 
  60:     /** The name. */
  61:     private String name;
  62: 
  63:     /**
  64:      * Private constructor.
  65:      *
  66:      * @param name  the name.
  67:      */
  68:     private KeyedValueComparatorType(String name) {
  69:         this.name = name;
  70:     }
  71: 
  72:     /**
  73:      * Returns a string representing the object.
  74:      *
  75:      * @return The string.
  76:      */
  77:     public String toString() {
  78:         return this.name;
  79:     }
  80: 
  81:     /**
  82:      * Returns <code>true</code> if this object is equal to the specified 
  83:      * object, and <code>false</code> otherwise.
  84:      *
  85:      * @param o  the other object.
  86:      *
  87:      * @return A boolean.
  88:      */
  89:     public boolean equals(Object o) {
  90:         if (this == o) {
  91:             return true;
  92:         }
  93:         if (!(o instanceof KeyedValueComparatorType)) {
  94:             return false;
  95:         }
  96: 
  97:         KeyedValueComparatorType type = (KeyedValueComparatorType) o;
  98:         if (!this.name.equals(type.name)) {
  99:             return false;
 100:         }
 101: 
 102:         return true;
 103:     }
 104: 
 105:     /**
 106:      * Returns a hash code.
 107:      * 
 108:      * @return A hash code.
 109:      */
 110:     public int hashCode() {
 111:         return this.name.hashCode();
 112:     }
 113: }