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 Sex {
19: public static final Sex M = new Sex(0);
20: public static final Sex F = new Sex(1);
21:
22: public static final String stringM = "m";
23: public static final String stringF = "f";
24: public static final String[] sexList = new String[] { Sex.stringM,
25: Sex.stringF };
26:
27: private int sex;
28:
29: public Sex() {
30: }
31:
32: private Sex(final int sex) {
33: this .sex = sex;
34: }
35:
36: public String getSex() {
37: return Sex.sexList[this .sex];
38: }
39:
40: public final static Sex resolve(final String sex) {
41: if (Sex.stringM.equals(sex)) {
42: return Sex.M;
43: } else if (Sex.stringF.equals(sex)) {
44: return Sex.F;
45: } else {
46: throw new RuntimeException("Sex '" + sex
47: + "' does not exist for Sex Enum");
48: }
49: }
50:
51: public String toString() {
52: return getSex();
53: }
54:
55: public boolean equals(final Object object) {
56: return this == object;
57: }
58:
59: public int hashCode() {
60: return this.sex;
61: }
62:
63: }
|