Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPObjectIdentifier.java
1 /*
2  * Copyright (c) 2013 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.protocol.pcep.impl;
10
11 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
12 import org.opendaylight.protocol.pcep.PCEPErrors;
13
14 /**
15  * PCEP objects are identified with a couple <class, type>.
16  */
17 public class PCEPObjectIdentifier {
18         /**
19          * Class identifier for {@link org.opendaylight.protocol.pcep.PCEPObject PCEPObject}
20          */
21         public static enum ObjectClass {
22                 OPEN(1),
23                 RP(2),
24                 NO_PATH(3),
25                 END_POINTS(4),
26                 BANDWIDTH(5),
27                 METRIC(6),
28                 ERO(7),
29                 RRO(8),
30                 LSPA(9),
31                 IRO(10),
32                 SVEC(11),
33                 NOTIFICATION(12),
34                 ERROR(13),
35                 LOAD_BALANCING(14),
36                 CLOSE(15),
37                 XRO(17),
38                 OBJCETIVE_FUNCTION(21),
39                 GLOBAL_CONSTRAINTS(24),
40                 UNREACHED_DESTINATION(28),
41                 SERO(29),
42                 SRRO(30),
43                 BRANCH_NODE(31),
44                 LSP(32);
45
46                 private final int identifier;
47
48                 ObjectClass(final int identifier) {
49                         this.identifier = identifier;
50                 }
51
52                 public int getIdentifier() {
53                         return this.identifier;
54                 }
55
56                 public static ObjectClass getFromInt(int identifier) throws PCEPDocumentedException {
57                         for (final ObjectClass type_e : ObjectClass.values()) {
58                                 if (type_e.getIdentifier() == identifier)
59                                         return type_e;
60                         }
61
62                         throw new PCEPDocumentedException("Unrecognized object class " + identifier, PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
63                 }
64         }
65
66         private final int objectType;
67
68         private final ObjectClass objectClass;
69
70         public PCEPObjectIdentifier(ObjectClass objectClass, int objectType) {
71                 this.objectType = objectType;
72                 this.objectClass = objectClass;
73         }
74
75         public int getObjectType() {
76                 return this.objectType;
77         }
78
79         public ObjectClass getObjectClass() {
80                 return this.objectClass;
81         }
82
83         @Override
84         public int hashCode() {
85                 final int prime = 31;
86                 int result = 1;
87                 result = prime * result + ((this.objectClass == null) ? 0 : this.objectClass.hashCode());
88                 result = prime * result + this.objectType;
89                 return result;
90         }
91
92         @Override
93         public boolean equals(Object obj) {
94                 if (this == obj)
95                         return true;
96                 if (obj == null)
97                         return false;
98                 if (this.getClass() != obj.getClass())
99                         return false;
100                 final PCEPObjectIdentifier other = (PCEPObjectIdentifier) obj;
101                 if (this.objectClass != other.objectClass)
102                         return false;
103                 if (this.objectType != other.objectType)
104                         return false;
105                 return true;
106         }
107 }