blob: 7f76b4d77fe0e62cd0b2b99c062fb1ed2aba491d [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001package org.projectfloodlight.openflow.types;
2
3import org.projectfloodlight.openflow.annotations.Immutable;
4
5import com.google.common.hash.PrimitiveSink;
6import com.google.common.primitives.UnsignedInts;
7
8/**
9 * Abstraction of a buffer id in OpenFlow. Immutable.
10 *
11 * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com>
12 */
13@Immutable
14public class OFBufferId implements Comparable<OFBufferId>, PrimitiveSinkable {
15 public static final OFBufferId NO_BUFFER = new OFBufferId(0xFFFFFFFF);
16
17 private final int rawValue;
18
19 private OFBufferId(int rawValue) {
20 this.rawValue = rawValue;
21 }
22
23 public static OFBufferId of(final int rawValue) {
24 if (rawValue == NO_BUFFER.getInt())
25 return NO_BUFFER;
26 return new OFBufferId(rawValue);
27 }
28
29 public int getInt() {
30 return rawValue;
31 }
32
33 @Override
34 public String toString() {
35 return Long.toString(U32.f(rawValue));
36 }
37
38 @Override
39 public int hashCode() {
40 final int prime = 31;
41 int result = 1;
42 result = prime * result + rawValue;
43 return result;
44 }
45
46 @Override
47 public boolean equals(Object obj) {
48 if (this == obj)
49 return true;
50 if (obj == null)
51 return false;
52 if (getClass() != obj.getClass())
53 return false;
54 OFBufferId other = (OFBufferId) obj;
55 if (rawValue != other.rawValue)
56 return false;
57 return true;
58 }
59
60 @Override
61 public int compareTo(OFBufferId o) {
62 return UnsignedInts.compare(rawValue, o.rawValue);
63 }
64
65 @Override
66 public void putTo(PrimitiveSink sink) {
67 sink.putInt(rawValue);
68 }
69}