source: src/main/java/agents/org/apache/commons/lang/enum1/EnumUtils.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 5.2 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * 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 */
17package agents.org.apache.commons.lang.enum1;
18
19import java.util.Iterator;
20import java.util.List;
21import java.util.Map;
22
23/**
24 * <p>
25 * Utility class for accessing and manipulating {@link Enum}s.
26 * </p>
27 *
28 * @deprecated Replaced by {@link agents.org.apache.commons.lang.enums.EnumUtils
29 * org.apache.commons.lang.enums.EnumUtils} and will be removed in
30 * version 3.0. All classes in this package are deprecated and
31 * repackaged to {@link agents.org.apache.commons.lang.enums} since
32 * <code>enum</code> is a Java 1.5 keyword.
33 * @see agents.org.apache.commons.lang.enums.EnumUtils
34 * @see Enum
35 * @see ValuedEnum
36 * @author Apache Software Foundation
37 * @author Gary Gregory
38 * @since 1.0
39 * @version $Id: EnumUtils.java 905636 2010-02-02 14:03:32Z niallp $
40 */
41public class EnumUtils {
42
43 /**
44 * Public constructor. This class should not normally be instantiated.
45 *
46 * @since 2.0
47 */
48 public EnumUtils() {
49 super();
50 }
51
52 /**
53 * <p>
54 * Gets an <code>Enum</code> object by class and name.
55 * </p>
56 *
57 * @param enumClass
58 * the class of the <code>Enum</code> to get
59 * @param name
60 * the name of the Enum to get, may be <code>null</code>
61 * @return the enum object
62 * @throws IllegalArgumentException
63 * if the enum class is <code>null</code>
64 */
65 public static Enum getEnum(Class enumClass, String name) {
66 return Enum.getEnum(enumClass, name);
67 }
68
69 /**
70 * <p>
71 * Gets a <code>ValuedEnum</code> object by class and value.
72 * </p>
73 *
74 * @param enumClass
75 * the class of the <code>Enum</code> to get
76 * @param value
77 * the value of the <code>Enum</code> to get
78 * @return the enum object, or null if the enum does not exist
79 * @throws IllegalArgumentException
80 * if the enum class is <code>null</code>
81 */
82 public static ValuedEnum getEnum(Class enumClass, int value) {
83 return (ValuedEnum) ValuedEnum.getEnum(enumClass, value);
84 }
85
86 /**
87 * <p>
88 * Gets the <code>Map</code> of <code>Enum</code> objects by name using the
89 * <code>Enum</code> class.
90 * </p>
91 *
92 * <p>
93 * If the requested class has no enum objects an empty <code>Map</code> is
94 * returned. The <code>Map</code> is unmodifiable.
95 * </p>
96 *
97 * @param enumClass
98 * the class of the <code>Enum</code> to get
99 * @return the enum object Map
100 * @throws IllegalArgumentException
101 * if the enum class is <code>null</code>
102 * @throws IllegalArgumentException
103 * if the enum class is not a subclass of <code>Enum</code>
104 */
105 public static Map getEnumMap(Class enumClass) {
106 return Enum.getEnumMap(enumClass);
107 }
108
109 /**
110 * <p>
111 * Gets the <code>List</code> of <code>Enum</code> objects using the
112 * <code>Enum</code> class.
113 * </p>
114 *
115 * <p>
116 * The list is in the order that the objects were created (source code
117 * order).
118 * </p>
119 *
120 * <p>
121 * If the requested class has no enum objects an empty <code>List</code> is
122 * returned. The <code>List</code> is unmodifiable.
123 * </p>
124 *
125 * @param enumClass
126 * the class of the Enum to get
127 * @return the enum object Map
128 * @throws IllegalArgumentException
129 * if the enum class is <code>null</code>
130 * @throws IllegalArgumentException
131 * if the enum class is not a subclass of <code>Enum</code>
132 */
133 public static List getEnumList(Class enumClass) {
134 return Enum.getEnumList(enumClass);
135 }
136
137 /**
138 * <p>
139 * Gets an <code>Iterator</code> over the <code>Enum</code> objects in an
140 * <code>Enum</code> class.
141 * </p>
142 *
143 * <p>
144 * The iterator is in the order that the objects were created (source code
145 * order).
146 * </p>
147 *
148 * <p>
149 * If the requested class has no enum objects an empty <code>Iterator</code>
150 * is returned. The <code>Iterator</code> is unmodifiable.
151 * </p>
152 *
153 * @param enumClass
154 * the class of the <code>Enum</code> to get
155 * @return an <code>Iterator</code> of the <code>Enum</code> objects
156 * @throws IllegalArgumentException
157 * if the enum class is <code>null</code>
158 * @throws IllegalArgumentException
159 * if the enum class is not a subclass of <code>Enum</code>
160 */
161 public static Iterator iterator(Class enumClass) {
162 return Enum.getEnumList(enumClass).iterator();
163 }
164
165}
Note: See TracBrowser for help on using the repository browser.