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