001    /* ======================================================
002     * Orson : a free chart beans library based on JFreeChart
003     * ======================================================
004     *
005     * (C) Copyright 2007, by Object Refinery Limited.
006     *
007     * Project Info:  not-yet-released
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    
029    package org.jfree.beans;
030    
031    import java.io.ObjectStreamException;
032    import java.io.Serializable;
033    
034    /**
035     * A token representing the axis scale type.
036     */
037    public final class AxisScale implements Serializable {
038        
039        /** Integer. */
040        public static final AxisScale INTEGER = new AxisScale("AxisScale.INTEGER");
041    
042        /** Floating point. */
043        public static final AxisScale FLOAT = new AxisScale("AxisScale.FLOAT");
044    
045        /** The name. */
046        private String name;
047    
048        /**
049         * Private constructor.
050         *
051         * @param name  the name.
052         */
053        private AxisScale(String name) {
054            this.name = name;
055        }
056    
057        /**
058         * Returns a string representing the object.
059         *
060         * @return the string (never <code>null</code>).
061         */
062        public String toString() {
063            return this.name;
064        }
065    
066    
067        /**
068         * Compares this object for equality with an other object.
069         * Implementation note: This simply compares the factor instead
070         * of the name.
071         *
072         * @param obj  the other object
073         * 
074         * @return true or false
075         */
076        public boolean equals(Object obj) {
077            if (this == obj) {
078                return true;
079            }
080            if (!(obj instanceof AxisScale)) {
081                return false;
082            }
083            AxisScale that = (AxisScale) obj;
084            return this.name.equals(that.name);
085        }
086    
087        /**
088         * Returns a hash code value for the object.
089         *
090         * @return the hashcode
091         */
092        public int hashCode() {
093            return this.name.hashCode();
094        }
095    
096        /**
097         * Ensures that serialization returns the unique instances.
098         * 
099         * @return the object.
100         * 
101         * @throws ObjectStreamException if there is a problem.
102         */
103        private Object readResolve() throws ObjectStreamException {
104            if (this.equals(AxisScale.INTEGER)) {
105                return AxisScale.INTEGER;
106            }
107            else if (this.equals(AxisScale.FLOAT)) {
108                return AxisScale.FLOAT;
109            }           
110            return null;
111        }
112    
113    }