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