blob: 6d10b35e99d44d4aabf666e972174ae298122869 [file] [log] [blame]
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -07001package net.onrc.onos.api.newintent;
2
3/**
4 * Intent identifier suitable as an external key.
5 *
6 * This class is immutable.
7 */
8public final class IntentId {
9
10 private static final int DEC = 10;
11 private static final int HEX = 16;
12
13 private final long id;
14
15 /**
16 * Creates an intent identifier from the specified string representation.
17 *
18 * @param value long value
19 * @return intent identifier
20 */
21 public static IntentId valueOf(String value) {
22 long id = value.startsWith("0x")
23 ? Long.parseLong(value.substring(2), HEX)
24 : Long.parseLong(value, DEC);
25 return new IntentId(id);
26 }
27
28
29 /**
30 * Constructs the ID corresponding to a given long value.
31 *
32 * @param id the underlying value of this ID
33 */
34 public IntentId(long id) {
35 this.id = id;
36 }
37
38 @Override
39 public int hashCode() {
40 return (int) (id ^ (id >>> 32));
41 }
42
43 @Override
44 public boolean equals(Object obj) {
45 if (obj == this) {
46 return true;
47 }
48
49 if (!(obj instanceof IntentId)) {
50 return false;
51 }
52
53 IntentId that = (IntentId) obj;
54 return this.id == that.id;
55 }
56
57 @Override
58 public String toString() {
59 return "0x" + Long.toHexString(id);
60 }
61
62}