    001/* ===========================================================
    002 * JFreeChart : a free chart library for the Java(tm) platform
    003 * ===========================================================
    004 *
    005 * (C) Copyright 2000-2011, 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    public String toString() {
    085        return this.name;
    086    }
    087
    088    /**
    089     * Tests this type for equality with an arbitrary object.
    090     *
    091     * @param obj  the object to test against.
    092     *
    093     * @return A boolean.
    094     */
    095    public boolean equals(Object obj) {
    096
    097        if (obj == null) {
    098            return false;
    099        }
    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