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;
10 import java.util.EnumMap;
11 import java.util.HashMap;
13 import java.util.NoSuchElementException;
15 import org.opendaylight.protocol.pcep.PCEPOFCodes;
18 * Mapping of enumerable objective function codes to integral identifiers and
21 public class PCEPOFCodesMapping {
22 private static final PCEPOFCodesMapping instance = new PCEPOFCodesMapping();
24 private final Map<PCEPOFCodes, Integer> ofCodesMap = new EnumMap<PCEPOFCodes, Integer>(PCEPOFCodes.class);
25 private final Map<Integer, PCEPOFCodes> ofCodeIdsMap = new HashMap<Integer, PCEPOFCodes>();
27 private PCEPOFCodesMapping() {
31 private void fillIn() {
32 this.fillIn(1, PCEPOFCodes.MCP);
33 this.fillIn(2, PCEPOFCodes.MLP);
34 this.fillIn(3, PCEPOFCodes.MBP);
35 this.fillIn(4, PCEPOFCodes.MBC);
36 this.fillIn(5, PCEPOFCodes.MLL);
37 this.fillIn(6, PCEPOFCodes.MCC);
38 this.fillIn(7, PCEPOFCodes.SPT);
39 this.fillIn(8, PCEPOFCodes.MCT);
42 private void fillIn(int identifier, PCEPOFCodes ofCode) {
43 this.ofCodesMap.put(ofCode, identifier);
44 this.ofCodeIdsMap.put(identifier, ofCode);
47 public int getFromOFCodesEnum(PCEPOFCodes ofCode) {
48 final Integer ofci = this.ofCodesMap.get(ofCode);
50 throw new NoSuchElementException("Unknown PCEPOFCodes type: " + ofCode);
54 public PCEPOFCodes getFromCodeIdentifier(int identifier) {
55 final PCEPOFCodes ofc = this.ofCodeIdsMap.get(identifier);
57 throw new NoSuchElementException("Unknown PCEPOFCode identifier.");
61 public static PCEPOFCodesMapping getInstance() {