Toshio Koide | b8cea26 | 2014-08-12 18:45:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.flowmanager; |
| 2 | |
Toshio Koide | b86338e | 2014-08-21 19:29:43 -0700 | [diff] [blame] | 3 | import java.util.Objects; |
| 4 | |
Toshio Koide | a7827bb | 2014-08-29 11:36:06 -0700 | [diff] [blame] | 5 | import javax.annotation.concurrent.Immutable; |
| 6 | |
Toshio Koide | b8cea26 | 2014-08-12 18:45:46 -0700 | [diff] [blame] | 7 | /** |
| 8 | * Represents ID for {@link FlowBatchOperation}. |
Toshio Koide | a7827bb | 2014-08-29 11:36:06 -0700 | [diff] [blame] | 9 | * <p> |
| 10 | * This class is immutable. |
Toshio Koide | b8cea26 | 2014-08-12 18:45:46 -0700 | [diff] [blame] | 11 | */ |
Toshio Koide | a7827bb | 2014-08-29 11:36:06 -0700 | [diff] [blame] | 12 | @Immutable |
| 13 | public final class FlowBatchId { |
Pavlin Radoslavov | 165ff47 | 2014-09-02 12:58:41 -0700 | [diff] [blame] | 14 | private static final int DEC = 10; |
| 15 | private static final int HEX = 16; |
| 16 | |
Toshio Koide | b86338e | 2014-08-21 19:29:43 -0700 | [diff] [blame] | 17 | private final long id; |
| 18 | |
| 19 | /** |
Pavlin Radoslavov | 165ff47 | 2014-09-02 12:58:41 -0700 | [diff] [blame] | 20 | * Creates a flow batch identifier from the specified string |
| 21 | * representation. |
| 22 | * |
| 23 | * @param value long value |
| 24 | * @return flow batch identifier |
| 25 | */ |
| 26 | public static FlowBatchId valueOf(String value) { |
| 27 | long id = value.toLowerCase().startsWith("0x") |
| 28 | ? Long.parseLong(value.substring(2), HEX) |
| 29 | : Long.parseLong(value, DEC); |
| 30 | return new FlowBatchId(id); |
| 31 | } |
| 32 | |
| 33 | /** |
Toshio Koide | b86338e | 2014-08-21 19:29:43 -0700 | [diff] [blame] | 34 | * Creates a new FlowBatchId object using long value. |
| 35 | */ |
| 36 | public FlowBatchId(long id) { |
| 37 | this.id = id; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public String toString() { |
Toshio Koide | a7827bb | 2014-08-29 11:36:06 -0700 | [diff] [blame] | 42 | return "0x" + Long.toHexString(id); |
Toshio Koide | b86338e | 2014-08-21 19:29:43 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public int hashCode() { |
| 47 | return Objects.hashCode(id); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public boolean equals(Object obj) { |
| 52 | return (obj instanceof FlowBatchId) ? id == ((FlowBatchId) obj).id : false; |
| 53 | } |
Toshio Koide | b8cea26 | 2014-08-12 18:45:46 -0700 | [diff] [blame] | 54 | } |