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
21 public interface EnumInfo {
24 * Get the name of the enum as it appears in the MIT's
29 public String getName();
32 * Get the Integer representation of the value by name
38 public BigInteger getEnumValue(String name);
40 public String getEnumValue(BigInteger value);
43 * Class for building immutable EnumInfo objects
47 public static class EnumInfoBuilder {
50 private final Map<String, BigInteger> enumValuesByString = new HashMap<>();
51 private final Map<BigInteger, String> enumValuesByInt = new HashMap<>();
53 public EnumInfoBuilder() {
57 * Set the name of the EnumInfo object
62 public EnumInfoBuilder setName(String name) {
68 * Add a name/value pair to the enum, where
69 * value is an Integer object
75 public EnumInfoBuilder setEnumValue(String name, BigInteger value) {
76 this.enumValuesByString.put(name, value);
77 this.enumValuesByInt.put(value, name);
81 public EnumInfo build() {
82 return new EnumInfoImpl(this);
85 public static class EnumInfoImpl implements EnumInfo {
87 private final String name;
88 private final Map<String, BigInteger> enumValuesByString;
89 private final Map<BigInteger, String> enumValuesByInt;
91 public EnumInfoImpl(EnumInfoBuilder builder) {
92 this.name = builder.name;
93 this.enumValuesByString = builder.enumValuesByString;
94 this.enumValuesByInt = builder.enumValuesByInt;
98 public String getName() {
103 public BigInteger getEnumValue(String name) {
104 return this.enumValuesByString.get(name);
108 public String getEnumValue(BigInteger value) {
109 return this.enumValuesByInt.get(value);