blob: 29efe4cb5f5e1896a94b1684915a6e7d3b5e8e26 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavov8e5bab22013-04-02 04:19:41 +00003import java.math.BigInteger;
4
HIGUCHI Yutaf086d8a2013-06-12 15:26:35 -07005import net.onrc.onos.ofcontroller.util.serializers.FlowEntryIdDeserializer;
6import net.onrc.onos.ofcontroller.util.serializers.FlowEntryIdSerializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08008import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08009import org.codehaus.jackson.map.annotate.JsonSerialize;
10
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080011/**
12 * The class representing a Flow Entry ID.
13 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080014@JsonDeserialize(using=FlowEntryIdDeserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080015@JsonSerialize(using=FlowEntryIdSerializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080016public class FlowEntryId {
17 private long value;
18
19 /**
20 * Default constructor.
21 */
22 public FlowEntryId() {
23 this.value = 0;
24 }
25
26 /**
27 * Constructor from an integer value.
28 *
29 * @param value the value to use.
30 */
31 public FlowEntryId(long value) {
32 this.value = value;
33 }
34
35 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080036 * Constructor from a string.
37 *
38 * @param value the value to use.
39 */
40 public FlowEntryId(String value) {
Pavlin Radoslavov8e5bab22013-04-02 04:19:41 +000041 //
42 // Use the help of BigInteger to parse strings representing
43 // large unsigned hex long values.
44 //
45 char c = 0;
46 if (value.length() > 2)
47 c = value.charAt(1);
48 if ((c == 'x') || (c == 'X'))
49 this.value = new BigInteger(value.substring(2), 16).longValue();
50 else
51 this.value = Long.decode(value);
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080052 }
53
54 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080055 * Get the value of the Flow Entry ID.
56 *
57 * @return the value of the Flow Entry ID.
58 */
59 public long value() { return value; }
60
61 /**
62 * Set the value of the Flow Entry ID.
63 *
64 * @param value the value to set.
65 */
66 public void setValue(long value) {
67 this.value = value;
68 }
Brian O'Connora8e49802013-10-30 20:49:59 -070069
70 /**
71 * Returns true of the object is another Flow Entry ID with
72 * the same value; otherwise, returns false.
73 *
74 * @param Object to compare
75 */
76 @Override
77 public boolean equals(Object obj){
78 if(obj.getClass() == this.getClass()) {
79 FlowEntryId entry = (FlowEntryId) obj;
80 return this.value() == entry.value();
81 }
82 return false;
83 }
84
85 /**
86 * Return the hash code of the Flow Entry ID
87 */
88 @Override
89 public int hashCode() {
90 return Long.valueOf(value).hashCode();
91 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080092
93 /**
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080094 * Convert the Flow Entry ID value to a hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080095 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080096 * @return the Flow Entry ID value to a hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080097 */
98 @Override
99 public String toString() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800100 return "0x" + Long.toHexString(this.value);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800101 }
102}