|
|
|
@ -170,7 +170,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* Compare this LongObjectId to another and obtain a sort ordering. |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public final int compareTo(final AnyLongObjectId other) { |
|
|
|
|
public final int compareTo(AnyLongObjectId other) { |
|
|
|
|
if (this == other) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
@ -202,7 +202,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @return a negative integer, zero, or a positive integer as this object is |
|
|
|
|
* less than, equal to, or greater than the specified object. |
|
|
|
|
*/ |
|
|
|
|
public final int compareTo(final byte[] bs, final int p) { |
|
|
|
|
public final int compareTo(byte[] bs, int p) { |
|
|
|
|
int cmp; |
|
|
|
|
|
|
|
|
|
cmp = NB.compareUInt64(w1, NB.decodeInt64(bs, p)); |
|
|
|
@ -231,7 +231,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @return a negative integer, zero, or a positive integer as this object is |
|
|
|
|
* less than, equal to, or greater than the specified object. |
|
|
|
|
*/ |
|
|
|
|
public final int compareTo(final long[] bs, final int p) { |
|
|
|
|
public final int compareTo(long[] bs, int p) { |
|
|
|
|
int cmp; |
|
|
|
|
|
|
|
|
|
cmp = NB.compareUInt64(w1, bs[p]); |
|
|
|
@ -257,7 +257,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @return true if this LongObjectId begins with the abbreviation; else |
|
|
|
|
* false. |
|
|
|
|
*/ |
|
|
|
|
public boolean startsWith(final AbbreviatedLongObjectId abbr) { |
|
|
|
|
public boolean startsWith(AbbreviatedLongObjectId abbr) { |
|
|
|
|
return abbr.prefixCompare(this) == 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -274,13 +274,13 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* the other id to compare to. May be null. |
|
|
|
|
* @return true only if both LongObjectIds have identical bits. |
|
|
|
|
*/ |
|
|
|
|
public final boolean equals(final AnyLongObjectId other) { |
|
|
|
|
public final boolean equals(AnyLongObjectId other) { |
|
|
|
|
return other != null ? equals(this, other) : false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
public final boolean equals(final Object o) { |
|
|
|
|
public final boolean equals(Object o) { |
|
|
|
|
if (o instanceof AnyLongObjectId) |
|
|
|
|
return equals((AnyLongObjectId) o); |
|
|
|
|
else |
|
|
|
@ -293,7 +293,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @param w |
|
|
|
|
* the buffer to copy to. Must be in big endian order. |
|
|
|
|
*/ |
|
|
|
|
public void copyRawTo(final ByteBuffer w) { |
|
|
|
|
public void copyRawTo(ByteBuffer w) { |
|
|
|
|
w.putLong(w1); |
|
|
|
|
w.putLong(w2); |
|
|
|
|
w.putLong(w3); |
|
|
|
@ -308,7 +308,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @param o |
|
|
|
|
* the offset within b to write at. |
|
|
|
|
*/ |
|
|
|
|
public void copyRawTo(final byte[] b, final int o) { |
|
|
|
|
public void copyRawTo(byte[] b, int o) { |
|
|
|
|
NB.encodeInt64(b, o, w1); |
|
|
|
|
NB.encodeInt64(b, o + 8, w2); |
|
|
|
|
NB.encodeInt64(b, o + 16, w3); |
|
|
|
@ -323,7 +323,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @param o |
|
|
|
|
* the offset within b to write at. |
|
|
|
|
*/ |
|
|
|
|
public void copyRawTo(final long[] b, final int o) { |
|
|
|
|
public void copyRawTo(long[] b, int o) { |
|
|
|
|
b[o] = w1; |
|
|
|
|
b[o + 1] = w2; |
|
|
|
|
b[o + 2] = w3; |
|
|
|
@ -338,14 +338,14 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @throws java.io.IOException |
|
|
|
|
* the stream writing failed. |
|
|
|
|
*/ |
|
|
|
|
public void copyRawTo(final OutputStream w) throws IOException { |
|
|
|
|
public void copyRawTo(OutputStream w) throws IOException { |
|
|
|
|
writeRawLong(w, w1); |
|
|
|
|
writeRawLong(w, w2); |
|
|
|
|
writeRawLong(w, w3); |
|
|
|
|
writeRawLong(w, w4); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void writeRawLong(final OutputStream w, long v) |
|
|
|
|
private static void writeRawLong(OutputStream w, long v) |
|
|
|
|
throws IOException { |
|
|
|
|
w.write((int) (v >>> 56)); |
|
|
|
|
w.write((int) (v >>> 48)); |
|
|
|
@ -365,7 +365,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @throws java.io.IOException |
|
|
|
|
* the stream writing failed. |
|
|
|
|
*/ |
|
|
|
|
public void copyTo(final OutputStream w) throws IOException { |
|
|
|
|
public void copyTo(OutputStream w) throws IOException { |
|
|
|
|
w.write(toHexByteArray()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -406,7 +406,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
private static final byte[] hexbyte = { '0', '1', '2', '3', '4', '5', '6', |
|
|
|
|
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
|
|
|
|
|
|
|
|
|
private static void formatHexByte(final byte[] dst, final int p, long w) { |
|
|
|
|
private static void formatHexByte(byte[] dst, int p, long w) { |
|
|
|
|
int o = p + 15; |
|
|
|
|
while (o >= p && w != 0) { |
|
|
|
|
dst[o--] = hexbyte[(int) (w & 0xf)]; |
|
|
|
@ -424,7 +424,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @throws java.io.IOException |
|
|
|
|
* the stream writing failed. |
|
|
|
|
*/ |
|
|
|
|
public void copyTo(final Writer w) throws IOException { |
|
|
|
|
public void copyTo(Writer w) throws IOException { |
|
|
|
|
w.write(toHexCharArray()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -440,7 +440,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @throws java.io.IOException |
|
|
|
|
* the stream writing failed. |
|
|
|
|
*/ |
|
|
|
|
public void copyTo(final char[] tmp, final Writer w) throws IOException { |
|
|
|
|
public void copyTo(char[] tmp, Writer w) throws IOException { |
|
|
|
|
toHexCharArray(tmp); |
|
|
|
|
w.write(tmp, 0, Constants.LONG_OBJECT_ID_STRING_LENGTH); |
|
|
|
|
} |
|
|
|
@ -455,7 +455,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* @param w |
|
|
|
|
* the string to append onto. |
|
|
|
|
*/ |
|
|
|
|
public void copyTo(final char[] tmp, final StringBuilder w) { |
|
|
|
|
public void copyTo(char[] tmp, StringBuilder w) { |
|
|
|
|
toHexCharArray(tmp); |
|
|
|
|
w.append(tmp, 0, Constants.LONG_OBJECT_ID_STRING_LENGTH); |
|
|
|
|
} |
|
|
|
@ -466,7 +466,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
return dst; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void toHexCharArray(final char[] dst) { |
|
|
|
|
private void toHexCharArray(char[] dst) { |
|
|
|
|
formatHexChar(dst, 0, w1); |
|
|
|
|
formatHexChar(dst, 16, w2); |
|
|
|
|
formatHexChar(dst, 32, w3); |
|
|
|
@ -524,7 +524,7 @@ public abstract class AnyLongObjectId implements Comparable<AnyLongObjectId> {
|
|
|
|
|
* length of the abbreviated string. |
|
|
|
|
* @return SHA-256 abbreviation. |
|
|
|
|
*/ |
|
|
|
|
public AbbreviatedLongObjectId abbreviate(final int len) { |
|
|
|
|
public AbbreviatedLongObjectId abbreviate(int len) { |
|
|
|
|
final long a = AbbreviatedLongObjectId.mask(len, 1, w1); |
|
|
|
|
final long b = AbbreviatedLongObjectId.mask(len, 2, w2); |
|
|
|
|
final long c = AbbreviatedLongObjectId.mask(len, 3, w3); |
|
|
|
|