001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2020, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ------------------ 028 * HistogramType.java 029 * ------------------ 030 * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 05-Mar-2004 : Version 1 (DG); 038 * 039 */ 040 041package org.jfree.data.statistics; 042 043import java.io.ObjectStreamException; 044import java.io.Serializable; 045 046/** 047 * A class for creating constants to represent the histogram type. See Bloch's 048 * enum tip in 'Effective Java'. 049 */ 050public class HistogramType implements Serializable { 051 052 /** For serialization. */ 053 private static final long serialVersionUID = 2618927186251997727L; 054 055 /** Frequency histogram. */ 056 public static final HistogramType FREQUENCY 057 = new HistogramType("FREQUENCY"); 058 059 /** Relative frequency. */ 060 public static final HistogramType RELATIVE_FREQUENCY 061 = new HistogramType("RELATIVE_FREQUENCY"); 062 063 /** Scale area to one. */ 064 public static final HistogramType SCALE_AREA_TO_1 065 = new HistogramType("SCALE_AREA_TO_1"); 066 067 /** The type name. */ 068 private String name; 069 070 /** 071 * Creates a new type. 072 * 073 * @param name the name. 074 */ 075 private HistogramType(String name) { 076 this.name = name; 077 } 078 079 /** 080 * Returns a string representing the object. 081 * 082 * @return The string. 083 */ 084 @Override 085 public String toString() { 086 return this.name; 087 } 088 089 /** 090 * Tests this type for equality with an arbitrary object. 091 * 092 * @param obj the object to test against. 093 * 094 * @return A boolean. 095 */ 096 @Override 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 @Override 126 public int hashCode() { 127 return this.name.hashCode(); 128 } 129 130 /** 131 * Ensures that serialization returns the unique instances. 132 * 133 * @return The object. 134 * 135 * @throws ObjectStreamException if there is a problem. 136 */ 137 private Object readResolve() throws ObjectStreamException { 138 if (this.equals(HistogramType.FREQUENCY)) { 139 return HistogramType.FREQUENCY; 140 } 141 else if (this.equals(HistogramType.RELATIVE_FREQUENCY)) { 142 return HistogramType.RELATIVE_FREQUENCY; 143 } 144 else if (this.equals(HistogramType.SCALE_AREA_TO_1)) { 145 return HistogramType.SCALE_AREA_TO_1; 146 } 147 return null; 148 } 149 150} 151