435b400c2fdb7d28692c944b3f091af5a05e8a2c
[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 com.google.common.base.Preconditions;
12 import com.google.common.collect.Maps;
13 import java.util.Arrays;
14 import java.util.Map;
15 import java.util.Optional;
16 import javax.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
23  * is "invert-match". If there are more possible values added in the future,
24  * this enum can be extended with more enum constants.
25  */
26 public enum ModifierKind {
27     INVERT_MATCH("invert-match");
28
29     private static final Map<String, ModifierKind> MODIFIER_KIND_MAP = Maps.uniqueIndex(
30         Arrays.asList(ModifierKind.values()), ModifierKind::getKeyword);
31
32     private final String keyword;
33
34     ModifierKind(final String keyword) {
35         this.keyword = Preconditions.checkNotNull(keyword);
36     }
37
38     /**
39      * YANG keyword of this modifier.
40      *
41      * @return String that corresponds to the YANG keyword.
42      */
43     public @Nonnull String getKeyword() {
44         return keyword;
45     }
46
47     /**
48      * Returns ModifierKind based on supplied Yang keyword.
49      *
50      * @param keyword
51      *            Yang keyword in string form
52      * @return ModifierKind based on supplied YANG keyword
53      * @throws NullPointerException if keyword is null
54      */
55     public static Optional<ModifierKind> parse(final String keyword) {
56         return Optional.ofNullable(MODIFIER_KIND_MAP.get(Preconditions.checkNotNull(keyword)));
57     }
58 }