01: /*
02: * Copyright 2005 JBoss Inc
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.drools.examples.manners;
17:
18: public class Hobby {
19: public static final String stringH1 = "h1";
20: public static final String stringH2 = "h2";
21: public static final String stringH3 = "h3";
22: public static final String stringH4 = "h4";
23: public static final String stringH5 = "h5";
24:
25: public static final String[] hobbyStrings = new String[] {
26: Hobby.stringH1, Hobby.stringH2, Hobby.stringH3,
27: Hobby.stringH4, Hobby.stringH5 };
28:
29: public static final Hobby H1 = new Hobby(1);
30: public static final Hobby H2 = new Hobby(2);
31: public static final Hobby H3 = new Hobby(3);
32: public static final Hobby H4 = new Hobby(4);
33: public static final Hobby H5 = new Hobby(5);
34:
35: private String hobbyStr;
36: private int hobbyIndex;
37:
38: public Hobby() {
39: }
40:
41: private Hobby(final int hobby) {
42: this .hobbyIndex = hobby - 1;
43: this .hobbyStr = Hobby.hobbyStrings[this .hobbyIndex];
44: }
45:
46: public String getHobby() {
47: return this .hobbyStr;
48: }
49:
50: public final static Hobby resolve(final String hobby) {
51: if (Hobby.stringH1.equals(hobby)) {
52: return Hobby.H1;
53: } else if (Hobby.stringH2.equals(hobby)) {
54: return Hobby.H2;
55: } else if (Hobby.stringH3.equals(hobby)) {
56: return Hobby.H3;
57: } else if (Hobby.stringH4.equals(hobby)) {
58: return Hobby.H4;
59: } else if (Hobby.stringH5.equals(hobby)) {
60: return Hobby.H5;
61: } else {
62: throw new RuntimeException("Hobby '" + hobby
63: + "' does not exist for Hobby Enum");
64: }
65: }
66:
67: public String toString() {
68: return getHobby();
69: }
70:
71: public boolean equals(final Object object) {
72: return (this == object);
73: }
74:
75: public int hashCode() {
76: return this.hobbyIndex;
77: }
78:
79: }
|