Top Description Fields Constructors Methods
org.eclipse.jgit.lib

public final Class AbbreviatedObjectId

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.text.MessageFormat, org.eclipse.jgit.errors.InvalidObjectIdException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.util.NB, .RawParseUtils

A prefix abbreviation of an org.eclipse.jgit.lib.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.

Field Summary

Modifier and TypeField and Description
pack-priv final int
nibbles

Number of half-bytes used by this id.

private static final long
pack-priv final int
pack-priv final int
pack-priv final int
pack-priv final int
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
AbbreviatedObjectId(final int n, final int new_1, final int new_2, final int new_3, final int new_4, final int new_5)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

private static final AbbreviatedObjectId
fromHexString(final byte[] bs, int ptr, final int end)

public static final AbbreviatedObjectId

Returns:

the converted object id.
fromObjectId
(AnyObjectId
the org.eclipse.jgit.lib.ObjectId to convert from.
id
)

Convert an AbbreviatedObjectId from an org.eclipse.jgit.lib.AnyObjectId.

public static final AbbreviatedObjectId

Returns:

the converted object id.
fromString
(final byte[]
the US-ASCII buffer to read from.
buf
,
final int
position to read the first character from.
offset
,
final int
one past the last position to read (end-offset is the length of the string).
end
)

Convert an AbbreviatedObjectId from hex characters (US-ASCII).

public static final AbbreviatedObjectId

Returns:

the converted object id.
fromString
(String
the string to read from. Must be <= 40 characters.
str
)

Convert an AbbreviatedObjectId from hex characters.

public final int

Returns:

value for a fan-out style map, only valid of length >= 2.
getFirstByte
()

Get value for a fan-out style map, only valid of length >= 2.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private static final int
hexUInt32(final byte[] bs, int p, final int end)

public boolean

Returns:

true if this ObjectId is actually a complete id.
isComplete
()

Whether this ObjectId is actually a complete id.

public static final boolean

Returns:

true if the string can converted into an AbbreviatedObjectId.
isId
(String
the string to test.
id
)

Test a string of characters to verify it is a hex format.

public int

Returns:

number of hex digits appearing in this id.
length
()

Get number of hex digits appearing in this id.

pack-priv static int
mask(int nibbles, int word, int v)

private int
mask(int word, int v)

public final String

Returns:

string form of the abbreviation, in lower case hexadecimal.
name
()

Get string form of the abbreviation, in lower case hexadecimal.

public final int

Returns:

<0 if this abbreviation names an object that is less than 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.
prefixCompare
(AnyObjectId
the other object id.
other
)

Compares this abbreviation to a full object id.

public final int

Returns:

<0 if this abbreviation names an object that is less than 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.
prefixCompare
(byte[]
array containing the other ObjectId in network byte order.
bs
,
int
position within bs to start the compare at. At least 20 bytes, starting at this position are required.
p
)

Compare this abbreviation to a network-byte-order ObjectId.

public final int

Returns:

<0 if this abbreviation names an object that is less than 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.
prefixCompare
(int[]
array containing the other ObjectId in network byte order.
bs
,
int
position within bs to start the compare at. At least 5 ints, starting at this position are required.
p
)

Compare this abbreviation to a network-byte-order ObjectId.

public ObjectId

Returns:

a complete ObjectId; null if isComplete() is false
toObjectId
()

A complete ObjectId; null if isComplete() is false

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

nibblesback to summary
pack-priv final int nibbles

Number of half-bytes used by this id.

serialVersionUIDback to summary
private static final long serialVersionUID
w1back to summary
pack-priv final int w1
w2back to summary
pack-priv final int w2
w3back to summary
pack-priv final int w3
w4back to summary
pack-priv final int w4
w5back to summary
pack-priv final int w5

Constructor Detail

AbbreviatedObjectIdback to summary
pack-priv AbbreviatedObjectId(final int n, final int new_1, final int new_2, final int new_3, final int new_4, final int new_5)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
fromHexStringback to summary
private static final AbbreviatedObjectId fromHexString(final byte[] bs, int ptr, final int end)
fromObjectIdback to summary
public static final AbbreviatedObjectId fromObjectId(AnyObjectId id)

Convert an AbbreviatedObjectId from an org.eclipse.jgit.lib.AnyObjectId.

This method copies over all bits of the Id, and is therefore complete (see isComplete()).

Parameters
id:AnyObjectId

the org.eclipse.jgit.lib.ObjectId to convert from.

Returns:AbbreviatedObjectId

the converted object id.

fromStringback to summary
public static final AbbreviatedObjectId fromString(final byte[] buf, final int offset, final int end)

Convert an AbbreviatedObjectId from hex characters (US-ASCII).

Parameters
buf:byte[]

the US-ASCII buffer to read from.

offset:int

position to read the first character from.

end:int

one past the last position to read (end-offset is the length of the string).

Returns:AbbreviatedObjectId

the converted object id.

fromStringback to summary
public static final AbbreviatedObjectId fromString(String str)

Convert an AbbreviatedObjectId from hex characters.

Parameters
str:String

the string to read from. Must be <= 40 characters.

Returns:AbbreviatedObjectId

the converted object id.

getFirstByteback to summary
public final int getFirstByte()

Get value for a fan-out style map, only valid of length >= 2.

Returns:int

value for a fan-out style map, only valid of length >= 2.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hexUInt32back to summary
private static final int hexUInt32(final byte[] bs, int p, final int end)
isCompleteback to summary
public boolean isComplete()

Whether this ObjectId is actually a complete id.

Returns:boolean

true if this ObjectId is actually a complete id.

isIdback to summary
public static final boolean isId(String id)

Test a string of characters to verify it is a hex format.

If true the string can be parsed with fromString(String).

Parameters
id:String

the string to test.

Returns:boolean

true if the string can converted into an AbbreviatedObjectId.

lengthback to summary
public int length()

Get number of hex digits appearing in this id.

Returns:int

number of hex digits appearing in this id.

maskback to summary
pack-priv static int mask(int nibbles, int word, int v)
maskback to summary
private int mask(int word, int v)
nameback to summary
public final String name()

Get string form of the abbreviation, in lower case hexadecimal.

Returns:String

string form of the abbreviation, in lower case hexadecimal.

prefixCompareback to summary
public final int prefixCompare(AnyObjectId other)

Compares this abbreviation to a full object id.

Parameters
other:AnyObjectId

the other object id.

Returns:int

<0 if this abbreviation names an object that is less than 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.

prefixCompareback to summary
public final int prefixCompare(byte[] bs, int p)

Compare this abbreviation to a network-byte-order ObjectId.

Parameters
bs:byte[]

array containing the other ObjectId in network byte order.

p:int

position within bs to start the compare at. At least 20 bytes, starting at this position are required.

Returns:int

<0 if this abbreviation names an object that is less than 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.

prefixCompareback to summary
public final int prefixCompare(int[] bs, int p)

Compare this abbreviation to a network-byte-order ObjectId.

Parameters
bs:int[]

array containing the other ObjectId in network byte order.

p:int

position within bs to start the compare at. At least 5 ints, starting at this position are required.

Returns:int

<0 if this abbreviation names an object that is less than 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.

toObjectIdback to summary
public ObjectId toObjectId()

A complete ObjectId; null if isComplete() is false

Returns:ObjectId

a complete ObjectId; null if isComplete() is false

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@SuppressWarnings:nls
@Override