1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.util.byteaccess;
21
22
23
24
25
26
27
28
29 abstract class AbstractByteArray implements ByteArray {
30
31
32
33 @Override
34 public final int length() {
35 return last() - first();
36 }
37
38
39
40
41
42 @Override
43 public abstract int hashCode();
44
45
46
47
48 @Override
49 public final boolean equals(Object other) {
50
51 if (other == this) {
52 return true;
53 }
54
55
56 if (!(other instanceof ByteArray)) {
57 return false;
58 }
59
60 ByteArray/../org/apache/mina/util/byteaccess/ByteArray.html#ByteArray">ByteArray otherByteArray = (ByteArray) other;
61
62
63 if (first() != otherByteArray.first() || last() != otherByteArray.last()
64 || !order().equals(otherByteArray.order())) {
65 return false;
66 }
67
68
69 Cursor cursor = cursor();
70 Cursor otherCursor = otherByteArray.cursor();
71
72 for (int remaining = cursor.getRemaining(); remaining > 0;) {
73
74 if (remaining >= 4) {
75 int i = cursor.getInt();
76 int otherI = otherCursor.getInt();
77
78 if (i != otherI) {
79 return false;
80 }
81 } else {
82 byte b = cursor.get();
83 byte otherB = otherCursor.get();
84
85 if (b != otherB) {
86 return false;
87 }
88 }
89 }
90
91 return true;
92 }
93 }