Five more Equals/HashCode/StringBuilder replacements
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / vendorextension / v6extension / V6Error.java
1 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
2
3 import java.nio.ByteBuffer;
4 import java.util.Arrays;
5
6 import org.openflow.protocol.OFError;
7
8 public class V6Error extends OFError {
9         private static final long serialVersionUID = 1L;
10         public static int MINIMUM_LENGTH = 20;//OfHdr(8) + NXET_VENDOR(2) + NXEC_VENDOR_ERROR(2) + struct nx_vendor_error(8)
11         public static final short NICIRA_VENDOR_ERRORTYPE = (short)0xb0c2;
12         protected int V6VendorId;
13     protected short V6VendorErrorType;
14     protected short V6VendorErrorCode;
15     protected byte[] V6ErrorData;
16     
17     public V6Error(OFError e) {
18         this.length = (short)e.getLengthU();
19         this.errorType = e.getErrorType();
20         this.errorCode = e.getErrorCode();
21         this.xid = e.getXid();
22     }
23     
24     @Override
25     public void readFrom(ByteBuffer data) {
26         this.V6VendorId = data.getInt();
27         this.V6VendorErrorType = data.getShort();
28         this.V6VendorErrorCode = data.getShort();
29         int dataLength = this.getLengthU() - MINIMUM_LENGTH;
30         if (dataLength > 0) {
31             this.V6ErrorData = new byte[dataLength];
32             data.get(this.V6ErrorData);
33         }   
34     }
35     
36     /**
37      * @return the V6VendorId
38      */
39     public int getVendorId() {
40         return V6VendorId;
41     }
42     
43     /**
44      * @return the V6VendorErrorType
45      */
46     public short getVendorErrorType() {
47         return V6VendorErrorType;
48     }
49     
50     /**
51      * @return the VendorErrorType
52      */
53     public short getVendorErrorCode() {
54         return V6VendorErrorCode;
55     }
56     
57     /**
58      * @return the Error Bytes
59      */
60     public byte[] getError() {
61         return V6ErrorData;
62     }
63     
64     @Override
65     public int hashCode() {
66         final int prime = 31;
67         int result = super.hashCode();
68         result = prime * result + Arrays.hashCode(V6ErrorData);
69         result = prime * result + V6VendorErrorCode;
70         result = prime * result + V6VendorErrorType;
71         result = prime * result + V6VendorId;
72         return result;
73     }
74
75     @Override
76     public String toString() {
77         return "V6Error [V6VendorId=" + V6VendorId + ", V6VendorErrorType="
78                 + V6VendorErrorType + ", V6VendorErrorCode="
79                 + V6VendorErrorCode + ", V6ErrorData="
80                 + Arrays.toString(V6ErrorData) + ", errorType=" + errorType
81                 + ", errorCode=" + errorCode + ", factory=" + factory
82                 + ", error=" + Arrays.toString(error) + ", errorIsAscii="
83                 + errorIsAscii + ", version=" + version + ", type=" + type
84                 + ", length=" + length + ", xid=" + xid + "]";
85     }
86
87     @Override
88     public boolean equals(Object obj) {
89         if (this == obj)
90             return true;
91         if (!super.equals(obj))
92             return false;
93         if (getClass() != obj.getClass())
94             return false;
95         V6Error other = (V6Error) obj;
96         if (!Arrays.equals(V6ErrorData, other.V6ErrorData))
97             return false;
98         if (V6VendorErrorCode != other.V6VendorErrorCode)
99             return false;
100         if (V6VendorErrorType != other.V6VendorErrorType)
101             return false;
102         if (V6VendorId != other.V6VendorId)
103             return false;
104         return true;
105     }
106 }