KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > enums > Broken3OperationEnum


1 /*
2  * Copyright 2002-2005 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 package org.apache.commons.lang.enums;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 /**
23  * Broken Operator enumeration, getEnumClass() is Enum.class.
24  *
25  * @author Stephen Colebourne
26  * @version $Id: Broken3OperationEnum.java 161244 2005-04-14 06:16:36Z ggregory $
27  */

28 public abstract class Broken3OperationEnum extends Enum JavaDoc {
29     // This syntax works for JDK 1.3 and upwards:
30
// public static final OperationEnum PLUS = new OperationEnum("Plus") {
31
// public int eval(int a, int b) {
32
// return (a + b);
33
// }
34
// };
35
// public static final OperationEnum MINUS = new OperationEnum("Minus") {
36
// public int eval(int a, int b) {
37
// return (a - b);
38
// }
39
// };
40
// This syntax works for JDK 1.2 and upwards:
41
public static final Broken3OperationEnum PLUS = new PlusOperation();
42     private static class PlusOperation extends Broken3OperationEnum {
43         private PlusOperation() {
44             super("Plus");
45         }
46         public int eval(int a, int b) {
47             return (a + b);
48         }
49     }
50     public static final Broken3OperationEnum MINUS = new MinusOperation();
51     private static class MinusOperation extends Broken3OperationEnum {
52         private MinusOperation() {
53             super("Minus");
54         }
55         public int eval(int a, int b) {
56             return (a - b);
57         }
58     }
59
60     private Broken3OperationEnum(String JavaDoc name) {
61         super(name);
62     }
63     
64     public final Class JavaDoc getEnumClass() {
65         return Enum JavaDoc.class;
66     }
67
68     public abstract int eval(int a, int b);
69
70     public static Broken3OperationEnum getEnum(String JavaDoc name) {
71         return (Broken3OperationEnum) getEnum(Broken3OperationEnum.class, name);
72     }
73
74     public static Map JavaDoc getEnumMap() {
75         return getEnumMap(Broken3OperationEnum.class);
76     }
77
78     public static List JavaDoc getEnumList() {
79         return getEnumList(Broken3OperationEnum.class);
80     }
81
82     public static Iterator JavaDoc iterator() {
83         return iterator(Broken3OperationEnum.class);
84     }
85 }
86
Popular Tags