Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / concepts / UnnumberedInterfaceIdentifier.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 package org.opendaylight.protocol.pcep.concepts;
9
10 import org.opendaylight.protocol.concepts.Identifier;
11
12 /**
13  * A 32-bit (unsigned) identifying an interface within a router. This identifier
14  * is explicitly local to the router, e.g. each router has its own namespace.
15  */
16 public final class UnnumberedInterfaceIdentifier implements Comparable<UnnumberedInterfaceIdentifier>, Identifier {
17
18         private static final long serialVersionUID = -8488014237579913120L;
19
20         private final long interfaceId;
21
22         /**
23          * Creates an instance of UnnumberedInterfaceIdentifier from long number.
24          * 
25          * @param interfaceId
26          *            long the value of the UnnumberedInterfaceIdentifier
27          */
28         public UnnumberedInterfaceIdentifier(final long interfaceId) {
29                 if (interfaceId < 0 || interfaceId > 4294967295L)
30                         throw new IllegalArgumentException("Invalid link identifier");
31                 this.interfaceId = interfaceId;
32         }
33
34         /**
35          * Getter for Interface Id represented as long.
36          * 
37          * @return long representation of Interface Id. From 0 to 4294967295.
38          */
39         public long getInterfaceId() {
40                 return this.interfaceId;
41         }
42
43         @Override
44         public int compareTo(final UnnumberedInterfaceIdentifier o) {
45                 if (this.interfaceId < o.getInterfaceId())
46                         return -1;
47                 if (this.interfaceId > o.getInterfaceId())
48                         return 1;
49                 return 0;
50         }
51
52         @Override
53         public int hashCode() {
54                 final int prime = 31;
55                 int result = 1;
56                 result = prime * result + (int) (this.interfaceId ^ (this.interfaceId >>> 32));
57                 return result;
58         }
59
60         @Override
61         public boolean equals(Object obj) {
62                 if (this == obj)
63                         return true;
64                 if (obj == null)
65                         return false;
66                 if (this.getClass() != obj.getClass())
67                         return false;
68                 final UnnumberedInterfaceIdentifier other = (UnnumberedInterfaceIdentifier) obj;
69                 if (this.interfaceId != other.interfaceId)
70                         return false;
71                 return true;
72         }
73
74         @Override
75         public String toString() {
76                 final StringBuilder builder = new StringBuilder();
77                 builder.append("UnnumberedInterfaceIdentifier [interfaceId=");
78                 builder.append(this.interfaceId);
79                 builder.append("]");
80                 return builder.toString();
81         }
82 }