7966a32c0324bd5e6f3d2564e5258c89ddce25e0
[mdsal.git] / binding2 / mdsal-binding2-java-api-generator / src / main / twirl / org / opendaylight / mdsal / binding2 / enumTemplate.scala.txt
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 @import org.opendaylight.mdsal.binding2.java.api.generator.renderers.EnumRenderer.writeEnumeration
10 @import org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.formatDataForJavaDoc
11 @import org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.wrapToDocumentation
12 @import org.opendaylight.mdsal.binding2.model.api.Enumeration
13 @import org.opendaylight.mdsal.binding2.model.api.GeneratedType
14
15 @(genType: GeneratedType, importedName: String)
16 @if(genType != null) {
17 @{wrapToDocumentation(formatDataForJavaDoc(genType))}
18 public enum @{genType.getName} {
19 @{writeEnumeration(genType.asInstanceOf[Enumeration])}
20
21     @{importedName} name;
22     int value;
23     private static final java.util.Map<java.lang.Integer, @{genType.getName}> VALUE_MAP;
24
25     static {
26         final com.google.common.collect.ImmutableMap.Builder<java.lang.Integer, @{genType.getName}> b = com.google.common.collect.ImmutableMap.builder();
27         for (@{genType.getName} enumItem : @{genType.getName}.values())
28         {
29             b.put(enumItem.value, enumItem);
30         }
31
32         VALUE_MAP = b.build();
33     }
34
35     private @{genType.getName}(int value, @{importedName} name) {
36         this.value = value;
37         this.name = name;
38     }
39
40     /**
41      * Returns the name of the enumeration item as it is specified in the input yang.
42      *
43      * @@return the name of the enumeration item as it is specified in the input yang
44      */
45     public @{importedName} getName() {
46         return name;
47     }
48
49     /**
50      * @@return integer value
51      */
52     public int getIntValue() {
53         return value;
54     }
55
56     /**
57      * @@param valueArg
58      * @@return corresponding @{genType.getName} item
59      */
60     public static @{genType.getName} forValue(int valueArg) {
61         return VALUE_MAP.get(valueArg);
62     }
63 }
64 }