public final class AbbreviatedObjectId
extends java.lang.Object
implements java.io.Serializable
ObjectId
.
Sometimes Git produces abbreviated SHA-1 strings, using sufficient leading digits from the ObjectId name to still be unique within the repository the string was generated from. These ids are likely to be unique for a useful period of time, especially if they contain at least 6-10 hex digits.
This class converts the hex string into a binary form, to make it more efficient for matching against an object.
Modifier and Type | Field and Description |
---|---|
(package private) int |
nibbles
Number of half-bytes used by this id.
|
private static long |
serialVersionUID |
(package private) int |
w1 |
(package private) int |
w2 |
(package private) int |
w3 |
(package private) int |
w4 |
(package private) int |
w5 |
Constructor and Description |
---|
AbbreviatedObjectId(int n,
int new_1,
int new_2,
int new_3,
int new_4,
int new_5) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
private static AbbreviatedObjectId |
fromHexString(byte[] bs,
int ptr,
int end) |
static AbbreviatedObjectId |
fromObjectId(AnyObjectId id)
Convert an AbbreviatedObjectId from an
AnyObjectId . |
static AbbreviatedObjectId |
fromString(byte[] buf,
int offset,
int end)
Convert an AbbreviatedObjectId from hex characters (US-ASCII).
|
static AbbreviatedObjectId |
fromString(java.lang.String str)
Convert an AbbreviatedObjectId from hex characters.
|
int |
getFirstByte()
Get value for a fan-out style map, only valid of length >= 2.
|
int |
hashCode() |
private static int |
hexUInt32(byte[] bs,
int p,
int end) |
boolean |
isComplete()
Whether this ObjectId is actually a complete id.
|
static boolean |
isId(java.lang.String id)
Test a string of characters to verify it is a hex format.
|
int |
length()
Get number of hex digits appearing in this id.
|
private int |
mask(int word,
int v) |
(package private) static int |
mask(int nibbles,
int word,
int v) |
java.lang.String |
name()
Get string form of the abbreviation, in lower case hexadecimal.
|
int |
prefixCompare(AnyObjectId other)
Compares this abbreviation to a full object id.
|
int |
prefixCompare(byte[] bs,
int p)
Compare this abbreviation to a network-byte-order ObjectId.
|
int |
prefixCompare(int[] bs,
int p)
Compare this abbreviation to a network-byte-order ObjectId.
|
ObjectId |
toObjectId()
A complete ObjectId; null if
isComplete() is false |
java.lang.String |
toString() |
private static final long serialVersionUID
final int nibbles
final int w1
final int w2
final int w3
final int w4
final int w5
AbbreviatedObjectId(int n, int new_1, int new_2, int new_3, int new_4, int new_5)
public static final boolean isId(java.lang.String id)
If true the string can be parsed with fromString(String)
.
id
- the string to test.public static final AbbreviatedObjectId fromString(byte[] buf, int offset, int end)
buf
- the US-ASCII buffer to read from.offset
- position to read the first character from.end
- one past the last position to read (end-offset
is
the length of the string).public static final AbbreviatedObjectId fromObjectId(AnyObjectId id)
AnyObjectId
.
This method copies over all bits of the Id, and is therefore complete
(see isComplete()
).
id
- the ObjectId
to convert from.public static final AbbreviatedObjectId fromString(java.lang.String str)
str
- the string to read from. Must be <= 40 characters.private static final AbbreviatedObjectId fromHexString(byte[] bs, int ptr, int end)
private static final int hexUInt32(byte[] bs, int p, int end)
static int mask(int nibbles, int word, int v)
public int length()
public boolean isComplete()
public ObjectId toObjectId()
isComplete()
is falseisComplete()
is falsepublic final int prefixCompare(AnyObjectId other)
other
- the other object id.other
; 0 if this abbreviation exactly matches the
first length()
digits of other.name()
;
>0 if this abbreviation names an object that is after
other
.public final int prefixCompare(byte[] bs, int p)
bs
- array containing the other ObjectId in network byte order.p
- position within bs
to start the compare at. At least
20 bytes, starting at this position are required.other
; 0 if this abbreviation exactly matches the
first length()
digits of other.name()
;
>0 if this abbreviation names an object that is after
other
.public final int prefixCompare(int[] bs, int p)
bs
- array containing the other ObjectId in network byte order.p
- position within bs
to start the compare at. At least 5
ints, starting at this position are required.other
; 0 if this abbreviation exactly matches the
first length()
digits of other.name()
;
>0 if this abbreviation names an object that is after
other
.public final int getFirstByte()
private int mask(int word, int v)
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public final java.lang.String name()
public java.lang.String toString()
toString
in class java.lang.Object