KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > query > SortOrder


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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 package org.outerj.daisy.repository.query;
17
18 public final class SortOrder {
19     private final String JavaDoc name;
20     private final char code;
21
22     private SortOrder(String JavaDoc name, char code) {
23         this.name = name;
24         this.code = code;
25     }
26
27     public String JavaDoc toString() {
28         return name;
29     }
30
31     public char getCode() {
32         return code;
33     }
34
35     public static SortOrder fromString(String JavaDoc name) {
36         if (ASCENDING.name.equals(name))
37             return ASCENDING;
38         else if (DESCENDING.name.equals(name))
39             return DESCENDING;
40         else if (NONE.name.equals(name))
41             return NONE;
42         else
43             throw new RuntimeException JavaDoc("Invalid sort order name: " + name);
44     }
45
46     public static SortOrder fromCode(char code) {
47         if (ASCENDING.code == code)
48             return ASCENDING;
49         else if (DESCENDING.code == code)
50             return DESCENDING;
51         else if (NONE.code == code)
52             return NONE;
53         else
54             throw new RuntimeException JavaDoc("Invalid sort order code: " + code);
55     }
56
57     public static final SortOrder ASCENDING = new SortOrder("ascending", 'A');
58     public static final SortOrder DESCENDING = new SortOrder("descending", 'D');
59     public static final SortOrder NONE = new SortOrder("none", 'N');
60 }
61
Popular Tags