/* ===========================================================
 * 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;

/**
 * Defines tokens used to indicate sorting order (ascending or descending).
 */
public final class SortOrder implements Serializable {

    /** For serialization. */
    private static final long serialVersionUID = -2124469847758108312L;
    
    /** Ascending order. */
    public static final SortOrder ASCENDING 
        = new SortOrder("SortOrder.ASCENDING");

    /** Descending order. */
    public static final SortOrder DESCENDING 
        = new SortOrder("SortOrder.DESCENDING");

    /** The name. */
    private String name;

    /**
     * Private constructor.
     *
     * @param name  the name.
     */
    private SortOrder(String name) {
        this.name = name;
    }

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

    /**
     * Returns {@code true} if this object is equal to the specified 
     * object, and {@code false} otherwise.
     *
     * @param obj  the other object.
     *
     * @return A boolean.
     */
    @Override
    public boolean equals(Object obj) {

        if (this == obj) {
            return true;
        }
        if (!(obj instanceof SortOrder)) {
            return false;
        }

        SortOrder that = (SortOrder) obj;
        if (!this.name.equals(that.toString())) {
            return false;
        }

        return true;
    }
    
    /**
     * Returns a hash code value for the object.
     *
     * @return The hashcode
     */
    @Override
    public int hashCode() {
        return this.name.hashCode();
    }

    /**
     * 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(SortOrder.ASCENDING)) {
            return SortOrder.ASCENDING;
        }
        else if (this.equals(SortOrder.DESCENDING)) {
            return SortOrder.DESCENDING;
        }
        return null;
    }
}


@@ -1257,76 +1257,8 @@
 l;%0A%0A
-import java.io.ObjectStreamException;%0Aimport java.io.Serializable;%0A%0A
 /**%0A
@@ -1348,260 +1348,67 @@
 lic 
-final class SortOrder implements Serializable %7B%0A%0A    /** For serialization. */%0A    private static final long serialVersionUID = -2124469847758108312L;%0A    %0A    /** Ascending order. */%0A    public static final SortOrder ASCENDING %0A        = new SortOrder
+enum SortOrder %7B%0A%0A    /** Ascending order. */%0A    ASCENDING
 (%22So
@@ -1418,33 +1418,33 @@
 rder.ASCENDING%22)
-;
+,
 %0A%0A    /** Descen
@@ -1466,73 +1466,18 @@
     
-public static final SortOrder DESCENDING %0A        = new SortOrder
+DESCENDING
 (%22So
@@ -1532,16 +1532,22 @@
 private 
+final 
 String n
@@ -1884,1235 +1884,5 @@
  %7D%0A%0A
-    /**%0A     * Returns %7B@code true%7D if this object is equal to the specified %0A     * object, and %7B@code false%7D otherwise.%0A     *%0A     * @param obj  the other object.%0A     *%0A     * @return A boolean.%0A     */%0A    @Override%0A    public boolean equals(Object obj) %7B%0A%0A        if (this == obj) %7B%0A            return true;%0A        %7D%0A        if (!(obj instanceof SortOrder)) %7B%0A            return false;%0A        %7D%0A%0A        SortOrder that = (SortOrder) obj;%0A        if (!this.name.equals(that.toString())) %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    @Override%0A    public int hashCode() %7B%0A        return this.name.hashCode();%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(SortOrder.ASCENDING)) %7B%0A            return SortOrder.ASCENDING;%0A        %7D%0A        else if (this.equals(SortOrder.DESCENDING)) %7B%0A            return SortOrder.DESCENDING;%0A        %7D%0A        return null;%0A    %7D%0A%7D%0A%0A
+%7D

Convert to enum