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

public abstract Class AnyObjectId

extends Object
implements Comparable<AnyObjectId>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
org.eclipse.jgit.lib.MutableObjectId, org.eclipse.jgit.lib.ObjectId
Imports
java.io.IOException, .OutputStream, .Writer, java.nio.ByteBuffer, org.eclipse.jgit.util.NB, .References

A (possibly mutable) SHA-1 abstraction.

If this is an instance of org.eclipse.jgit.lib.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

Modifier and TypeField and Description
private static final byte[]
private static final char[]
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public AbbreviatedObjectId

Returns:

SHA-1 abbreviation.
abbreviate
(int
length of the abbreviated string.
len
)

Return an abbreviation (prefix) of this object SHA-1.

public final int
compareTo(AnyObjectId
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public final int

Returns:

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
compareTo
(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 ObjectId to a network-byte-order ObjectId.

public final int

Returns:

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
compareTo
(int[]
array containing the other ObjectId in network byte order.
bs
,
int
position within bs to start the compare at. At least 5 integers, starting at this position are required.
p
)

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

public final ObjectId

Returns:

an immutable copy, using the smallest memory footprint possible.
copy
()

Obtain an immutable copy of this current object name value.

public void
copyRawTo(ByteBuffer
the buffer to copy to. Must be in big endian order.
w
)

Copy this ObjectId to an output writer in raw binary.

public void
copyRawTo(byte[]
the buffer to copy to.
b
,
int
the offset within b to write at.
o
)

Copy this ObjectId to a byte array.

public void
copyRawTo(int[]
the buffer to copy to.
b
,
int
the offset within b to write at.
o
)

Copy this ObjectId to an int array.

public void
copyRawTo(OutputStream
the stream to write to.
w
)

Copy this ObjectId to an output writer in raw binary.

public void
copyTo(OutputStream
the stream to copy to.
w
)

Copy this ObjectId to an output writer in hex format.

public void
copyTo(byte[]
the buffer to copy to.
b
,
int
the offset within b to write at.
o
)

Copy this ObjectId to a byte array in hex format.

public void
copyTo(ByteBuffer
the buffer to copy to.
b
)

Copy this ObjectId to a ByteBuffer in hex format.

public void
copyTo(Writer
the stream to copy to.
w
)

Copy this ObjectId to an output writer in hex format.

public void
copyTo(char[]
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).
tmp
,
Writer
the stream to copy to.
w
)

Copy this ObjectId to an output writer in hex format.

public void
copyTo(char[]
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).
tmp
,
StringBuilder
the string to append onto.
w
)

Copy this ObjectId to a StringBuilder in hex format.

public final boolean

Returns:

true only if both ObjectIds have identical bits.
equals
(AnyObjectId
the other id to compare to. May be null.
other
)

Determine if this ObjectId has exactly the same value as another.

public final 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 void
formatHexByte(byte[] dst, int p, int w)

pack-priv static void
formatHexChar(char[] dst, int p, int w)

public final int

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].
getByte
(int
index of the byte to obtain from the raw form of the ObjectId. Must be in range [0, org.eclipse.jgit.lib.Constants#OBJECT_ID_LENGTH).
index
)

Get any byte from the ObjectId.

public final int

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].
getFirstByte
()

Get the first 8 bits of the ObjectId.

public final String

Returns:

string form of the SHA-1, in lower case hexadecimal.
getName
()

Get string form of the SHA-1, in lower case hexadecimal.

public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public static boolean

Returns:

true if the two identifiers are the same.
isEqual
(final AnyObjectId
the first identifier to compare. Must not be null.
firstObjectId
,
final AnyObjectId
the second identifier to compare. Must not be null.
secondObjectId
)

Compare two object identifier byte sequences for equality.

public final String

Returns:

string form of the SHA-1, in lower case hexadecimal.
name
()

name.

public boolean

Returns:

true if this ObjectId begins with the abbreviation; else false.
startsWith
(AbbreviatedObjectId
the abbreviation.
abbr
)

Tests if this ObjectId starts with the given abbreviation.

private byte[]
private char[]
private void
toHexCharArray(char[] dst)

public abstract ObjectId

Returns:

an immutable copy. May be this if this is already an immutable instance.
toObjectId
()

Obtain an immutable copy of this current object name value.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private static void
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

hexbyteback to summary
private static final byte[] hexbyte
hexcharback to summary
private static final char[] hexchar
w1back to summary
pack-priv int w1
w2back to summary
pack-priv int w2
w3back to summary
pack-priv int w3
w4back to summary
pack-priv int w4
w5back to summary
pack-priv int w5

Constructor Detail

AnyObjectIdback to summary
public AnyObjectId()

Method Detail

abbreviateback to summary
public AbbreviatedObjectId abbreviate(int len)

Return an abbreviation (prefix) of this object SHA-1.

This implementation does not guarantee uniqueness. Callers should instead use org.eclipse.jgit.lib.ObjectReader#abbreviate(AnyObjectId, int) to obtain a unique abbreviation within the scope of a particular object database.

Parameters
len:int

length of the abbreviated string.

Returns:AbbreviatedObjectId

SHA-1 abbreviation.

