Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.squawk.util
Class BitSet

    java.lang.Object
      com.sun.squawk.util.BitSet

    public final class BitSet

extends Object

This class provides mechanisms for manipulating a bit set.

Constructor Summary
`BitSet()` Creates a new BitSet instance whose underlying byte array is controlled by the instance.
`BitSet(byte[] bits)` Creates a new BitSet instance whose underlying byte array is controlled by the client of the instance.

Method Summary
`boolean` | `areBitsExternal()`
`int` | `cardinality()` Returns the number of bits set to 1 in this `BitSet`.
`void` | `clear()` Clears all of the bits in this BitSet.
`void` | `clear(int bitIndex)` Clears the bit at a given index.
`void` | `copyInto(byte[] bits)` Copies the bit set representation into a provided byte array.
`boolean` | `equals(Object obj)` Compares this object against the specified object.
`boolean` | `get(int bitIndex)` Returns the value of the bit with the specified index.
`int` | `hashCode()` Returns a hash code value for this bit set.
`int` | `length()` Returns the "logical size" of this `BitSet`: the index of the highest set bit in the `BitSet` plus one.
`int` | `nextSetBit(int fromIndex)` Returns the index of the first bit that is set to `true` that occurs on or after the specified starting index.
`void` | `or(BitSet other)` Performs a logical OR of this bit set with the bit set argument.
`void` | `or(BitSet other, int shift)` Performs a logical OR of this bit set with a given bit set.
`void` | `set(int bitIndex)` Sets the bit at a given index.
`int` | `size()` Returns the number of bits of space actually in use by this `BitSet` to represent bit values.
`String` | `toString()` Returns a string representation of this bit set.
`protected void` | `validateIndex(int bitIndex)` Determines if a given bit index is valid.

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### BitSet

    public BitSet()

  Creates a new BitSet instance whose underlying byte array is controlled by the instance. Only this type of BitSet will grow as necessary and will never throw an IndexOutOfBoundsException if a given bitIndex is greater than the current physical size of the underlying byte array.

### BitSet

    public BitSet(byte[] bits)

  Creates a new BitSet instance whose underlying byte array is controlled by the client of the instance. This type of BitSet will throw an IndexOutOfBoundsException if a given bitIndex is greater than the highest bit that can be expressed in the underlying byte array.

  Parameters:
    `bits` - the underlying byte array

Method Detail

### areBitsExternal

    public boolean areBitsExternal()

### validateIndex

    protected void validateIndex(int bitIndex)

  Determines if a given bit index is valid.

  Parameters:
    `bitIndex` - the bit index to test
  Throws:
    `IndexOutOfBoundsException` - is the given index is negative

### copyInto

    public void copyInto(byte[] bits)

  Copies the bit set representation into a provided byte array. The number of bytes copied is equal to the minimum of length of the provided byte array and the internal byte array.

  Parameters:
    `bits` - the byte array to copy into
  Throws:
    `NullPointerException` - if the given buffer is null.

### length

    public int length()

  Returns the "logical size" of this `BitSet`: the index of the highest set bit in the `BitSet` plus one.

  Returns:
    the logical size of this `BitSet`.

### size

    public int size()

  Returns the number of bits of space actually in use by this `BitSet` to represent bit values.

  Returns:
    the number of bits currently in this bit set.

### set

    public void set(int bitIndex)

  Sets the bit at a given index.

  Parameters:
    `bitIndex` - the index of the bit to set
  Throws:
    `IndexOutOfBoundsException` - if the given bit index is negative or if this is an `external` BitSet instance and `bitIndex >= this.size()`

### clear

    public void clear(int bitIndex)

  Clears the bit at a given index.

  Parameters:
    `bitIndex` - the index of the bit to clear
  Throws:
    `IndexOutOfBoundsException` - if the given bit index is negative

### clear

    public void clear()

  Clears all of the bits in this BitSet.

### get

    public boolean get(int bitIndex)

  Returns the value of the bit with the specified index. The value is `true` if the bit with the index `bitIndex` is currently set in this `BitSet`; otherwise, the result is `false`.

  Parameters:
    `bitIndex` - the bit index.
  Returns:
    the value of the bit with the specified index.
  Throws:
    `IndexOutOfBoundsException` - if the given bit index is negative

### cardinality

    public int cardinality()

  Returns the number of bits set to 1 in this `BitSet`.

  Returns:
    the number of bits set to 1 in this `BitSet`.

### or

    public void or(BitSet other)

  Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit at index n in this set is 1 if and only if it was already set or the bit at index n in `other` was set. The semantics of this operation can be expressed as:

  >           this = this | other;

  Parameters:
    `other` - a bit set

### or

    public void or(BitSet other,
                   int shift)

  Performs a logical OR of this bit set with a given bit set. The semantics of this operation can be expressed as:

  >           this = this | (other >= 0 ? other << offset : other >> offset);

  Parameters:
    `other` - a bit set
    `shift` - the amount by which other should be logically shifted before being or'ed with this bit set

### equals

    public boolean equals(Object obj)

  Compares this object against the specified object. The result is `true` if and only if the argument is not `null` and is a `Bitset` object that has exactly the same set of bits set to `true` as this bit set. That is, for every nonnegative `int` index `k`,

      ((BitSet)obj).get(k) == this.get(k)

  must be true. The current sizes of the two bit sets are not compared.

  Overrides the `equals` method of `Object`.

  Overrides:
    `equals` in class `Object`
  Parameters:
    `obj` - the object to compare with.
  Returns:
    `true` if the objects are the same; `false` otherwise.
  See Also:
    `BitSet.size()`

### hashCode

    public int hashCode()

  Returns a hash code value for this bit set.

  Overrides:
    `hashCode` in class `Object`
  Returns:
    a hash code value for this bit set.
  See Also:
    `Object.equals(java.lang.Object)`, `Hashtable`

### nextSetBit

    public int nextSetBit(int fromIndex)

  Returns the index of the first bit that is set to `true` that occurs on or after the specified starting index. If no such bit exists then -1 is returned. To iterate over the `true` bits use the following loop:

  >      for (int i = oopMap.nextSetBit(0); i >= 0; i = oopMap.nextSetBit(i + 1)) {
  >          // operate on index i here
  >      }

  Parameters:
    `fromIndex` - the index to start checking from (inclusive). This must be positive
  Returns:
    the index of the next set bit.
  Throws:
    `IndexOutOfBoundsException` - if the specified index is negative.

### toString

    public String toString()

  Returns a string representation of this bit set. For every index for which this `BitSet` contains a bit in the set state, the decimal representation of that index is included in the result. Such indices are listed in order from lowest to highest, separated by ", " (a comma and a space) and surrounded by braces, resulting in the usual mathematical notation for a set of integers.

  Overrides the `toString` method of `Object`.

  Example:

       BitSet drPepper = new BitSet();

  Now `drPepper.toString()` returns "`{}`".

       drPepper.set(2);

  Now `drPepper.toString()` returns "`{2}`".

       drPepper.set(4);
       drPepper.set(10);

  Now `drPepper.toString()` returns "`{2, 4, 10}`".

  Overrides:
    `toString` in class `Object`
  Returns:
    a string representation of this bit set.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

"
For updated information see the Java FRC site
"