/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
 * Other names may be trademarks of their respective owners.]
 *
 */

package org.jfree.chart.util;

import java.io.ObjectStreamException;
import java.io.Serializable;

/**
 * Represents a direction of rotation ({@code CLOCKWISE} or 
 * {@code ANTICLOCKWISE}).
 */
public final class Rotation implements Serializable {

    /** For serialization. */
    private static final long serialVersionUID = -4662815260201591676L;
    
    /** Clockwise. */
    public static final Rotation CLOCKWISE 
        = new Rotation("Rotation.CLOCKWISE", -1.0);

    /** The reverse order renders the primary dataset first. */
    public static final Rotation ANTICLOCKWISE 
        = new Rotation("Rotation.ANTICLOCKWISE", 1.0);

    /** The name. */
    private String name;
    
    /** 
     * The factor (-1.0 for {@code CLOCKWISE} and 1.0 for 
     * {@code ANTICLOCKWISE}). 
     */
    private double factor;

    /**
     * Private constructor.
     *
     * @param name  the name.
     * @param factor  the rotation factor.
     */
    private Rotation(String name, double factor) {
        this.name = name;
        this.factor = factor;
    }

    /**
     * Returns a string representing the object.
     *
     * @return the string (never {@code null}).
     */
    @Override
    public String toString() {
        return this.name;
    }

    /**
     * Returns the rotation factor, which is -1.0 for {@code CLOCKWISE} 
     * and 1.0 for {@code ANTICLOCKWISE}.
     * 
     * @return the rotation factor.
     */
    public double getFactor() {
        return this.factor;
    }

    /**
     * Compares this object for equality with an other object.
     * Implementation note: This simply compares the factor instead
     * of the name.
     *
     * @param o the other object
     * @return true or false
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Rotation)) {
            return false;
        }

        final Rotation rotation = (Rotation) o;

        if (this.factor != rotation.factor) {
            return false;
        }

        return true;
    }

    /**
     * Returns a hash code value for the object.
     *
     * @return the hashcode
     */
    public int hashCode() {
        final long temp = Double.doubleToLongBits(this.factor);
        return (int) (temp ^ (temp >>> 32));
    }

    /**
     * Ensures that serialization returns the unique instances.
     * 
     * @return the object.
     * 
     * @throws ObjectStreamException if there is a problem.
     */
    private Object readResolve() throws ObjectStreamException {
        if (this.equals(Rotation.CLOCKWISE)) {
            return Rotation.CLOCKWISE;
        }
        else if (this.equals(Rotation.ANTICLOCKWISE)) {
            return Rotation.ANTICLOCKWISE;
        }      
        return null;
    }

}


@@ -1257,76 +1257,8 @@
 l;%0A%0A
-import java.io.ObjectStreamException;%0Aimport java.io.Serializable;%0A%0A
 /**%0A
@@ -1360,251 +1360,60 @@
 lic 
-final class Rotation implements Serializable %7B%0A%0A    /** For serialization. */%0A    private static final long serialVersionUID = -4662815260201591676L;%0A    %0A    /** Clockwise. */%0A    public static final Rotation CLOCKWISE %0A        = new Rotation
+enum Rotation %7B%0A%0A    /** Clockwise. */%0A    CLOCKWISE
 (%22Ro
@@ -1432,25 +1432,25 @@
 WISE%22, -1.0)
-;
+,
 %0A%0A    /** Th
@@ -1511,74 +1511,21 @@
     
-public static final Rotation ANTICLOCKWISE %0A        = new Rotation
+ANTICLOCKWISE
 (%22Ro
@@ -1604,20 +1604,16 @@
 me;%0A
-    
 %0A    /**
  %0A  
@@ -1608,17 +1608,16 @@
 %0A    /**
- 
 %0A     * 
@@ -1666,17 +1666,16 @@
  1.0 for
- 
 %0A     * 
@@ -1697,17 +1697,16 @@
 KWISE%7D).
- 
 %0A     */
@@ -2249,17 +2249,16 @@
 OCKWISE%7D
- 
 %0A     * 
@@ -2290,33 +2290,32 @@
 OCKWISE%7D.%0A     *
- 
 %0A     * @return 
@@ -2413,1323 +2413,7 @@
   %7D%0A
-%0A    /**%0A     * Compares this object for equality with an other object.%0A     * Implementation note: This simply compares the factor instead%0A     * of the name.%0A     *%0A     * @param o the other object%0A     * @return true or false%0A     */%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) %7B%0A            return true;%0A        %7D%0A        if (!(o instanceof Rotation)) %7B%0A            return false;%0A        %7D%0A%0A        final Rotation rotation = (Rotation) o;%0A%0A        if (this.factor != rotation.factor) %7B%0A            return false;%0A        %7D%0A%0A        return true;%0A    %7D%0A%0A    /**%0A     * Returns a hash code value for the object.%0A     *%0A     * @return the hashcode%0A     */%0A    public int hashCode() %7B%0A        final long temp = Double.doubleToLongBits(this.factor);%0A        return (int) (temp %5E (temp %3E%3E%3E 32));%0A    %7D%0A%0A    /**%0A     * Ensures that serialization returns the unique instances.%0A     * %0A     * @return the object.%0A     * %0A     * @throws ObjectStreamException if there is a problem.%0A     */%0A    private Object readResolve() throws ObjectStreamException %7B%0A        if (this.equals(Rotation.CLOCKWISE)) %7B%0A            return Rotation.CLOCKWISE;%0A        %7D%0A        else if (this.equals(Rotation.ANTICLOCKWISE)) %7B%0A            return Rotation.ANTICLOCKWISE;%0A        %7D      %0A        return null;%0A    %7D%0A%0A
 %7D%0A%0A

Convert to enum