blob: ad86d295157539ef5cd0870007f6257589c00ef1 [file] [log] [blame]
Rob Vaterlausfeee3712013-09-30 11:24:19 -07001package org.projectfloodlight.openflow.types;
2
3import org.projectfloodlight.openflow.util.HexString;
4
Andreas Wundsam72977ce2013-10-15 21:31:59 -07005import com.google.common.primitives.UnsignedLongs;
6
Rob Vaterlausfeee3712013-09-30 11:24:19 -07007/**
8 * Abstraction of a datapath ID that can be set and/or accessed as either a
9 * long value or a colon-separated string.
Andreas Wundsam72977ce2013-10-15 21:31:59 -070010 *
Rob Vaterlausfeee3712013-09-30 11:24:19 -070011 * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com>
12 */
Andreas Wundsam72977ce2013-10-15 21:31:59 -070013public class DatapathId implements Comparable<DatapathId> {
Rob Vaterlausfeee3712013-09-30 11:24:19 -070014
15 public static final DatapathId NONE = new DatapathId(0);
16
17 private final long rawValue;
18
19 private DatapathId(long rawValue) {
20 this.rawValue = rawValue;
21 }
22
23 public static DatapathId of(long rawValue) {
24 return new DatapathId(rawValue);
25 }
26
27 public static DatapathId of(String s) {
28 return new DatapathId(HexString.toLong(s));
29 }
30
31 public long getLong() {
32 return rawValue;
33 }
34
35 public U64 getUnsignedLong() {
36 return U64.of(rawValue);
37 }
38
39 @Override
40 public String toString() {
41 return HexString.toHexString(rawValue);
42 }
43
44 @Override
45 public int hashCode() {
46 final int prime = 31;
47 int result = 1;
48 result = prime * result + (int) (rawValue ^ (rawValue >>> 32));
49 return result;
50 }
51
52 @Override
53 public boolean equals(Object obj) {
54 if (this == obj)
55 return true;
56 if (obj == null)
57 return false;
58 if (getClass() != obj.getClass())
59 return false;
60 DatapathId other = (DatapathId) obj;
61 if (rawValue != other.rawValue)
62 return false;
63 return true;
64 }
Andreas Wundsam72977ce2013-10-15 21:31:59 -070065
66 @Override
67 public int compareTo(DatapathId o) {
68 return UnsignedLongs.compare(rawValue, o.rawValue);
69 }
Rob Vaterlausfeee3712013-09-30 11:24:19 -070070}