LimeWire Collection Component API

org.limewire.collection
Class BitNumbers

java.lang.Object
  extended by org.limewire.collection.BitNumbers

public class BitNumbers
extends Object

Allows storage & retrieval of numbers based on the index of an on or off bit in a byte[] or a hexadecimal String representation of that byte[].


Field Summary
static BitNumbers EMPTY_BN
          A convenient shared immutable empty BitNumbers.
 
Constructor Summary
BitNumbers(byte[] data)
          Constructs a BitNumbers backed by the given byte[].
BitNumbers(int size)
          Constructs a BitNumbers large enough to store numbers up to size.
BitNumbers(String hexString)
          Constructs a BitNumbers based on the given hex string.
 
Method Summary
 boolean equals(Object obj)
           
 int getMax()
          Returns the maximum number that can be stored in this BitNumbers.
 int hashCode()
           
 boolean isEmpty()
          Returns true if no set bits exist.
 boolean isSet(int idx)
          Returns true if the correct bit is set.
 void set(int idx)
          Sets the bit corresponding to the index.
static BitNumbers synchronizedBitNumbers(BitNumbers delegate)
           
 byte[] toByteArray()
          Returns the byte array that BitNumbers is backed off of.
 String toHexString()
          A hexadecimal representation of the byte[]
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_BN

public static final BitNumbers EMPTY_BN
A convenient shared immutable empty BitNumbers.

Constructor Detail

BitNumbers

public BitNumbers(byte[] data)
Constructs a BitNumbers backed by the given byte[].


BitNumbers

public BitNumbers(int size)
Constructs a BitNumbers large enough to store numbers up to size.


BitNumbers

public BitNumbers(String hexString)
           throws IllegalArgumentException
Constructs a BitNumbers based on the given hex string. This accepts a nibble for the last element, thus: FF corresponds to elements 0 through 8 being on FFF corresponds to elements 0 through 12 being on (implies below) FFF0 corresponds to elements 0 through 12 being on also

Throws:
IllegalArgumentException
Method Detail

isSet

public boolean isSet(int idx)
Returns true if the correct bit is set.


getMax

public int getMax()
Returns the maximum number that can be stored in this BitNumbers.


set

public void set(int idx)
Sets the bit corresponding to the index.


toByteArray

public byte[] toByteArray()
Returns the byte array that BitNumbers is backed off of.


isEmpty

public boolean isEmpty()
Returns true if no set bits exist.


equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toHexString

public String toHexString()
A hexadecimal representation of the byte[]


toString

public String toString()
Overrides:
toString in class Object

synchronizedBitNumbers

public static BitNumbers synchronizedBitNumbers(BitNumbers delegate)

LimeWire Collection Component API

Copyright © 2008 Lime Wire LLC. All Rights Reserved.