blob: c72d7cbb1b95227938752a30c2b41e211c65a49e [file] [log] [blame]
Toshio Koide025a9152014-07-21 11:00:34 -07001package net.onrc.onos.api.flowmanager;
2
Toshio Koide515ba842014-08-20 11:53:37 -07003import java.util.Objects;
4
Toshio Koide778c4d62014-08-29 11:18:31 -07005import javax.annotation.concurrent.Immutable;
6
Toshio Koidefad1cd52014-08-07 17:10:07 -07007import net.onrc.onos.api.batchoperation.BatchOperationTarget;
Toshio Koide025a9152014-07-21 11:00:34 -07008
9/**
Toshio Koide7894ca02014-08-15 14:30:13 -070010 * Represents ID for Flow objects.
Toshio Koide778c4d62014-08-29 11:18:31 -070011 * <p>
12 * This class is immutable.
Toshio Koide025a9152014-07-21 11:00:34 -070013 */
Toshio Koide778c4d62014-08-29 11:18:31 -070014@Immutable
15public final class FlowId implements BatchOperationTarget {
Pavlin Radoslavov165ff472014-09-02 12:58:41 -070016 private static final int DEC = 10;
17 private static final int HEX = 16;
18
Toshio Koide778c4d62014-08-29 11:18:31 -070019 private final long id;
Toshio Koide025a9152014-07-21 11:00:34 -070020
21 /**
Pavlin Radoslavov165ff472014-09-02 12:58:41 -070022 * Creates a flow identifier from the specified string representation.
23 *
24 * @param value long value
25 * @return flow identifier
26 */
27 public static FlowId valueOf(String value) {
28 long id = value.toLowerCase().startsWith("0x")
29 ? Long.parseLong(value.substring(2), HEX)
30 : Long.parseLong(value, DEC);
31 return new FlowId(id);
32 }
33
34 /**
Toshio Koide2c67a2d2014-08-27 11:30:56 -070035 * Default constructor for Kryo deserialization.
36 */
37 @Deprecated
38 protected FlowId() {
Toshio Koide778c4d62014-08-29 11:18:31 -070039 id = 0;
Toshio Koide2c67a2d2014-08-27 11:30:56 -070040 }
41
42 /**
Toshio Koide025a9152014-07-21 11:00:34 -070043 * Creates new instance with string ID.
Toshio Koide515ba842014-08-20 11:53:37 -070044 * <p>
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070045 * This FlowId instance should be generated with
46 * {@link net.onrc.onos.core.util.IdGenerator} of flow ID.
Toshio Koide025a9152014-07-21 11:00:34 -070047 *
48 * @param id String representation of the ID.
49 */
Toshio Koide515ba842014-08-20 11:53:37 -070050 public FlowId(long id) {
Toshio Koide778c4d62014-08-29 11:18:31 -070051 this.id = id;
Toshio Koide025a9152014-07-21 11:00:34 -070052 }
53
54 @Override
55 public String toString() {
Toshio Koide778c4d62014-08-29 11:18:31 -070056 return "0x" + Long.toHexString(id);
Toshio Koide025a9152014-07-21 11:00:34 -070057 }
58
59 @Override
60 public int hashCode() {
Toshio Koide778c4d62014-08-29 11:18:31 -070061 return Objects.hashCode(id);
Toshio Koide025a9152014-07-21 11:00:34 -070062 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (obj instanceof FlowId) {
Toshio Koide515ba842014-08-20 11:53:37 -070067 FlowId that = (FlowId) obj;
Toshio Koide778c4d62014-08-29 11:18:31 -070068 return Objects.equals(this.id, that.id);
Toshio Koide025a9152014-07-21 11:00:34 -070069 }
70 return false;
71 }
72}