blob: 08ab7fa1d698f074bdc0166c5fdfa1767dcb3b33 [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
2
3/**
4 * Intent identifier suitable as an external key.
toma1d16b62014-10-02 23:45:11 -07005 * <p/>
Brian O'Connorb876bf12014-10-02 14:59:37 -07006 * This class is immutable.
7 */
8public final class IntentId implements BatchOperationTarget {
9
Thomas Vachuskac96058a2014-10-20 23:00:16 -070010 private final long fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070011
12 /**
13 * Creates an intent identifier from the specified string representation.
14 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070015 * @param fingerprint long value
Brian O'Connorb876bf12014-10-02 14:59:37 -070016 * @return intent identifier
17 */
Thomas Vachuskab97cf282014-10-20 23:31:12 -070018 public static IntentId valueOf(long fingerprint) {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070019 return new IntentId(fingerprint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070020 }
21
22 /**
23 * Constructor for serializer.
24 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070025 IntentId() {
26 this.fingerprint = 0;
Brian O'Connorb876bf12014-10-02 14:59:37 -070027 }
28
29 /**
30 * Constructs the ID corresponding to a given long value.
31 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070032 * @param fingerprint the underlying value of this ID
Brian O'Connorb876bf12014-10-02 14:59:37 -070033 */
Thomas Vachuskac96058a2014-10-20 23:00:16 -070034 IntentId(long fingerprint) {
35 this.fingerprint = fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070036 }
37
38 @Override
39 public int hashCode() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070040 return (int) (fingerprint ^ (fingerprint >>> 32));
Brian O'Connorb876bf12014-10-02 14:59:37 -070041 }
42
43 @Override
44 public boolean equals(Object obj) {
45 if (obj == this) {
46 return true;
47 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070048 if (!(obj instanceof IntentId)) {
49 return false;
50 }
Brian O'Connorb876bf12014-10-02 14:59:37 -070051 IntentId that = (IntentId) obj;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070052 return this.fingerprint == that.fingerprint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070053 }
54
55 @Override
56 public String toString() {
Thomas Vachuskac96058a2014-10-20 23:00:16 -070057 return "0x" + Long.toHexString(fingerprint);
Brian O'Connorb876bf12014-10-02 14:59:37 -070058 }
59
60}