1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  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
17package java.lang;
18
19/**
20 * Thrown if an {@code enum} constant does not exist for a particular name.
21 *
22 * @since 1.5
23 */
24public class EnumConstantNotPresentException extends RuntimeException {
25
26    private static final long serialVersionUID = -6046998521960521108L;
27
28    @SuppressWarnings("unchecked")
29    private final Class<? extends Enum> enumType;
30
31    private final String constantName;
32
33    /**
34     * Constructs a new {@code EnumConstantNotPresentException} with the current
35     * stack trace and a detail message based on the specified enum type and
36     * missing constant name.
37     *
38     * @param enumType
39     *            the enum type.
40     * @param constantName
41     *            the missing constant name.
42     */
43    @SuppressWarnings("unchecked")
44    public EnumConstantNotPresentException(Class<? extends Enum> enumType, String constantName) {
45        super("enum constant " + enumType.getName() + "." + constantName + " is missing");
46        this.enumType = enumType;
47        this.constantName = constantName;
48    }
49
50    /**
51     * Gets the enum type for which the constant name is missing.
52     *
53     * @return the enum type for which a constant name has not been found.
54     */
55    @SuppressWarnings("unchecked")
56    public Class<? extends Enum> enumType() {
57        return enumType;
58    }
59
60    /**
61     * Gets the name of the missing constant.
62     *
63     * @return the name of the constant that has not been found in the enum
64     *         type.
65     */
66    public String constantName() {
67        return constantName;
68    }
69}
70