Modifier and Type | Method and Description |
---|---|
abstract byte[] |
asBytes()
Returns the value of this hash code as a byte array.
|
abstract int |
asInt()
Returns the first four bytes of this hashcode's bytes, converted to
an
int value in little-endian order. |
abstract long |
asLong()
Returns the first eight bytes of this hashcode's bytes, converted to
a
long value in little-endian order. |
abstract int |
bits()
Returns the number of bits in this hash code; a positive multiple of 8.
|
boolean |
equals(Object object)
Indicates whether some other object is "equal to" this one.
|
static HashCode |
fromBytes(byte[] bytes)
Creates a
HashCode from a byte array. |
static HashCode |
fromInt(int hash)
Creates a 32-bit
HashCode representation of the given int value. |
static HashCode |
fromLong(long hash)
Creates a 64-bit
HashCode representation of the given long value. |
static HashCode |
fromString(String string)
Creates a
HashCode from a hexadecimal (base 16 ) encoded string. |
int |
hashCode()
Returns a "Java hash code" for this
HashCode instance; this is well-defined
(so, for example, you can safely put HashCode instances into a HashSet ) but is otherwise probably not what you want to use. |
abstract long |
padToLong()
If this hashcode has enough bits, returns
asLong() , otherwise returns a long
value with asBytes() as the least-significant bytes and 0x00 as the remaining
most-significant bytes. |
String |
toString()
Returns a string containing each byte of
asBytes() , in order, as a two-digit unsigned
hexadecimal number in lower case. |
int |
writeBytesTo(byte[] dest,
int offset,
int maxLength)
Copies bytes from this hash code into
dest . |
public abstract int bits()
public abstract int asInt()
int
value in little-endian order.IllegalStateException
- if bits() < 32
public abstract long asLong()
long
value in little-endian order.IllegalStateException
- if bits() < 64
public abstract long padToLong()
asLong()
, otherwise returns a long
value with asBytes()
as the least-significant bytes and 0x00
as the remaining
most-significant bytes.Hashing.padToLong(HashCode)
)public abstract byte[] asBytes()
HashCode
object or any other arrays
returned by this method.public int writeBytesTo(byte[] dest, int offset, int maxLength)
dest
.dest
- the byte array into which the hash code will be writtenoffset
- the start offset in the datamaxLength
- the maximum number of bytes to writedest
IndexOutOfBoundsException
- if there is not enough room in dest
public static HashCode fromInt(int hash)
HashCode
representation of the given int value. The underlying bytes
are interpreted in little endian order.public static HashCode fromLong(long hash)
HashCode
representation of the given long value. The underlying bytes
are interpreted in little endian order.public static HashCode fromBytes(byte[] bytes)
HashCode
from a byte array. The array is defensively copied to preserve
the immutability contract of HashCode
. The array cannot be empty.public static HashCode fromString(String string)
HashCode
from a hexadecimal (base 16
) encoded string. The string must
be at least 2 characters long, and contain only valid, lower-cased hexadecimal characters.
This method accepts the exact format generated by toString()
. If you require more
lenient base 16
decoding, please use
BaseEncoding.decode(java.lang.CharSequence)
(and pass the result to fromBytes(byte[])
).
public final boolean equals(@Nullable Object object)
java.lang.Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
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.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
object
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public final int hashCode()
HashCode
instance; this is well-defined
(so, for example, you can safely put HashCode
instances into a HashSet
) but is otherwise probably not what you want to use.hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public final String toString()
asBytes()
, in order, as a two-digit unsigned
hexadecimal number in lower case.
Note that if the output is considered to be a single hexadecimal number, this hash code's
bytes are the big-endian representation of that number. This may be surprising since
everything else in the hashing API uniformly treats multibyte values as little-endian. But
this format conveniently matches that of utilities such as the UNIX md5sum
command.
To create a HashCode
from its string representation, see fromString(java.lang.String)
.
Copyright © 2010-2014. All Rights Reserved.