Feature uses features-parent as parent
[groupbasedpolicy.git] / renderers / opflex / src / main / java / org / opendaylight / groupbasedpolicy / renderer / opflex / mit / EnumInfo.java
1 /*
2  * Copyright (c) 2014 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.groupbasedpolicy.renderer.opflex.mit;
10
11 import java.math.BigInteger;
12 import java.util.HashMap;
13 import java.util.Map;
14
15 /**
16  * An object that represents an enum in the MIT's
17  * PropertyInfo object map
18  *
19  * @author tbachman
20  */
21 public interface EnumInfo {
22
23     /**
24      * Get the name of the enum as it appears in the MIT's
25      * PropertyInfo map.
26      *
27      * @return
28      */
29     public String getName();
30
31     /**
32      * Get the Integer representation of the value by name
33      * for the enum
34      *
35      * @param name
36      * @return
37      */
38     public BigInteger getEnumValue(String name);
39
40     public String getEnumValue(BigInteger value);
41
42     /**
43      * Class for building immutable EnumInfo objects
44      *
45      * @author tbachman
46      */
47     public static class EnumInfoBuilder {
48
49         private String name;
50         private final Map<String, BigInteger> enumValuesByString = new HashMap<>();
51         private final Map<BigInteger, String> enumValuesByInt = new HashMap<>();
52
53         public EnumInfoBuilder() {
54         }
55
56         /**
57          * Set the name of the EnumInfo object
58          *
59          * @param name
60          * @return
61          */
62         public EnumInfoBuilder setName(String name) {
63             this.name = name;
64             return this;
65         }
66
67         /**
68          * Add a name/value pair to the enum, where
69          * value is an Integer object
70          *
71          * @param name
72          * @param value
73          * @return
74          */
75         public EnumInfoBuilder setEnumValue(String name, BigInteger value) {
76             this.enumValuesByString.put(name, value);
77             this.enumValuesByInt.put(value, name);
78             return this;
79         }
80
81         public EnumInfo build() {
82             return new EnumInfoImpl(this);
83         }
84
85         public static class EnumInfoImpl implements EnumInfo {
86
87             private final String name;
88             private final Map<String, BigInteger> enumValuesByString;
89             private final Map<BigInteger, String> enumValuesByInt;
90
91             public EnumInfoImpl(EnumInfoBuilder builder) {
92                 this.name = builder.name;
93                 this.enumValuesByString = builder.enumValuesByString;
94                 this.enumValuesByInt = builder.enumValuesByInt;
95             }
96
97             @Override
98             public String getName() {
99                 return this.name;
100             }
101
102             @Override
103             public BigInteger getEnumValue(String name) {
104                 return this.enumValuesByString.get(name);
105             }
106
107             @Override
108             public String getEnumValue(BigInteger value) {
109                 return this.enumValuesByInt.get(value);
110             }
111         }
112     }
113 }