001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, 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: * NumberTickUnit.java
029: * -------------------
030: * (C) Copyright 2001-2007, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: NumberTickUnit.java,v 1.3.2.4 2007/06/11 13:41:07 mungady Exp $
036: *
037: * Changes (from 19-Dec-2001)
038: * --------------------------
039: * 19-Dec-2001 : Added standard header (DG);
040: * 01-May-2002 : Updated for changed to TickUnit class (DG);
041: * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG);
042: * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
043: * 09-Jan-2002 : Added a new constructor (DG);
044: * 26-Mar-2003 : Implemented Serializable (DG);
045: * 05-Jul-2005 : Added equals() implementation (DG);
046: * 05-Sep-2005 : Implemented hashCode(), thanks to Thomas Morgner (DG);
047: *
048: */
049:
050: package org.jfree.chart.axis;
051:
052: import java.io.Serializable;
053: import java.text.NumberFormat;
054:
055: /**
056: * A numerical tick unit.
057: */
058: public class NumberTickUnit extends TickUnit implements Serializable {
059:
060: /** For serialization. */
061: private static final long serialVersionUID = 3849459506627654442L;
062:
063: /** A formatter for the tick unit. */
064: private NumberFormat formatter;
065:
066: /**
067: * Creates a new number tick unit.
068: *
069: * @param size the size of the tick unit.
070: */
071: public NumberTickUnit(double size) {
072: this (size, NumberFormat.getNumberInstance());
073: }
074:
075: /**
076: * Creates a new number tick unit.
077: *
078: * @param size the size of the tick unit.
079: * @param formatter a number formatter for the tick unit (<code>null</code>
080: * not permitted).
081: */
082: public NumberTickUnit(double size, NumberFormat formatter) {
083: super (size);
084: if (formatter == null) {
085: throw new IllegalArgumentException(
086: "Null 'formatter' argument.");
087: }
088: this .formatter = formatter;
089: }
090:
091: /**
092: * Converts a value to a string.
093: *
094: * @param value the value.
095: *
096: * @return The formatted string.
097: */
098: public String valueToString(double value) {
099: return this .formatter.format(value);
100: }
101:
102: /**
103: * Tests this formatter for equality with an arbitrary object.
104: *
105: * @param obj the object (<code>null</code> permitted).
106: *
107: * @return A boolean.
108: */
109: public boolean equals(Object obj) {
110: if (obj == this ) {
111: return true;
112: }
113: if (!(obj instanceof NumberTickUnit)) {
114: return false;
115: }
116: if (!super .equals(obj)) {
117: return false;
118: }
119: NumberTickUnit that = (NumberTickUnit) obj;
120: if (!this .formatter.equals(that.formatter)) {
121: return false;
122: }
123: return true;
124: }
125:
126: /**
127: * Returns a hash code for this instance.
128: *
129: * @return A hash code.
130: */
131: public int hashCode() {
132: int result = super .hashCode();
133: result = 29
134: * result
135: + (this .formatter != null ? this .formatter.hashCode()
136: : 0);
137: return result;
138: }
139:
140: }
|