mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Separate the sync layer from its clients. #112
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
public abstract class UniqueId {
|
||||
|
||||
@@ -27,4 +28,20 @@ public abstract class UniqueId {
|
||||
if (hashCode == -1) hashCode = Arrays.hashCode(id);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public static class IdComparator implements Comparator<UniqueId> {
|
||||
|
||||
public static final IdComparator INSTANCE = new IdComparator();
|
||||
|
||||
@Override
|
||||
public int compare(UniqueId a, UniqueId b) {
|
||||
byte[] aBytes = a.getBytes(), bBytes = b.getBytes();
|
||||
for (int i = 0; i < UniqueId.LENGTH; i++) {
|
||||
int aUnsigned = aBytes[i] & 0xFF, bUnsigned = bBytes[i] & 0xFF;
|
||||
if (aUnsigned < bUnsigned) return -1;
|
||||
if (aUnsigned > bUnsigned) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user