001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.lang.enum;
018    
019    import java.util.Iterator;
020    import java.util.List;
021    import java.util.Map;
022    
023    /**
024     * <p>Utility class for accessing and manipulating {@link Enum}s.</p>
025     *
026     * @deprecated Replaced by {@link org.apache.commons.lang.enums.EnumUtils org.apache.commons.lang.enums.EnumUtils} 
027     *          and will be removed in version 3.0. All classes in this package are deprecated and repackaged to 
028     *          {@link org.apache.commons.lang.enums} since <code>enum</code> is a Java 1.5 keyword. 
029     * @see org.apache.commons.lang.enums.EnumUtils
030     * @see Enum
031     * @see ValuedEnum
032     * @author Apache Software Foundation
033     * @author Gary Gregory
034     * @since 1.0
035     * @version $Id: EnumUtils.java 905636 2010-02-02 14:03:32Z niallp $
036     */
037    public class EnumUtils {
038    
039        /**
040         * Public constructor. This class should not normally be instantiated.
041         * @since 2.0
042         */
043        public EnumUtils() {
044            super();
045        }
046    
047        /**
048         * <p>Gets an <code>Enum</code> object by class and name.</p>
049         * 
050         * @param enumClass  the class of the <code>Enum</code> to get
051         * @param name  the name of the Enum to get, may be <code>null</code>
052         * @return the enum object
053         * @throws IllegalArgumentException if the enum class is <code>null</code>
054         */
055        public static Enum getEnum(Class enumClass, String name) {
056            return Enum.getEnum(enumClass, name);
057        }
058    
059        /**
060         * <p>Gets a <code>ValuedEnum</code> object by class and value.</p>
061         * 
062         * @param enumClass  the class of the <code>Enum</code> to get
063         * @param value  the value of the <code>Enum</code> to get
064         * @return the enum object, or null if the enum does not exist
065         * @throws IllegalArgumentException if the enum class is <code>null</code>
066         */
067        public static ValuedEnum getEnum(Class enumClass, int value) {
068            return (ValuedEnum) ValuedEnum.getEnum(enumClass, value);
069        }
070    
071        /**
072         * <p>Gets the <code>Map</code> of <code>Enum</code> objects by
073         * name using the <code>Enum</code> class.</p>
074         *
075         * <p>If the requested class has no enum objects an empty
076         * <code>Map</code> is returned. The <code>Map</code> is unmodifiable.</p>
077         * 
078         * @param enumClass  the class of the <code>Enum</code> to get
079         * @return the enum object Map
080         * @throws IllegalArgumentException if the enum class is <code>null</code>
081         * @throws IllegalArgumentException if the enum class is not a subclass
082         *  of <code>Enum</code>
083         */
084        public static Map getEnumMap(Class enumClass) {
085            return Enum.getEnumMap(enumClass);
086        }
087    
088        /**
089         * <p>Gets the <code>List</code> of <code>Enum</code> objects using
090         * the <code>Enum</code> class.</p>
091         *
092         * <p>The list is in the order that the objects were created
093         * (source code order).</p>
094         *
095         * <p>If the requested class has no enum objects an empty
096         * <code>List</code> is returned. The <code>List</code> is unmodifiable.</p>
097         * 
098         * @param enumClass  the class of the Enum to get
099         * @return the enum object Map
100         * @throws IllegalArgumentException if the enum class is <code>null</code>
101         * @throws IllegalArgumentException if the enum class is not a subclass
102         *  of <code>Enum</code>
103         */
104        public static List getEnumList(Class enumClass) {
105            return Enum.getEnumList(enumClass);
106        }
107    
108        /**
109         * <p>Gets an <code>Iterator</code> over the <code>Enum</code> objects
110         * in an <code>Enum</code> class.</p>
111         *
112         * <p>The iterator is in the order that the objects were created
113         * (source code order).</p>
114         *
115         * <p>If the requested class has no enum objects an empty
116         * <code>Iterator</code> is returned. The <code>Iterator</code>
117         * is unmodifiable.</p>
118         * 
119         * @param enumClass  the class of the <code>Enum</code> to get
120         * @return an <code>Iterator</code> of the <code>Enum</code> objects
121         * @throws IllegalArgumentException if the enum class is <code>null</code>
122         * @throws IllegalArgumentException if the enum class is not a subclass of <code>Enum</code>
123         */
124        public static Iterator iterator(Class enumClass) {
125            return Enum.getEnumList(enumClass).iterator();
126        }
127        
128    }