Class AnyObjectId
- All Implemented Interfaces:
Comparable<AnyObjectId>
- Direct Known Subclasses:
MutableObjectId
,ObjectId
If this is an instance of MutableObjectId
the
concept of equality with this instance can alter at any time, if this
instance is modified to represent a different object name.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabbreviate
(int len) Return an abbreviation (prefix) of this object SHA-1.final int
compareTo
(byte[] bs, int p) Compare this ObjectId to a network-byte-order ObjectId.final int
compareTo
(int[] bs, int p) Compare this ObjectId to a network-byte-order ObjectId.final int
compareTo
(AnyObjectId other) final ObjectId
copy()
Obtain an immutable copy of this current object name value.void
copyRawTo
(byte[] b, int o) Copy this ObjectId to a byte array.void
copyRawTo
(int[] b, int o) Copy this ObjectId to an int array.void
Copy this ObjectId to an output writer in raw binary.void
Copy this ObjectId to an output writer in raw binary.void
copyTo
(byte[] b, int o) Copy this ObjectId to a byte array in hex format.void
Copy this ObjectId to an output writer in hex format.void
copyTo
(char[] tmp, StringBuilder w) Copy this ObjectId to a StringBuilder in hex format.void
Copy this ObjectId to an output writer in hex format.void
Copy this ObjectId to an output writer in hex format.void
copyTo
(ByteBuffer b) Copy this ObjectId to a ByteBuffer in hex format.final boolean
final boolean
equals
(AnyObjectId other) Determine if this ObjectId has exactly the same value as another.static boolean
equals
(AnyObjectId firstObjectId, AnyObjectId secondObjectId) Deprecated.private static void
formatHexByte
(byte[] dst, int p, int w) (package private) static void
formatHexChar
(char[] dst, int p, int w) final int
getByte
(int index) Get any byte from the ObjectId.final int
Get the first 8 bits of the ObjectId.final String
getName()
Get string form of the SHA-1, in lower case hexadecimal.final int
hashCode()
static boolean
isEqual
(AnyObjectId firstObjectId, AnyObjectId secondObjectId) Compare two object identifier byte sequences for equality.final String
name()
name.boolean
Tests if this ObjectId starts with the given abbreviation.private byte[]
private char[]
private void
toHexCharArray
(char[] dst) abstract ObjectId
Obtain an immutable copy of this current object name value.toString()
private static void
writeRawInt
(OutputStream w, int v)
-
Field Details
-
w1
int w1 -
w2
int w2 -
w3
int w3 -
w4
int w4 -
w5
int w5 -
hexbyte
private static final byte[] hexbyte -
hexchar
private static final char[] hexchar
-
-
Constructor Details
-
AnyObjectId
public AnyObjectId()
-
-
Method Details
-
equals
Deprecated.useisEqual(AnyObjectId, AnyObjectId)
insteadCompare two object identifier byte sequences for equality.- Parameters:
firstObjectId
- the first identifier to compare. Must not be null.secondObjectId
- the second identifier to compare. Must not be null.- Returns:
- true if the two identifiers are the same.
-
isEqual
Compare two object identifier byte sequences for equality.- Parameters:
firstObjectId
- the first identifier to compare. Must not be null.secondObjectId
- the second identifier to compare. Must not be null.- Returns:
- true if the two identifiers are the same.
- Since:
- 5.4
-
getFirstByte
public final int getFirstByte()Get the first 8 bits of the ObjectId. This is a faster version ofgetByte(0)
.- Returns:
- a discriminator usable for a fan-out style map. Returned values are unsigned and thus are in the range [0,255] rather than the signed byte range of [-128, 127].
-
getByte
public final int getByte(int index) Get any byte from the ObjectId. Callers hard-codinggetByte(0)
should instead use the much faster special case variantgetFirstByte()
.- Parameters:
index
- index of the byte to obtain from the raw form of the ObjectId. Must be in range [0,Constants.OBJECT_ID_LENGTH
).- Returns:
- the value of the requested byte at
index
. Returned values are unsigned and thus are in the range [0,255] rather than the signed byte range of [-128, 127]. - Throws:
ArrayIndexOutOfBoundsException
-index
is less than 0, equal toConstants.OBJECT_ID_LENGTH
, or greater thanConstants.OBJECT_ID_LENGTH
.
-
compareTo
Compare this ObjectId to another and obtain a sort ordering.
- Specified by:
compareTo
in interfaceComparable<AnyObjectId>
-
compareTo
public final int compareTo(byte[] bs, int p) Compare this ObjectId to a network-byte-order ObjectId.- Parameters:
bs
- array containing the other ObjectId in network byte order.p
- position withinbs
to start the compare at. At least 20 bytes, starting at this position are required.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
compareTo
public final int compareTo(int[] bs, int p) Compare this ObjectId to a network-byte-order ObjectId.- Parameters:
bs
- array containing the other ObjectId in network byte order.p
- position withinbs
to start the compare at. At least 5 integers, starting at this position are required.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
startsWith
Tests if this ObjectId starts with the given abbreviation.- Parameters:
abbr
- the abbreviation.- Returns:
- true if this ObjectId begins with the abbreviation; else false.
-
hashCode
public final int hashCode() -
equals
Determine if this ObjectId has exactly the same value as another.- Parameters:
other
- the other id to compare to. May be null.- Returns:
- true only if both ObjectIds have identical bits.
-
equals
-
copyRawTo
Copy this ObjectId to an output writer in raw binary.- Parameters:
w
- the buffer to copy to. Must be in big endian order.
-
copyRawTo
public void copyRawTo(byte[] b, int o) Copy this ObjectId to a byte array.- Parameters:
b
- the buffer to copy to.o
- the offset within b to write at.
-
copyRawTo
public void copyRawTo(int[] b, int o) Copy this ObjectId to an int array.- Parameters:
b
- the buffer to copy to.o
- the offset within b to write at.
-
copyRawTo
Copy this ObjectId to an output writer in raw binary.- Parameters:
w
- the stream to write to.- Throws:
IOException
- the stream writing failed.
-
writeRawInt
- Throws:
IOException
-
copyTo
Copy this ObjectId to an output writer in hex format.- Parameters:
w
- the stream to copy to.- Throws:
IOException
- the stream writing failed.
-
copyTo
public void copyTo(byte[] b, int o) Copy this ObjectId to a byte array in hex format.- Parameters:
b
- the buffer to copy to.o
- the offset within b to write at.
-
copyTo
Copy this ObjectId to a ByteBuffer in hex format.- Parameters:
b
- the buffer to copy to.
-
toHexByteArray
private byte[] toHexByteArray() -
formatHexByte
private static void formatHexByte(byte[] dst, int p, int w) -
copyTo
Copy this ObjectId to an output writer in hex format.- Parameters:
w
- the stream to copy to.- Throws:
IOException
- the stream writing failed.
-
copyTo
Copy this ObjectId to an output writer in hex format.- Parameters:
tmp
- temporary char array to buffer construct into before writing. Must be at least large enough to hold 2 digits for each byte of object id (40 characters or larger).w
- the stream to copy to.- Throws:
IOException
- the stream writing failed.
-
copyTo
Copy this ObjectId to a StringBuilder in hex format.- Parameters:
tmp
- temporary char array to buffer construct into before writing. Must be at least large enough to hold 2 digits for each byte of object id (40 characters or larger).w
- the string to append onto.
-
toHexCharArray
private char[] toHexCharArray() -
toHexCharArray
private void toHexCharArray(char[] dst) -
formatHexChar
static void formatHexChar(char[] dst, int p, int w) -
toString
-
name
name.
- Returns:
- string form of the SHA-1, in lower case hexadecimal.
-
getName
Get string form of the SHA-1, in lower case hexadecimal.- Returns:
- string form of the SHA-1, in lower case hexadecimal.
-
abbreviate
Return an abbreviation (prefix) of this object SHA-1.This implementation does not guarantee uniqueness. Callers should instead use
ObjectReader.abbreviate(AnyObjectId, int)
to obtain a unique abbreviation within the scope of a particular object database.- Parameters:
len
- length of the abbreviated string.- Returns:
- SHA-1 abbreviation.
-
copy
Obtain an immutable copy of this current object name value.Only returns
this
if this instance is an unsubclassed instance ofObjectId
; otherwise a new instance is returned holding the same value.This method is useful to shed any additional memory that may be tied to the subclass, yet retain the unique identity of the object id for future lookups within maps and repositories.
- Returns:
- an immutable copy, using the smallest memory footprint possible.
-
toObjectId
Obtain an immutable copy of this current object name value.See
copy()
ifthis
is a possibly subclassed (but immutable) identity and the application needs a lightweight identity only reference.- Returns:
- an immutable copy. May be
this
if this is already an immutable instance.
-
isEqual(AnyObjectId, AnyObjectId)
instead