2 * Copyright (c) 2013 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.protocol.pcep.impl.subobject;
10 import java.util.EnumMap;
11 import java.util.HashMap;
13 import java.util.NoSuchElementException;
15 import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute;
18 * Bidirectional mapping for XROSubobjectAttribute and appropriate identifier.
20 public class XROSubobjectAttributeMapping {
21 private static final XROSubobjectAttributeMapping instance = new XROSubobjectAttributeMapping();
23 private final Map<XROSubobjectAttribute, Integer> ofCodesMap = new EnumMap<XROSubobjectAttribute, Integer>(XROSubobjectAttribute.class);
24 private final Map<Integer, XROSubobjectAttribute> ofCodeIdsMap = new HashMap<Integer, XROSubobjectAttribute>();
26 private XROSubobjectAttributeMapping() {
30 private void fillIn() {
31 this.fillIn(0, XROSubobjectAttribute.INTERFACE);
32 this.fillIn(1, XROSubobjectAttribute.NODE);
33 this.fillIn(2, XROSubobjectAttribute.SRLG);
36 private void fillIn(int identifier, XROSubobjectAttribute ofCode) {
37 this.ofCodesMap.put(ofCode, identifier);
38 this.ofCodeIdsMap.put(identifier, ofCode);
41 public int getFromAttributeEnum(XROSubobjectAttribute ofCode) {
42 final Integer ofci = this.ofCodesMap.get(ofCode);
44 throw new NoSuchElementException("Unknown XROSubobjectAttribute type: " + ofCode);
48 public XROSubobjectAttribute getFromAttributeIdentifier(int identifier) {
49 final XROSubobjectAttribute ofc = this.ofCodeIdsMap.get(identifier);
51 throw new NoSuchElementException("Unknown XROSubobjectAttribute identifier.");
55 public static XROSubobjectAttributeMapping getInstance() {