Source for org.jfree.data.statistics.HistogramType

   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:  * HistogramType.java
  29:  * ------------------
  30:  * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: HistogramType.java,v 1.4.2.1 2005/10/25 21:34:46 mungady Exp $
  36:  *
  37:  * Changes
  38:  * -------
  39:  * 05-Mar-2004 : Version 1 (DG);
  40:  * 
  41:  */
  42: 
  43: package org.jfree.data.statistics;
  44: 
  45: import java.io.ObjectStreamException;
  46: import java.io.Serializable;
  47:     
  48: /**
  49:  * A class for creating constants to represent the histogram type.  See Bloch's
  50:  * enum tip in 'Effective Java'.
  51:  */
  52: public class HistogramType implements Serializable { 
  53:         
  54:     /** For serialization. */
  55:     private static final long serialVersionUID = 2618927186251997727L;
  56:     
  57:     /** Frequency histogram. */
  58:     public static final HistogramType FREQUENCY 
  59:         = new HistogramType("FREQUENCY");
  60:     
  61:     /** Relative frequency. */
  62:     public static final HistogramType RELATIVE_FREQUENCY 
  63:         = new HistogramType("RELATIVE_FREQUENCY");
  64:     
  65:     /** Scale area to one. */
  66:     public static final HistogramType SCALE_AREA_TO_1 
  67:         = new HistogramType("SCALE_AREA_TO_1");
  68: 
  69:     /** The type name. */
  70:     private String name;
  71:         
  72:     /** 
  73:      * Creates a new type.
  74:      * 
  75:      * @param name  the name.
  76:      */
  77:     private HistogramType(String name) {
  78:         this.name = name;
  79:     } 
  80: 
  81:     /**
  82:      * Returns a string representing the object.
  83:      *
  84:      * @return The string.
  85:      */
  86:     public String toString() {
  87:         return this.name;
  88:     }
  89: 
  90:     /**
  91:      * Tests this type for equality with an arbitrary object.
  92:      *
  93:      * @param obj  the object to test against.
  94:      *
  95:      * @return A boolean.
  96:      */
  97:     public boolean equals(Object obj) {
  98:         
  99:         if (obj == null) {
 100:             return false;   
 101:         }
 102:         
 103:         if (obj == this) {
 104:             return true;
 105:         }
 106:         
 107:         if (!(obj instanceof HistogramType)) {
 108:             return false;
 109:         }
 110:         
 111:         HistogramType t = (HistogramType) obj;
 112:         if (!this.name.equals(t.name)) {
 113:             return false;
 114:         }
 115:         
 116:         return true;
 117:         
 118:     }
 119: 
 120:     /**
 121:      * Returns a hash code value for the object.
 122:      *
 123:      * @return The hashcode
 124:      */
 125:     public int hashCode() {
 126:         return this.name.hashCode();
 127:     }
 128: 
 129:     /**
 130:      * Ensures that serialization returns the unique instances.
 131:      * 
 132:      * @return The object.
 133:      * 
 134:      * @throws ObjectStreamException if there is a problem.
 135:      */
 136:     private Object readResolve() throws ObjectStreamException {
 137:         if (this.equals(HistogramType.FREQUENCY)) {
 138:             return HistogramType.FREQUENCY;
 139:         }
 140:         else if (this.equals(HistogramType.RELATIVE_FREQUENCY)) {
 141:             return HistogramType.RELATIVE_FREQUENCY;
 142:         }
 143:         else if (this.equals(HistogramType.SCALE_AREA_TO_1)) {
 144:             return HistogramType.SCALE_AREA_TO_1;
 145:         }
 146:         return null;
 147:     }
 148: 
 149: }