01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 enum SortOrder {
19: ASCENDING("ascending", 'A'), DESCENDING("descending", 'D'), NONE(
20: "none", 'N');
21:
22: private final String name;
23: private final char code;
24:
25: private SortOrder(String name, char code) {
26: this .name = name;
27: this .code = code;
28: }
29:
30: public String toString() {
31: return name;
32: }
33:
34: public char getCode() {
35: return code;
36: }
37:
38: public static SortOrder fromString(String name) {
39: if (ASCENDING.name.equals(name))
40: return ASCENDING;
41: else if (DESCENDING.name.equals(name))
42: return DESCENDING;
43: else if (NONE.name.equals(name))
44: return NONE;
45: else
46: throw new RuntimeException("Invalid sort order name: "
47: + name);
48: }
49:
50: public static SortOrder fromCode(char code) {
51: if (ASCENDING.code == code)
52: return ASCENDING;
53: else if (DESCENDING.code == code)
54: return DESCENDING;
55: else if (NONE.code == code)
56: return NONE;
57: else
58: throw new RuntimeException("Invalid sort order code: "
59: + code);
60: }
61: }
|