compareToback to summary
public final int compareTo(AnyObjectId other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Compare this ObjectId to another and obtain a sort ordering.

Parameters
other:AnyObjectId

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
compareToback to summary
public final int compareTo(byte[] bs, int p)

Compare this ObjectId 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

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

compareToback to summary
public final int compareTo(int[] bs, int p)

Compare this ObjectId 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 integers, starting at this position are required.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

copyback to summary
public final ObjectId copy()

Obtain an immutable copy of this current object name value.

Only returns this if this instance is an unsubclassed instance of org.eclipse.jgit.lib.ObjectId; 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:ObjectId

an immutable copy, using the smallest memory footprint possible.

copyRawToback to summary
public void copyRawTo(ByteBuffer w)

Copy this ObjectId to an output writer in raw binary.

Parameters
w:ByteBuffer

the buffer to copy to. Must be in big endian order.

copyRawToback to summary
public void copyRawTo(byte[] b, int o)

Copy this ObjectId to a byte array.

Parameters
b:byte[]

the buffer to copy to.

o:int

the offset within b to write at.

copyRawToback to summary
public void copyRawTo(int[] b, int o)

Copy this ObjectId to an int array.

Parameters
b:int[]

the buffer to copy to.

o:int

the offset within b to write at.

copyRawToback to summary
public void copyRawTo(OutputStream w) throws IOException

Copy this ObjectId to an output writer in raw binary.

Parameters
w:OutputStream

the stream to write to.

Exceptions
IOException:
the stream writing failed.
copyToback to summary
public void copyTo(OutputStream w) throws IOException

Copy this ObjectId to an output writer in hex format.

Parameters
w:OutputStream

the stream to copy to.

Exceptions
IOException:
the stream writing failed.
copyToback to summary
public void copyTo(byte[] b, int o)

Copy this ObjectId to a byte array in hex format.

Parameters
b:byte[]

the buffer to copy to.

o:int

the offset within b to write at.

copyToback to summary
public void copyTo(ByteBuffer b)

Copy this ObjectId to a ByteBuffer in hex format.

Parameters
b:ByteBuffer

the buffer to copy to.

copyToback to summary
public void copyTo(Writer w) throws IOException

Copy this ObjectId to an output writer in hex format.

Parameters
w:Writer

the stream to copy to.

Exceptions
IOException:
the stream writing failed.
copyToback to summary
public void copyTo(char[] tmp, Writer w) throws IOException

Copy this ObjectId to an output writer in hex format.

Parameters
tmp:char[]

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:Writer

the stream to copy to.

Exceptions
IOException:
the stream writing failed.
copyToback to summary
public void copyTo(char[] tmp, StringBuilder w)

Copy this ObjectId to a StringBuilder in hex format.

Parameters
tmp:char[]

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:StringBuilder

the string to append onto.

equalsback to summary
public final boolean equals(AnyObjectId other)

Determine if this ObjectId has exactly the same value as another.

Parameters
other:AnyObjectId

the other id to compare to. May be null.

Returns:boolean

true only if both ObjectIds have identical bits.

Annotations
@SuppressWarnings:NonOverridingEquals, AmbiguousMethodReference
equalsback to summary
public final 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
formatHexByteback to summary
private static void formatHexByte(byte[] dst, int p, int w)
formatHexCharback to summary
pack-priv static void formatHexChar(char[] dst, int p, int w)
getByteback to summary
public final int getByte(int index)

Get any byte from the ObjectId. Callers hard-coding getByte(0) should instead use the much faster special case variant getFirstByte().

Parameters
index:int

index of the byte to obtain from the raw form of the ObjectId. Must be in range [0, org.eclipse.jgit.lib.Constants#OBJECT_ID_LENGTH).

Returns:int

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].

Exceptions
ArrayIndexOutOfBoundsException:
index is less than 0, equal to org.eclipse.jgit.lib.Constants#OBJECT_ID_LENGTH, or greater than org.eclipse.jgit.lib.Constants#OBJECT_ID_LENGTH.
getFirstByteback to summary
public final int getFirstByte()

Get the first 8 bits of the ObjectId. This is a faster version of getByte(0).

Returns:int

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].

getNameback to summary
public final String getName()

Get string form of the SHA-1, in lower case hexadecimal.

Returns:String

string form of the SHA-1, in lower case hexadecimal.

hashCodeback to summary
public final 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
isEqualback to summary
public static boolean isEqual(final AnyObjectId firstObjectId, final AnyObjectId secondObjectId)

Compare two object identifier byte sequences for equality.

Parameters
firstObjectId:AnyObjectId

the first identifier to compare. Must not be null.

secondObjectId:AnyObjectId

the second identifier to compare. Must not be null.

Returns:boolean

true if the two identifiers are the same.

Since
5.4
nameback to summary
public final String name()

name.

Returns:String

string form of the SHA-1, in lower case hexadecimal.

startsWithback to summary
public boolean startsWith(AbbreviatedObjectId abbr)

Tests if this ObjectId starts with the given abbreviation.

Parameters
abbr:AbbreviatedObjectId

the abbreviation.

Returns:boolean

true if this ObjectId begins with the abbreviation; else false.

toHexByteArrayback to summary
private byte[] toHexByteArray()
toHexCharArrayback to summary
private char[] toHexCharArray()
toHexCharArrayback to summary
private void toHexCharArray(char[] dst)
toObjectIdback to summary
public abstract ObjectId toObjectId()

Obtain an immutable copy of this current object name value.

See copy() if this is a possibly subclassed (but immutable) identity and the application needs a lightweight identity only reference.

Returns:ObjectId

an immutable copy. May be this if this is already an immutable instance.

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
writeRawIntback to summary
private static void writeRawInt(OutputStream w, int v) throws IOException