com.sun.jini.outrigger.snaplogstore
Class ByteArrayWrapper

java.lang.Object
  extended by com.sun.jini.outrigger.snaplogstore.ByteArrayWrapper
All Implemented Interfaces:
Serializable

 class ByteArrayWrapper
extends Object
implements Serializable

In the backend Uuids 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 Uuids to and from byte[16]s.


Field Summary
private  int hash
          A 32 bit hash of uuid
private  byte[] uuid
          The 16 bytes being wrapped
 
Constructor Summary
ByteArrayWrapper(byte[] v)
          Create a new ByteArrayWrapper that wraps the provided array.
 
Method Summary
 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[].
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uuid

private byte[] uuid
The 16 bytes being wrapped


hash

private int hash
A 32 bit hash of uuid

Constructor Detail

ByteArrayWrapper

ByteArrayWrapper(byte[] v)
Create a new ByteArrayWrapper that wraps the provided array.

Parameters:
v - The array to wrap.
Throws:
IllegalArgumentException - if v.length is not 16.
Method Detail

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toByteArray

static byte[] toByteArray(Uuid uuid)
Encode the passed Uuid in to a newly allocated byte[16] in big-endian byte order.

Parameters:
uuid - the Uuid to encode.
Returns:
A new byte[16] initialized to the same bit pattern as uuid.
Throws:
NullPointerException - if uuid is null.

toUuid

static Uuid toUuid(byte[] bits)
Create a new Uuid that matches the bit pattern in the passed byte[]. Assumes the bit pattern is in big-endian byte order.

Parameters:
bits - the byte[] with bit pattern
Returns:
A new Uuid that matches the passed byte[].
Throws:
NullPointerException - if uuid is null.
IllegalArgumentException - if bits.length is not 16.

hashFor

static int hashFor(byte[] uuid)
Compute an equivalent hash to Uuid.

Throws:
IllegalArgumentException - if uuid.length is not 16.


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.