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
9 package org.opendaylight.groupbasedpolicy.renderer.opflex.mit;
11 import java.math.BigInteger;
12 import java.util.HashMap;
16 * An object that represents an enum in the MIT's
17 * PropertyInfo object map
22 public interface EnumInfo {
25 * Get the name of the enum as it appears in the MIT's
30 public String getName();
33 * Get the Integer representation of the value by name
39 public BigInteger getEnumValue(String name);
41 public String getEnumValue(BigInteger value);
44 * Class for building immutable EnumInfo objects
49 public static class EnumInfoBuilder {
51 private Map<String, BigInteger> enumValuesByString;
52 private Map<BigInteger, String> enumValuesByInt;
54 public EnumInfoBuilder() {
55 this.enumValuesByString = new HashMap<String, BigInteger>();
56 this.enumValuesByInt = new HashMap<BigInteger, String>();
60 * Set the name of the EnumInfo object
65 public EnumInfoBuilder setName(String name) {
71 * Add a name/value pair to the enum, where
72 * value is an Integer object
78 public EnumInfoBuilder setEnumValue(String name, BigInteger value) {
79 this.enumValuesByString.put(name, value);
80 this.enumValuesByInt.put(value, name);
84 public EnumInfo build() {
85 return new EnumInfoImpl(this);
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;
93 public EnumInfoImpl(EnumInfoBuilder builder) {
94 this.name = builder.name;
95 this.enumValuesByString = builder.enumValuesByString;
96 this.enumValuesByInt = builder.enumValuesByInt;
100 public String getName() {
105 public BigInteger getEnumValue(String name) {
106 return this.enumValuesByString.get(name);
110 public String getEnumValue(BigInteger value) {
111 return this.enumValuesByInt.get(value);