blob: 5de5a12886fd2b738951b410fc862f32816e27ea [file] [log] [blame]
Toshio Koide025a9152014-07-21 11:00:34 -07001package net.onrc.onos.api.intent;
2
Toshio Koidefad1cd52014-08-07 17:10:07 -07003import net.onrc.onos.api.batchoperation.BatchOperationTarget;
Toshio Koide025a9152014-07-21 11:00:34 -07004
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -07005/**
6 * The class representing intent's ID.
7 *
Sho SHIMIZU9beddc02014-08-04 11:32:11 -07008 * <p>
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -07009 * This class is immutable.
Sho SHIMIZU9beddc02014-08-04 11:32:11 -070010 * </p>
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070011 */
Toshio Koidefad1cd52014-08-07 17:10:07 -070012public final class IntentId implements BatchOperationTarget {
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070013 private final long id;
Toshio Koide025a9152014-07-21 11:00:34 -070014
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070015 /**
16 * Constructs the ID corresponding to a given long value.
17 *
Sho SHIMIZU9beddc02014-08-04 11:32:11 -070018 * <p>
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070019 * In the future, this constructor will not be exposed to avoid misuses.
Sho SHIMIZU9beddc02014-08-04 11:32:11 -070020 * </p>
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070021 *
22 * @param id the underlay value of this ID.
23 */
24 public IntentId(long id) {
25 this.id = id;
Toshio Koide025a9152014-07-21 11:00:34 -070026 }
27
28 @Override
29 public int hashCode() {
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070030 return (int) (id ^ (id >>> 32));
Toshio Koide025a9152014-07-21 11:00:34 -070031 }
32
33 @Override
34 public boolean equals(Object obj) {
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070035 if (obj == this) {
36 return true;
Toshio Koide025a9152014-07-21 11:00:34 -070037 }
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070038
39 if (!(obj instanceof IntentId)) {
40 return false;
41 }
42
43 IntentId that = (IntentId) obj;
44 return this.id == that.id;
45 }
46
47 @Override
48 public String toString() {
49 return "0x" + Long.toHexString(id);
Toshio Koide025a9152014-07-21 11:00:34 -070050 }
51}