blob: d36ee7cc6ff70485ddaf65e912098572218a3714 [file] [log] [blame]
Toshio Koideb8cea262014-08-12 18:45:46 -07001package net.onrc.onos.api.flowmanager;
2
Toshio Koideb86338e2014-08-21 19:29:43 -07003import java.util.Objects;
4
Toshio Koidea7827bb2014-08-29 11:36:06 -07005import javax.annotation.concurrent.Immutable;
6
Toshio Koideb8cea262014-08-12 18:45:46 -07007/**
8 * Represents ID for {@link FlowBatchOperation}.
Toshio Koidea7827bb2014-08-29 11:36:06 -07009 * <p>
10 * This class is immutable.
Toshio Koideb8cea262014-08-12 18:45:46 -070011 */
Toshio Koidea7827bb2014-08-29 11:36:06 -070012@Immutable
13public final class FlowBatchId {
Pavlin Radoslavov165ff472014-09-02 12:58:41 -070014 private static final int DEC = 10;
15 private static final int HEX = 16;
16
Toshio Koideb86338e2014-08-21 19:29:43 -070017 private final long id;
18
19 /**
Pavlin Radoslavov165ff472014-09-02 12:58:41 -070020 * 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 Koideb86338e2014-08-21 19:29:43 -070034 * 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 Koidea7827bb2014-08-29 11:36:06 -070042 return "0x" + Long.toHexString(id);
Toshio Koideb86338e2014-08-21 19:29:43 -070043 }
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 Koideb8cea262014-08-12 18:45:46 -070054}