KickJava   Java API By Example, From Geeks To Geeks.

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


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  * <p>Utility class for accessing and manipulating {@link Enum}s.</p>
24  *
25  * @deprecated Replaced by {@link org.apache.commons.lang.enums.EnumUtils org.apache.commons.lang.enums.EnumUtils}
26  * and will be removed in version 3.0. All classes in this package are deprecated and repackaged to
27  * {@link org.apache.commons.lang.enums} since <code>enum</code> is a Java 1.5 keyword.
28  * @see org.apache.commons.lang.enums.EnumUtils
29  * @see Enum
30  * @see ValuedEnum
31  * @author Stephen Colebourne
32  * @author Gary Gregory
33  * @since 1.0
34  * @version $Id: EnumUtils.java 161243 2005-04-14 04:30:28Z ggregory $
35  */

36 public class EnumUtils {
37
38     /**
39      * Public constructor. This class should not normally be instantiated.
40      * @since 2.0
41      */

42     public EnumUtils() {
43     }
44
45     /**
46      * <p>Gets an <code>Enum</code> object by class and name.</p>
47      *
48      * @param enumClass the class of the <code>Enum</code> to get
49      * @param name the name of the Enum to get, may be <code>null</code>
50      * @return the enum object
51      * @throws IllegalArgumentException if the enum class is <code>null</code>
52      */

53     public static Enum getEnum(Class enumClass, String name) {
54         return Enum.getEnum(enumClass, name);
55     }
56
57     /**
58      * <p>Gets a <code>ValuedEnum</code> object by class and value.</p>
59      *
60      * @param enumClass the class of the <code>Enum</code> to get
61      * @param value the value of the <code>Enum</code> to get
62      * @return the enum object, or null if the enum does not exist
63      * @throws IllegalArgumentException if the enum class is <code>null</code>
64      */

65     public static ValuedEnum getEnum(Class enumClass, int value) {
66         return (ValuedEnum) ValuedEnum.getEnum(enumClass, value);
67     }
68
69     /**
70      * <p>Gets the <code>Map</code> of <code>Enum</code> objects by
71      * name using the <code>Enum</code> class.</p>
72      *
73      * <p>If the requested class has no enum objects an empty
74      * <code>Map</code> is returned. The <code>Map</code> is unmodifiable.</p>
75      *
76      * @param enumClass the class of the <code>Enum</code> to get
77      * @return the enum object Map
78      * @throws IllegalArgumentException if the enum class is <code>null</code>
79      * @throws IllegalArgumentException if the enum class is not a subclass
80      * of <code>Enum</code>
81      */

82     public static Map getEnumMap(Class enumClass) {
83         return Enum.getEnumMap(enumClass);
84     }
85
86     /**
87      * <p>Gets the <code>List</code> of <code>Enum</code> objects using
88      * the <code>Enum</code> class.</p>
89      *
90      * <p>The list is in the order that the objects were created
91      * (source code order).</p>
92      *
93      * <p>If the requested class has no enum objects an empty
94      * <code>List</code> is returned. The <code>List</code> is unmodifiable.</p>
95      *
96      * @param enumClass the class of the Enum to get
97      * @return the enum object Map
98      * @throws IllegalArgumentException if the enum class is <code>null</code>
99      * @throws IllegalArgumentException if the enum class is not a subclass
100      * of <code>Enum</code>
101      */

102     public static List getEnumList(Class enumClass) {
103         return Enum.getEnumList(enumClass);
104     }
105
106     /**
107      * <p>Gets an <code>Iterator</code> over the <code>Enum</code> objects
108      * in an <code>Enum</code> class.</p>
109      *
110      * <p>The iterator is in the order that the objects were created
111      * (source code order).</p>
112      *
113      * <p>If the requested class has no enum objects an empty
114      * <code>Iterator</code> is returned. The <code>Iterator</code>
115      * is unmodifiable.</p>
116      *
117      * @param enumClass the class of the <code>Enum</code> to get
118      * @return an <code>Iterator</code> of the <code>Enum</code> objects
119      * @throws IllegalArgumentException if the enum class is <code>null</code>
120      * @throws IllegalArgumentException if the enum class is not a subclass of <code>Enum</code>
121      */

122     public static Iterator iterator(Class enumClass) {
123         return Enum.getEnumList(enumClass).iterator();
124     }
125     
126 }
127
Popular Tags