mirror of
https://github.com/corda/corda.git
synced 2025-06-15 05:38:14 +00:00
make ByteBuffer implement Comparable
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
package java.nio;
|
package java.nio;
|
||||||
|
|
||||||
public class ByteBuffer {
|
public class ByteBuffer implements Comparable<ByteBuffer> {
|
||||||
private final byte[] array;
|
private final byte[] array;
|
||||||
private int arrayOffset;
|
private int arrayOffset;
|
||||||
private int capacity;
|
private int capacity;
|
||||||
@ -25,6 +25,22 @@ public class ByteBuffer {
|
|||||||
position = 0;
|
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() {
|
public byte[] array() {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user