Merge "Bug 2347: DOMConcurrentDataCommitCoordinator uses wrong phase name"
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / OFVendor.java
1 package org.openflow.protocol;
2
3 import java.nio.ByteBuffer;
4 import java.util.Arrays;
5
6 import org.openflow.util.U16;
7
8 /**
9  * Represents ofp_vendor_header
10  * @author David Erickson (daviderickson@cs.stanford.edu)
11  */
12 public class OFVendor extends OFMessage {
13     public static int MINIMUM_LENGTH = 12;
14
15     protected int vendor;
16     protected byte[] data;
17
18     public OFVendor() {
19         super();
20         this.type = OFType.VENDOR;
21         this.length = U16.t(MINIMUM_LENGTH);
22     }
23
24     /**
25      * @return the vendor
26      */
27     public int getVendor() {
28         return vendor;
29     }
30
31     /**
32      * @param vendor the vendor to set
33      */
34     public void setVendor(int vendor) {
35         this.vendor = vendor;
36     }
37
38     @Override
39     public void readFrom(ByteBuffer data) {
40         super.readFrom(data);
41         this.vendor = data.getInt();
42         if (this.length > MINIMUM_LENGTH) {
43             this.data = new byte[this.length - MINIMUM_LENGTH];
44             data.get(this.data);
45         }
46     }
47
48     @Override
49     public void writeTo(ByteBuffer data) {
50         super.writeTo(data);
51         data.putInt(this.vendor);
52         if (this.data != null)
53             data.put(this.data);
54     }
55
56     /**
57      * @return the data
58      */
59     public byte[] getData() {
60         return data;
61     }
62
63     /**
64      * @param data the data to set
65      */
66     public void setData(byte[] data) {
67         this.data = data;
68     }
69
70     /* (non-Javadoc)
71      * @see java.lang.Object#hashCode()
72      */
73     @Override
74     public int hashCode() {
75         final int prime = 337;
76         int result = super.hashCode();
77         result = prime * result + Arrays.hashCode(data);
78         result = prime * result + vendor;
79         return result;
80     }
81
82     /* (non-Javadoc)
83      * @see java.lang.Object#equals(java.lang.Object)
84      */
85     @Override
86     public boolean equals(Object obj) {
87         if (this == obj)
88             return true;
89         if (!super.equals(obj))
90             return false;
91         if (getClass() != obj.getClass())
92             return false;
93         OFVendor other = (OFVendor) obj;
94         if (!Arrays.equals(data, other.data))
95             return false;
96         if (vendor != other.vendor)
97             return false;
98         return true;
99     }
100 }