Cleanup use of Guava library
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / ModifierKind.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.yangtools.yang.model.api.type;
10
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.collect.Maps;
14 import java.util.Arrays;
15 import java.util.Map;
16 import java.util.Optional;
17 import javax.annotation.Nonnull;
18
19 /**
20  * Enum describing the effect of a YANG modifier statement.
21  *
22  * <p>
23  * As of YANG 1.1 (RFC7950) there is only one modifier value available and that
24  * is "invert-match". If there are more possible values added in the future,
25  * this enum can be extended with more enum constants.
26  */
27 public enum ModifierKind {
28     INVERT_MATCH("invert-match");
29
30     private static final Map<String, ModifierKind> MODIFIER_KIND_MAP = Maps.uniqueIndex(
31         Arrays.asList(ModifierKind.values()), ModifierKind::getKeyword);
32
33     private final String keyword;
34
35     ModifierKind(final String keyword) {
36         this.keyword = requireNonNull(keyword);
37     }
38
39     /**
40      * YANG keyword of this modifier.
41      *
42      * @return String that corresponds to the YANG keyword.
43      */
44     public @Nonnull String getKeyword() {
45         return keyword;
46     }
47
48     /**
49      * Returns ModifierKind based on supplied Yang keyword.
50      *
51      * @param keyword
52      *            Yang keyword in string form
53      * @return ModifierKind based on supplied YANG keyword
54      * @throws NullPointerException if keyword is null
55      */
56     public static Optional<ModifierKind> parse(final String keyword) {
57         return Optional.ofNullable(MODIFIER_KIND_MAP.get(requireNonNull(keyword)));
58     }
59 }