Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.intent; |
| 2 | |
| 3 | import net.onrc.onos.api.batchoperation.BatchOperationTargetId; |
| 4 | |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 5 | /** |
| 6 | * The class representing intent's ID. |
| 7 | * |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame^] | 8 | * <p> |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 9 | * This class is immutable. |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame^] | 10 | * </p> |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 11 | */ |
| 12 | public final class IntentId extends BatchOperationTargetId { |
| 13 | private final long id; |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 14 | |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 15 | /** |
| 16 | * Constructs the ID corresponding to a given long value. |
| 17 | * |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame^] | 18 | * <p> |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 19 | * In the future, this constructor will not be exposed to avoid misuses. |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame^] | 20 | * </p> |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 21 | * |
| 22 | * @param id the underlay value of this ID. |
| 23 | */ |
| 24 | public IntentId(long id) { |
| 25 | this.id = id; |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public int hashCode() { |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 30 | return (int) (id ^ (id >>> 32)); |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public boolean equals(Object obj) { |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 35 | if (obj == this) { |
| 36 | return true; |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 37 | } |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 38 | |
| 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 Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 50 | } |
| 51 | } |