KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > enum > Broken5OperationEnum


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.enum;
17
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21
22 /**
23  * Broken Operator enumeration, getEnumClass() is not an Enum class.
24  *
25  * @author Stephen Colebourne
26  * @version $Id: Broken5OperationEnum.java 161244 2005-04-14 06:16:36Z ggregory $
27  */

28 public abstract class Broken5OperationEnum extends Enum {
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 Broken5OperationEnum PLUS = new PlusOperation();
42     private static class PlusOperation extends Broken5OperationEnum {
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 Broken5OperationEnum MINUS = new MinusOperation();
51     private static class MinusOperation extends Broken5OperationEnum {
52         private MinusOperation() {
53             super("Minus");
54         }
55         public int eval(int a, int b) {
56             return (a - b);
57         }
58     }
59
60     private Broken5OperationEnum(String name) {
61         super(name);
62     }
63     
64     public final Class getEnumClass() {
65         return String.class;
66     }
67
68     public abstract int eval(int a, int b);
69
70     public static Broken5OperationEnum getEnum(String name) {
71         return (Broken5OperationEnum) getEnum(Broken5OperationEnum.class, name);
72     }
73
74     public static Map getEnumMap() {
75         return getEnumMap(Broken5OperationEnum.class);
76     }
77
78     public static List getEnumList() {
79         return getEnumList(Broken5OperationEnum.class);
80     }
81
82     public static Iterator iterator() {
83         return iterator(Broken5OperationEnum.class);
84     }
85 }
86
Popular Tags