mirror of
https://github.com/corda/corda.git
synced 2025-04-08 20:04:51 +00:00
make ByteBuffer implement Comparable
This commit is contained in:
parent
3570beaba9
commit
a6a1f8ba98
@ -1,6 +1,6 @@
|
||||
package java.nio;
|
||||
|
||||
public class ByteBuffer {
|
||||
public class ByteBuffer implements Comparable<ByteBuffer> {
|
||||
private final byte[] array;
|
||||
private int arrayOffset;
|
||||
private int capacity;
|
||||
@ -25,6 +25,22 @@ public class ByteBuffer {
|
||||
position = 0;
|
||||
}
|
||||
|
||||
public int compareTo(ByteBuffer o) {
|
||||
int end = (remaining() < o.remaining() ? remaining() : o.remaining());
|
||||
|
||||
for (int i = 0; i < end; ++i) {
|
||||
int d = get(position + i) - o.get(o.position + i);
|
||||
if (d != 0) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return remaining() - o.remaining();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof ByteBuffer && compareTo((ByteBuffer) o) == 0;
|
||||
}
|
||||
|
||||
public byte[] array() {
|
||||
return array;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user