Introduce {Qualified,Unqualified}.of()
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / ErrorSeverity.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.common;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.Maps;
13 import java.util.Arrays;
14 import java.util.Map;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Enumeration of {@code error-severity} values, as defined by
20  * <a href="https://datatracker.ietf.org/doc/html/rfc4741#section-4.3">RFC4741, section 4.3</a>.
21  */
22 @NonNullByDefault
23 public enum ErrorSeverity {
24     /**
25      * An error preventing an operation from completing successfully.
26      */
27     ERROR("error"),
28     /**
29      * A warning not affecting an operation's ability to complete successfully.
30      */
31     WARNING("warning");
32
33     private static final Map<String, ErrorSeverity> BY_ELEMENT_BODY =
34         Maps.uniqueIndex(Arrays.asList(values()), ErrorSeverity::elementBody);
35
36     private final String elementBody;
37
38     ErrorSeverity(final String elementName) {
39         this.elementBody = requireNonNull(elementName);
40     }
41
42     /**
43      * Return the XML element body of this object.
44      *
45      * @return element body of this object
46      */
47     public String elementBody() {
48         return elementBody;
49     }
50
51     public static @Nullable ErrorSeverity forElementBody(final String elementBody) {
52         return BY_ELEMENT_BODY.get(requireNonNull(elementBody));
53     }
54 }