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