LimeWire collection component api

org.limewire.collection
Class BitNumbers

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

public class BitNumbers
extends java.lang.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(java.lang.String hexString)
          Constructs a BitNumbers based on the given hex string.
 
Method Summary
 boolean equals(java.lang.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.
 java.lang.String toHexString()
          A hexadecimal representation of the byte[].
 java.lang.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(java.lang.String hexString)
           throws java.lang.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:
java.lang.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(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toHexString

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


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

synchronizedBitNumbers

public static BitNumbers synchronizedBitNumbers(BitNumbers delegate)

LimeWire collection component api

Copyright © 2009 Lime Wire LLC. All Rights Reserved.