Frames | No Frames |
1: /* ======================================================================== 2: * JCommon : a free general purpose class library for the Java(tm) platform 3: * ======================================================================== 4: * 5: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jcommon/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ------------- 28: * Rotation.java 29: * ------------- 30: * (C)opyright 2003-2005, by Object Refinery Limited and Contributors. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: Rotation.java,v 1.5 2005/11/16 15:58:41 taqua Exp $ 36: * 37: * Changes 38: * ------- 39: * 19-Aug-2003 : Version 1 (DG); 40: * 20-Feb-2004 : Updated Javadocs (DG); 41: * 42: */ 43: 44: package org.jfree.util; 45: 46: import java.io.ObjectStreamException; 47: import java.io.Serializable; 48: 49: /** 50: * Represents a direction of rotation (<code>CLOCKWISE</code> or 51: * <code>ANTICLOCKWISE</code>). 52: * @author David Gilbert 53: */ 54: public final class Rotation implements Serializable { 55: 56: /** For serialization. */ 57: private static final long serialVersionUID = -4662815260201591676L; 58: 59: /** Clockwise. */ 60: public static final Rotation CLOCKWISE 61: = new Rotation("Rotation.CLOCKWISE", -1.0); 62: 63: /** The reverse order renders the primary dataset first. */ 64: public static final Rotation ANTICLOCKWISE 65: = new Rotation("Rotation.ANTICLOCKWISE", 1.0); 66: 67: /** The name. */ 68: private String name; 69: 70: /** 71: * The factor (-1.0 for <code>CLOCKWISE</code> and 1.0 for 72: * <code>ANTICLOCKWISE</code>). 73: */ 74: private double factor; 75: 76: /** 77: * Private constructor. 78: * 79: * @param name the name. 80: * @param factor the rotation factor. 81: */ 82: private Rotation(final String name, final double factor) { 83: this.name = name; 84: this.factor = factor; 85: } 86: 87: /** 88: * Returns a string representing the object. 89: * 90: * @return the string (never <code>null</code>). 91: */ 92: public String toString() { 93: return this.name; 94: } 95: 96: /** 97: * Returns the rotation factor, which is -1.0 for <code>CLOCKWISE</code> 98: * and 1.0 for <code>ANTICLOCKWISE</code>. 99: * 100: * @return the rotation factor. 101: */ 102: public double getFactor() { 103: return this.factor; 104: } 105: 106: /** 107: * Compares this object for equality with an other object. 108: * Implementation note: This simply compares the factor instead 109: * of the name. 110: * 111: * @param o the other object 112: * @return true or false 113: */ 114: public boolean equals(final Object o) { 115: if (this == o) { 116: return true; 117: } 118: if (!(o instanceof Rotation)) { 119: return false; 120: } 121: 122: final Rotation rotation = (Rotation) o; 123: 124: if (this.factor != rotation.factor) { 125: return false; 126: } 127: 128: return true; 129: } 130: 131: /** 132: * Returns a hash code value for the object. 133: * 134: * @return the hashcode 135: */ 136: public int hashCode() { 137: final long temp = Double.doubleToLongBits(this.factor); 138: return (int) (temp ^ (temp >>> 32)); 139: } 140: 141: /** 142: * Ensures that serialization returns the unique instances. 143: * 144: * @return the object. 145: * 146: * @throws ObjectStreamException if there is a problem. 147: */ 148: private Object readResolve() throws ObjectStreamException { 149: if (this.equals(Rotation.CLOCKWISE)) { 150: return Rotation.CLOCKWISE; 151: } 152: else if (this.equals(Rotation.ANTICLOCKWISE)) { 153: return Rotation.ANTICLOCKWISE; 154: } 155: return null; 156: } 157: 158: }