class ByteArrayWrapper extends Object implements Serializable
Uuid
s are represented using
byte[16]
s. This works fine is most places, but
sometimes we need to use a Uuid
as a key in a hash
table. Arrays do not make good hash table keys so we wrap the array
in one of these to provide suitable implementations of
hashCode
and equals
.
This method also has utility methods for converting
Uuid
s to and from byte[16]
s.
Modifier and Type | Field and Description |
---|---|
private int |
hash
A 32 bit hash of uuid
|
private byte[] |
uuid
The 16 bytes being wrapped
|
Constructor and Description |
---|
ByteArrayWrapper(byte[] v)
Create a new
ByteArrayWrapper that
wraps the provided array. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
int |
hashCode() |
(package private) static int |
hashFor(byte[] uuid)
Compute an equivalent hash to
Uuid . |
(package private) static byte[] |
toByteArray(Uuid uuid)
Encode the passed
Uuid in to a newly allocated
byte[16] in big-endian byte order. |
(package private) static Uuid |
toUuid(byte[] bits)
Create a new
Uuid that matches the bit pattern
in the passed byte[] . |
private byte[] uuid
private int hash
ByteArrayWrapper(byte[] v)
ByteArrayWrapper
that
wraps the provided array.v
- The array to wrap.IllegalArgumentException
- if v.length
is
not 16.static byte[] toByteArray(Uuid uuid)
Uuid
in to a newly allocated
byte[16]
in big-endian byte order.uuid
- the Uuid
to encode.byte[16]
initialized to the
same bit pattern as uuid
.NullPointerException
- if uuid
is
null
.static Uuid toUuid(byte[] bits)
Uuid
that matches the bit pattern
in the passed byte[]
. Assumes the bit pattern
is in big-endian byte order.bits
- the byte[]
with bit patternUuid
that matches the
passed byte[]
.NullPointerException
- if uuid
is
null
.IllegalArgumentException
- if bits.length
is not 16.static int hashFor(byte[] uuid)
Uuid
.IllegalArgumentException
- if uuid.length
is not 16.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.