2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.sal.java.api.generator
\r
10 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
\r
11 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
\r
14 * Template for generating JAVA enumeration type.
\r
16 class EnumTemplate extends BaseTemplate {
\r
20 * Enumeration which will be transformed to JAVA source code for enumeration
\r
22 val Enumeration enums
\r
25 * Constructs instance of this class with concrete <code>enums</code>.
\r
27 * @param enums enumeration which will be transformed to JAVA source code
\r
29 new(Enumeration enums) {
\r
30 super(enums as GeneratedType )
\r
36 * Generates only JAVA enumeration source code.
\r
38 * @return string with JAVA enumeration source code
\r
40 def generateAsInnerClass() {
\r
45 * Template method which generates enumeration body (declaration + enumeration items).
\r
47 * @return string with the enumeration body
\r
50 public enum «enums.name» {
\r
51 «FOR v : enums.values SEPARATOR ",\n"»
\r
52 «" "»«v.name»(«v.value»)«
\r
56 static java.util.Map<java.lang.Integer, «enums.name»> valueMap;
\r
59 valueMap = new java.util.HashMap<>();
\r
60 for («enums.name» enumItem : «enums.name».values())
\r
62 valueMap.put(enumItem.value, enumItem);
\r
66 private «enums.name»(int value) {
\r
71 * @return integer value
\r
73 public int getIntValue() {
\r
79 * @return corresponding «enums.name» item
\r
81 public static «enums.name» forValue(int valueArg) {
\r
82 return valueMap.get(valueArg);
\r