KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > databinding > datagrid > api > sort > SortDirection


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.databinding.datagrid.api.sort;
19
20 /**
21  * <p>
22  * The SortDirection class is an abstract representation of the direction of a sort. This class
23  * is able to represent a sort that is either {@link #ASCENDING}, {@link #DESCENDING},
24  * or {@link #NONE}.
25  * </p>
26  * <p>
27  * The SortDirection class is used to specify the direction of sorting on a {@link Sort} JavaBean instance.
28  * </p>
29  */

30 public class SortDirection
31     implements java.io.Serializable JavaDoc {
32
33     /**
34      * Int value representing an ascending sort.
35      */

36     public static final int INT_ASCENDING = 0;
37
38     /**
39      * Int value representing a descending sort.
40      */

41     public static final int INT_DESCENDING = 1;
42
43     /**
44      * Int value representing no sort.
45      */

46     public static final int INT_NONE = 2;
47
48     /**
49      * Direction representing ascending.
50      */

51     public static final SortDirection ASCENDING = new SortDirection(INT_ASCENDING);
52
53     /**
54      * Direction representing descending.
55      */

56     public static final SortDirection DESCENDING = new SortDirection(INT_DESCENDING);
57
58     /**
59      * Direction representing no sort direction
60      * */

61     public static final SortDirection NONE = new SortDirection(INT_NONE);
62
63     private int _val;
64
65     private SortDirection(int val) {
66         _val = val;
67     }
68
69     /**
70      * Convert this sort direction to a readable String. Note, this does not return the query language
71      * operator -- only text for the direction itself.
72      * @return the readable direction name
73      */

74     public String JavaDoc toString() {
75         switch(_val) {
76             case INT_ASCENDING:
77                 return "ASCENDING";
78             case INT_DESCENDING:
79                 return "DESCENDING";
80             case INT_NONE:
81                 return "NONE";
82         }
83
84         String JavaDoc message = "Encountered an unknown sort direction with value \"" + _val + "\"";
85         assert false : message;
86         throw new IllegalStateException JavaDoc(message);
87     }
88
89     /**
90      * Equals method.
91      * @param value value to check
92      * @return <code>true</code> if this direction matches the <code>value</code>; <code>false</code> otherwise.
93      */

94     public boolean equals(Object JavaDoc value) {
95         if(value == this)
96             return true;
97         if(value == null || !(value instanceof SortDirection))
98             return false;
99
100         return ((SortDirection)value)._val == _val;
101     }
102
103     /**
104      * Hash code.
105      * @return the hash code
106      */

107     public int hashCode() {
108         return _val;
109     }
110
111     /**
112      * The direction's int value.
113      *
114      * @return the direction's value
115      */

116     public int getValue() {
117         return _val;
118     }
119 }
120
Popular Tags