aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-06-18 17:38:22 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-06-23 16:54:15 -0700
commit677b9b17e289bcce645b03986cee1e8b30f688ec (patch)
treedf466734b32b5bdf9e867958689481a0f76aa4b9 /org.eclipse.jgit/src
parent864cc3de10c3a1ead5eacab973759d6d58162286 (diff)
downloadjgit-677b9b17e289bcce645b03986cee1e8b30f688ec.tar.gz
jgit-677b9b17e289bcce645b03986cee1e8b30f688ec.zip
Expose AnyObjectId compareTo(byte[]) and compareTo(int[])
Storage systems can use these implementations to compare a passed AnyObjectId with a stored representation of an ObjectId in the canonical network byte order format. This can be useful to do a binary search, or just linear scan, over an encoded storage file. Change-Id: I8c72993c4f4c6e98d599ac2c9867453752f25fd2 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java
index d4d53574b3..7d08f3d4c9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java
@@ -142,7 +142,18 @@ public abstract class AnyObjectId implements Comparable {
return compareTo(((ObjectId) other));
}
- int compareTo(final byte[] bs, final int p) {
+ /**
+ * Compare this ObjectId to a network-byte-order ObjectId.
+ *
+ * @param bs
+ * array containing the other ObjectId in network byte order.
+ * @param p
+ * position within {@code bs} to start the compare at. At least
+ * 20 bytes, starting at this position are required.
+ * @return a negative integer, zero, or a positive integer as this object is
+ * less than, equal to, or greater than the specified object.
+ */
+ public int compareTo(final byte[] bs, final int p) {
int cmp;
cmp = NB.compareUInt32(w1, NB.decodeInt32(bs, p));
@@ -164,7 +175,18 @@ public abstract class AnyObjectId implements Comparable {
return NB.compareUInt32(w5, NB.decodeInt32(bs, p + 16));
}
- int compareTo(final int[] bs, final int p) {
+ /**
+ * Compare this ObjectId to a network-byte-order ObjectId.
+ *
+ * @param bs
+ * array containing the other ObjectId in network byte order.
+ * @param p
+ * position within {@code bs} to start the compare at. At least 5
+ * integers, starting at this position are required.
+ * @return a negative integer, zero, or a positive integer as this object is
+ * less than, equal to, or greater than the specified object.
+ */
+ public int compareTo(final int[] bs, final int p) {
int cmp;
cmp = NB.compareUInt32(w1, bs[p]);