Class AnyLongObjectId
- java.lang.Object
-
- org.eclipse.jgit.lfs.lib.AnyLongObjectId
-
- All Implemented Interfaces:
java.lang.Comparable<AnyLongObjectId>
- Direct Known Subclasses:
LongObjectId,MutableLongObjectId
public abstract class AnyLongObjectId extends java.lang.Object implements java.lang.Comparable<AnyLongObjectId>
A (possibly mutable) SHA-256 abstraction.If this is an instance of
MutableLongObjectIdthe concept of equality with this instance can alter at any time, if this instance is modified to represent a different object name. Ported to SHA-256 fromAnyObjectId- Since:
- 4.3
-
-
Constructor Summary
Constructors Constructor Description AnyLongObjectId()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AbbreviatedLongObjectIdabbreviate(int len)Return an abbreviation (prefix) of this object SHA-256.intcompareTo(byte[] bs, int p)Compare this LongObjectId to a network-byte-order LongObjectId.intcompareTo(long[] bs, int p)Compare this LongObjectId to a network-byte-order LongObjectId.intcompareTo(AnyLongObjectId other)Compare this LongObjectId to another and obtain a sort ordering.LongObjectIdcopy()Obtain an immutable copy of this current object.voidcopyRawTo(byte[] b, int o)Copy this LongObjectId to a byte array.voidcopyRawTo(long[] b, int o)Copy this LongObjectId to an long array.voidcopyRawTo(java.io.OutputStream w)Copy this LongObjectId to an output writer in raw binary.voidcopyRawTo(java.nio.ByteBuffer w)Copy this LongObjectId to an output writer in raw binary.voidcopyTo(byte[] b, int o)Copy this LongObjectId to a byte array in hex format.voidcopyTo(char[] tmp, java.io.Writer w)Copy this LongObjectId to an output writer in hex format.voidcopyTo(char[] tmp, java.lang.StringBuilder w)Copy this LongObjectId to a StringBuilder in hex format.voidcopyTo(java.io.OutputStream w)Copy this LongObjectId to an output writer in hex format.voidcopyTo(java.io.Writer w)Copy this LongObjectId to an output writer in hex format.voidcopyTo(java.nio.ByteBuffer b)Copy this LongObjectId to a ByteBuffer in hex format.booleanequals(java.lang.Object o)booleanequals(AnyLongObjectId other)Determine if this LongObjectId has exactly the same value as another.static booleanequals(AnyLongObjectId firstObjectId, AnyLongObjectId secondObjectId)Deprecated.useisEqual(AnyLongObjectId, AnyLongObjectId)instead.private static voidformatHexByte(byte[] dst, int p, long w)(package private) static voidformatHexChar(char[] dst, int p, long w)intgetByte(int index)Get any byte from the LongObjectId.intgetFirstByte()Get the first 8 bits of the LongObjectId.java.lang.StringgetName()Get string form of the SHA-256intgetSecondByte()Get the second 8 bits of the LongObjectId.inthashCode()static booleanisEqual(AnyLongObjectId firstObjectId, AnyLongObjectId secondObjectId)Compare two object identifier byte sequences for equality.java.lang.Stringname()Get string form of the SHA-256booleanstartsWith(AbbreviatedLongObjectId abbr)Tests if this LongObjectId starts with the given abbreviation.private byte[]toHexByteArray()(package private) char[]toHexCharArray()private voidtoHexCharArray(char[] dst)abstract LongObjectIdtoObjectId()Obtain an immutable copy of this current object.java.lang.StringtoString()private static voidwriteRawLong(java.io.OutputStream w, long v)
-
-
-
Method Detail
-
equals
@Deprecated public static boolean equals(AnyLongObjectId firstObjectId, AnyLongObjectId secondObjectId)
Deprecated.useisEqual(AnyLongObjectId, AnyLongObjectId)instead.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.
-
isEqual
public static boolean isEqual(AnyLongObjectId firstObjectId, AnyLongObjectId secondObjectId)
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 LongObjectId. 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].
-
getSecondByte
public final int getSecondByte()
Get the second 8 bits of the LongObjectId.- 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 LongObjectId. 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 LongObjectId. Must be in range [0,Constants.LONG_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:
java.lang.ArrayIndexOutOfBoundsException-indexis less than 0, equal toConstants.LONG_OBJECT_ID_LENGTH, or greater thanConstants.LONG_OBJECT_ID_LENGTH.
-
compareTo
public final int compareTo(AnyLongObjectId other)
Compare this LongObjectId to another and obtain a sort ordering.- Specified by:
compareToin interfacejava.lang.Comparable<AnyLongObjectId>
-
compareTo
public final int compareTo(byte[] bs, int p)Compare this LongObjectId to a network-byte-order LongObjectId.- Parameters:
bs- array containing the other LongObjectId in network byte order.p- position withinbsto start the compare at. At least 32 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(long[] bs, int p)Compare this LongObjectId to a network-byte-order LongObjectId.- Parameters:
bs- array containing the other LongObjectId in network byte order.p- position withinbsto start the compare at. At least 4 longs, 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
public boolean startsWith(AbbreviatedLongObjectId abbr)
Tests if this LongObjectId starts with the given abbreviation.- Parameters:
abbr- the abbreviation.- Returns:
- true if this LongObjectId begins with the abbreviation; else false.
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(AnyLongObjectId other)
Determine if this LongObjectId has exactly the same value as another.- Parameters:
other- the other id to compare to. May be null.- Returns:
- true only if both LongObjectIds have identical bits.
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
copyRawTo
public void copyRawTo(java.nio.ByteBuffer w)
Copy this LongObjectId 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 LongObjectId to a byte array.- Parameters:
b- the buffer to copy to.o- the offset within b to write at.
-
copyRawTo
public void copyRawTo(long[] b, int o)Copy this LongObjectId to an long array.- Parameters:
b- the buffer to copy to.o- the offset within b to write at.
-
copyRawTo
public void copyRawTo(java.io.OutputStream w) throws java.io.IOExceptionCopy this LongObjectId to an output writer in raw binary.- Parameters:
w- the stream to write to.- Throws:
java.io.IOException- the stream writing failed.
-
writeRawLong
private static void writeRawLong(java.io.OutputStream w, long v) throws java.io.IOException- Throws:
java.io.IOException
-
copyTo
public void copyTo(java.io.OutputStream w) throws java.io.IOExceptionCopy this LongObjectId to an output writer in hex format.- Parameters:
w- the stream to copy to.- Throws:
java.io.IOException- the stream writing failed.
-
copyTo
public void copyTo(byte[] b, int o)Copy this LongObjectId to a byte array in hex format.- Parameters:
b- the buffer to copy to.o- the offset within b to write at.
-
copyTo
public void copyTo(java.nio.ByteBuffer b)
Copy this LongObjectId 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, long w)
-
copyTo
public void copyTo(java.io.Writer w) throws java.io.IOExceptionCopy this LongObjectId to an output writer in hex format.- Parameters:
w- the stream to copy to.- Throws:
java.io.IOException- the stream writing failed.
-
copyTo
public void copyTo(char[] tmp, java.io.Writer w) throws java.io.IOExceptionCopy this LongObjectId 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 (64 characters or larger).w- the stream to copy to.- Throws:
java.io.IOException- the stream writing failed.
-
copyTo
public void copyTo(char[] tmp, java.lang.StringBuilder w)Copy this LongObjectId 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 (64 characters or larger).w- the string to append onto.
-
toHexCharArray
char[] toHexCharArray()
-
toHexCharArray
private void toHexCharArray(char[] dst)
-
formatHexChar
static void formatHexChar(char[] dst, int p, long w)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
name
public final java.lang.String name()
Get string form of the SHA-256- Returns:
- string form of the SHA-256, in lower case hexadecimal.
-
getName
public final java.lang.String getName()
Get string form of the SHA-256- Returns:
- string form of the SHA-256, in lower case hexadecimal.
-
abbreviate
public AbbreviatedLongObjectId abbreviate(int len)
Return an abbreviation (prefix) of this object SHA-256.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-256 abbreviation.
-
copy
public final LongObjectId copy()
Obtain an immutable copy of this current object.Only returns
thisif this instance is an unsubclassed instance ofLongObjectId; 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
public abstract LongObjectId toObjectId()
Obtain an immutable copy of this current object.See
copy()ifthisis a possibly subclassed (but immutable) identity and the application needs a lightweight identity only reference.- Returns:
- an immutable copy. May be
thisif this is already an immutable instance.
-
-