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: * Color enumeration which demonstrates how to provide a view of the constants
25: * in a different class to the Enum. This technique is the safest, however it
26: * is obviously inconvenient as it involves defining two sets of constants.
27: * See NestedLinked for an alternative.
28: *
29: * @author Stephen Colebourne
30: * @version $Id: NestReferenced.java 437554 2006-08-28 06:21:41Z bayard $
31: */
32:
33: public final class NestReferenced {
34:
35: public static final ColorEnum RED = ColorEnum.RED;
36: public static final ColorEnum GREEN = ColorEnum.GREEN;
37: public static final ColorEnum BLUE = ColorEnum.BLUE;
38:
39: public NestReferenced() {
40: super ();
41: }
42:
43: public static final class ColorEnum extends Enum {
44:
45: // must be defined here, not just in outer class
46: private static final ColorEnum RED = new ColorEnum("Red");
47: private static final ColorEnum GREEN = new ColorEnum("Green");
48: private static final ColorEnum BLUE = new ColorEnum("Blue");
49:
50: private ColorEnum(String color) {
51: super (color);
52: }
53:
54: public static ColorEnum getEnum(String color) {
55: return (ColorEnum) getEnum(ColorEnum.class, color);
56: }
57:
58: public static Map getEnumMap() {
59: return getEnumMap(ColorEnum.class);
60: }
61:
62: public static List getEnumList() {
63: return getEnumList(ColorEnum.class);
64: }
65:
66: public static Iterator iterator() {
67: return iterator(ColorEnum.class);
68: }
69: }
70: }
|