KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > util > SortOrder


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  * SortOrder.java
29  * --------------
30  * (C) Copyright 2003, 2004, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: SortOrder.java,v 1.6 2005/10/18 13:24:19 mungady Exp $
36  *
37  * Changes:
38  * --------
39  * 05-Mar-2003 : Version 1 (DG);
40  * 13-Mar-2003 : Implemented Serializable (DG);
41  * 27-Aug-2003 : Moved from JFreeChart --> JCommon (DG);
42  * 29-Jul-2004 : Fixed error in readResolve() method (DG);
43  *
44  */

45
46 package org.jfree.util;
47
48 import java.io.ObjectStreamException JavaDoc;
49 import java.io.Serializable JavaDoc;
50
51 /**
52  * Defines tokens used to indicate sorting order (ascending or descending).
53  *
54  * @author David Gilbert
55  */

56 public final class SortOrder implements Serializable JavaDoc {
57
58     /** For serialization. */
59     private static final long serialVersionUID = -2124469847758108312L;
60     
61     /** Ascending order. */
62     public static final SortOrder ASCENDING
63         = new SortOrder("SortOrder.ASCENDING");
64
65     /** Descending order. */
66     public static final SortOrder DESCENDING
67         = new SortOrder("SortOrder.DESCENDING");
68
69     /** The name. */
70     private String JavaDoc name;
71
72     /**
73      * Private constructor.
74      *
75      * @param name the name.
76      */

77     private SortOrder(final String JavaDoc name) {
78         this.name = name;
79     }
80
81     /**
82      * Returns a string representing the object.
83      *
84      * @return The string.
85      */

86     public String JavaDoc toString() {
87         return this.name;
88     }
89
90     /**
91      * Returns <code>true</code> if this object is equal to the specified
92      * object, and <code>false</code> otherwise.
93      *
94      * @param obj the other object.
95      *
96      * @return A boolean.
97      */

98     public boolean equals(final Object JavaDoc obj) {
99
100         if (this == obj) {
101             return true;
102         }
103         if (!(obj instanceof SortOrder)) {
104             return false;
105         }
106
107         final SortOrder that = (SortOrder) obj;
108         if (!this.name.equals(that.toString())) {
109             return false;
110         }
111
112         return true;
113     }
114     
115     /**
116      * Returns a hash code value for the object.
117      *
118      * @return The hashcode
119      */

120     public int hashCode() {
121         return this.name.hashCode();
122     }
123
124     /**
125      * Ensures that serialization returns the unique instances.
126      *
127      * @return The object.
128      *
129      * @throws ObjectStreamException if there is a problem.
130      */

131     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
132         if (this.equals(SortOrder.ASCENDING)) {
133             return SortOrder.ASCENDING;
134         }
135         else if (this.equals(SortOrder.DESCENDING)) {
136             return SortOrder.DESCENDING;
137         }
138         return null;
139     }
140 }
141
Popular Tags