001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 025 * in the United States and other countries.] 026 * 027 * ------------------ 028 * HistogramType.java 029 * ------------------ 030 * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * $Id: HistogramType.java,v 1.4.2.1 2005/10/25 21:34:46 mungady Exp $ 036 * 037 * Changes 038 * ------- 039 * 05-Mar-2004 : Version 1 (DG); 040 * 041 */ 042 043 package org.jfree.data.statistics; 044 045 import java.io.ObjectStreamException; 046 import java.io.Serializable; 047 048 /** 049 * A class for creating constants to represent the histogram type. See Bloch's 050 * enum tip in 'Effective Java'. 051 */ 052 public class HistogramType implements Serializable { 053 054 /** For serialization. */ 055 private static final long serialVersionUID = 2618927186251997727L; 056 057 /** Frequency histogram. */ 058 public static final HistogramType FREQUENCY 059 = new HistogramType("FREQUENCY"); 060 061 /** Relative frequency. */ 062 public static final HistogramType RELATIVE_FREQUENCY 063 = new HistogramType("RELATIVE_FREQUENCY"); 064 065 /** Scale area to one. */ 066 public static final HistogramType SCALE_AREA_TO_1 067 = new HistogramType("SCALE_AREA_TO_1"); 068 069 /** The type name. */ 070 private String name; 071 072 /** 073 * Creates a new type. 074 * 075 * @param name the name. 076 */ 077 private HistogramType(String name) { 078 this.name = name; 079 } 080 081 /** 082 * Returns a string representing the object. 083 * 084 * @return The string. 085 */ 086 public String toString() { 087 return this.name; 088 } 089 090 /** 091 * Tests this type for equality with an arbitrary object. 092 * 093 * @param obj the object to test against. 094 * 095 * @return A boolean. 096 */ 097 public boolean equals(Object obj) { 098 099 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 } 150