01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.lang.enums;
18:
19: import java.util.Iterator;
20: import java.util.List;
21: import java.util.Map;
22:
23: /**
24: * Broken Operator enumeration, getEnumClass() is not an Enum class.
25: *
26: * @author Stephen Colebourne
27: * @version $Id: Broken5OperationEnum.java 437554 2006-08-28 06:21:41Z bayard $
28: */
29: public abstract class Broken5OperationEnum extends Enum {
30: // This syntax works for JDK 1.3 and upwards:
31: // public static final OperationEnum PLUS = new OperationEnum("Plus") {
32: // public int eval(int a, int b) {
33: // return (a + b);
34: // }
35: // };
36: // public static final OperationEnum MINUS = new OperationEnum("Minus") {
37: // public int eval(int a, int b) {
38: // return (a - b);
39: // }
40: // };
41: // This syntax works for JDK 1.2 and upwards:
42: public static final Broken5OperationEnum PLUS = new PlusOperation();
43:
44: private static class PlusOperation extends Broken5OperationEnum {
45: private PlusOperation() {
46: super ("Plus");
47: }
48:
49: public int eval(int a, int b) {
50: return (a + b);
51: }
52: }
53:
54: public static final Broken5OperationEnum MINUS = new MinusOperation();
55:
56: private static class MinusOperation extends Broken5OperationEnum {
57: private MinusOperation() {
58: super ("Minus");
59: }
60:
61: public int eval(int a, int b) {
62: return (a - b);
63: }
64: }
65:
66: private Broken5OperationEnum(String name) {
67: super (name);
68: }
69:
70: public final Class getEnumClass() {
71: return String.class;
72: }
73:
74: public abstract int eval(int a, int b);
75:
76: public static Broken5OperationEnum getEnum(String name) {
77: return (Broken5OperationEnum) getEnum(
78: Broken5OperationEnum.class, name);
79: }
80:
81: public static Map getEnumMap() {
82: return getEnumMap(Broken5OperationEnum.class);
83: }
84:
85: public static List getEnumList() {
86: return getEnumList(Broken5OperationEnum.class);
87: }
88:
89: public static Iterator iterator() {
90: return iterator(Broken5OperationEnum.class);
91: }
92: }
|