Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import org.projectfloodlight.openflow.util.HexString; |
| 4 | |
| 5 | /** |
| 6 | * Abstraction of a datapath ID that can be set and/or accessed as either a |
| 7 | * long value or a colon-separated string. |
| 8 | * |
| 9 | * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com> |
| 10 | */ |
| 11 | public class DatapathId { |
| 12 | |
| 13 | public static final DatapathId NONE = new DatapathId(0); |
| 14 | |
| 15 | private final long rawValue; |
| 16 | |
| 17 | private DatapathId(long rawValue) { |
| 18 | this.rawValue = rawValue; |
| 19 | } |
| 20 | |
| 21 | public static DatapathId of(long rawValue) { |
| 22 | return new DatapathId(rawValue); |
| 23 | } |
| 24 | |
| 25 | public static DatapathId of(String s) { |
| 26 | return new DatapathId(HexString.toLong(s)); |
| 27 | } |
| 28 | |
| 29 | public long getLong() { |
| 30 | return rawValue; |
| 31 | } |
| 32 | |
| 33 | public U64 getUnsignedLong() { |
| 34 | return U64.of(rawValue); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public String toString() { |
| 39 | return HexString.toHexString(rawValue); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public int hashCode() { |
| 44 | final int prime = 31; |
| 45 | int result = 1; |
| 46 | result = prime * result + (int) (rawValue ^ (rawValue >>> 32)); |
| 47 | return result; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public boolean equals(Object obj) { |
| 52 | if (this == obj) |
| 53 | return true; |
| 54 | if (obj == null) |
| 55 | return false; |
| 56 | if (getClass() != obj.getClass()) |
| 57 | return false; |
| 58 | DatapathId other = (DatapathId) obj; |
| 59 | if (rawValue != other.rawValue) |
| 60 | return false; |
| 61 | return true; |
| 62 | } |
| 63 | } |