a3
Class BitVector

java.lang.Object
  extended by a3.BitVector
All Implemented Interfaces:
java.lang.Iterable<java.lang.Boolean>

public class BitVector
extends java.lang.Object
implements java.lang.Iterable<java.lang.Boolean>

An efficient implementation of an extensible array of bits. Based on BitSet, but provides an interface more like ArrayList or Vector.

Author:
Dexter

Constructor Summary
BitVector()
          Constructs a BitSet with no elements.
 
Method Summary
 void add(boolean value)
          Adds a new bit to the end of the BitVector.
 BitVector clone()
          Returns an independent deep copy of this BitVector.
 boolean get(int index)
          Returns the bit at index index.
 java.util.Iterator<java.lang.Boolean> iterator()
          Returns an iterator over this BitVector.
 void set(int index, boolean value)
          Sets the bit at index index to the specified value.
 int size()
          Returns the size (number of bits) in this BitVector.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitVector

public BitVector()
Constructs a BitSet with no elements.

Method Detail

set

public void set(int index,
                boolean value)
         throws java.lang.ArrayIndexOutOfBoundsException
Sets the bit at index index to the specified value. The index parameter must be at least 0 and less than size().

Parameters:
index - index of the bit to set
value - boolean value to set it to
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of bounds

get

public boolean get(int index)
            throws java.lang.ArrayIndexOutOfBoundsException
Returns the bit at index index. The index parameter must be at least 0 and less than size().

Parameters:
index - index of the bit to get
Returns:
the value of the bit at index index
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of bounds

size

public int size()
Returns the size (number of bits) in this BitVector.

Returns:
the size (number of bits) in this BitVector

add

public void add(boolean value)
Adds a new bit to the end of the BitVector.

Parameters:
value - the value of the bit to add

iterator

public java.util.Iterator<java.lang.Boolean> iterator()
Returns an iterator over this BitVector.

Specified by:
iterator in interface java.lang.Iterable<java.lang.Boolean>
Returns:
an iterator over this BitVector
See Also:
Iterator

clone

public BitVector clone()
Returns an independent deep copy of this BitVector.

Overrides:
clone in class java.lang.Object
Returns:
an independent deep copy of this BitVector