Added range type to subject-feature-definition/parameter
[groupbasedpolicy.git] / groupbasedpolicy / 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  */
22 public interface EnumInfo {
23
24         /**
25          * Get the name of the enum as it appears in the MIT's
26          * PropertyInfo map.
27          *
28          * @return
29          */
30         public String getName();
31
32         /**
33          * Get the Integer representation of the value by name
34          * for the enum
35          *
36          * @param name
37          * @return
38          */
39         public BigInteger getEnumValue(String name);
40
41         public String getEnumValue(BigInteger value);
42
43         /**
44          * Class for building immutable EnumInfo objects
45          *
46          * @author tbachman
47          *
48          */
49         public static class EnumInfoBuilder {
50                 private String name;
51                 private Map<String, BigInteger> enumValuesByString;
52                 private Map<BigInteger, String> enumValuesByInt;
53
54                 public EnumInfoBuilder() {
55                         this.enumValuesByString = new HashMap<String, BigInteger>();
56                         this.enumValuesByInt = new HashMap<BigInteger, String>();
57                 }
58
59                 /**
60                  * Set the name of the EnumInfo object
61                  *
62                  * @param name
63                  * @return
64                  */
65                 public EnumInfoBuilder setName(String name) {
66                         this.name = name;
67                         return this;
68                 }
69
70                 /**
71                  * Add a name/value pair to the enum, where
72                  * value is an Integer object
73                  *
74                  * @param name
75                  * @param value
76                  * @return
77                  */
78                 public EnumInfoBuilder setEnumValue(String name, BigInteger value) {
79                         this.enumValuesByString.put(name, value);
80                         this.enumValuesByInt.put(value, name);
81                         return this;
82                 }
83
84                 public EnumInfo build() {
85                         return new EnumInfoImpl(this);
86                 }
87
88                 public static class EnumInfoImpl implements EnumInfo {
89                         private final String name;
90                         private final Map<String, BigInteger> enumValuesByString;
91                         private final Map<BigInteger, String> enumValuesByInt;
92
93                         public EnumInfoImpl(EnumInfoBuilder builder) {
94                                 this.name = builder.name;
95                                 this.enumValuesByString = builder.enumValuesByString;
96                                 this.enumValuesByInt = builder.enumValuesByInt;
97                         }
98
99                         @Override
100                         public String getName() {
101                                 return this.name;
102                         }
103
104                         @Override
105                         public BigInteger getEnumValue(String name) {
106                                 return this.enumValuesByString.get(name);
107                         }
108
109                         @Override
110                         public String getEnumValue(BigInteger value) {
111                                 return this.enumValuesByInt.get(value);
112                         }
113                 }
114         }
115 }