Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile Client
11g Release 1 (11.1.1)

E17503-02

oracle.adfnmc.java.util
Class BitSet

java.lang.Object
  extended by oracle.adfnmc.java.util.BitSet

public class BitSet
extends java.lang.Object

The BitSet class implements a bit field. Each element in a BitSet can be on(1) or off(0). A BitSet is created with a given size and grows when this size is exceeded. Growth is always rounded to a 64 bit boundary.


Constructor Summary
BitSet()
          Create a new BitSet with size equal to 64 bits
BitSet(int nbits)
          Create a new BitSet with size equal to nbits.
 
Method Summary
 void and(BitSet bs)
          Performs the logical AND of this BitSet with another BitSet.
 void andNot(BitSet bs)
          Clears all bits in the receiver which are also set in the parameter BitSet.
 int cardinality()
          Answers the number of bits that are true in this bitset.
 void clear()
          Clears all the bits in this bitset.
 void clear(int pos)
          Clears the bit at index pos.
 void clear(int pos1, int pos2)
          Clears the bits starting from pos1 to pos2.
 boolean equals(java.lang.Object obj)
          Compares the argument to this BitSet and answer if they are equal.
 void flip(int pos)
          Flips the bit at index pos.
 void flip(int pos1, int pos2)
          Flips the bits starting from pos1 to pos2.
 boolean get(int pos)
          Retrieve the bit at index pos.
 BitSet get(int pos1, int pos2)
          Retrieves the bits starting from pos1 to pos2 and answers back a new bitset made of these bits.
 int hashCode()
          Computes the hash code for this BitSet.
 boolean intersects(BitSet bs)
          Checks if these two bitsets have at least one bit set to true in the same position.
 boolean isEmpty()
          Answers true if all the bits in this bitset are set to false.
 int length()
          Returns the number of bits up to and including the highest bit set.
 int nextClearBit(int pos)
          Answers the position of the first bit that is false on or after pos
 int nextSetBit(int pos)
          Answers the position of the first bit that is true on or after pos
 void or(BitSet bs)
          Performs the logical OR of this BitSet with another BitSet.
 void set(int pos)
          Sets the bit at index pos to 1.
 void set(int pos, boolean val)
          Sets the bit at index pos to the value.
 void set(int pos1, int pos2)
          Sets the bits starting from pos1 to pos2.
 void set(int pos1, int pos2, boolean val)
          Sets the bits starting from pos1 to pos2 to the given boolean value.
 int size()
          Answers the number of bits this bitset has.
 java.lang.String toString()
          Answers a string containing a concise, human-readable description of the receiver.
 void xor(BitSet bs)
          Performs the logical XOR of this BitSet with another BitSet.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitSet

public BitSet()
Create a new BitSet with size equal to 64 bits

See Also:
clear(int), set(int), clear(), clear(int, int), set(int, boolean), set(int, int), set(int, int, boolean)

BitSet

public BitSet(int nbits)
Create a new BitSet with size equal to nbits. If nbits is not a multiple of 64, then create a BitSet with size nbits rounded to the next closest multiple of 64.

Parameters:
nbits - the size of the bit set
Throws:
java.lang.NegativeArraySizeException - if nbits < 0.
See Also:
clear(int), set(int), clear(), clear(int, int), set(int, boolean), set(int, int), set(int, int, boolean)
Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares the argument to this BitSet and answer if they are equal. The object must be an instance of BitSet with the same bits set.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the BitSet object to compare
Returns:
A boolean indicating whether or not this BitSet and obj are equal
See Also:
hashCode()

hashCode

public int hashCode()
Computes the hash code for this BitSet.

Overrides:
hashCode in class java.lang.Object
Returns:
The int representing the hash code for this bit set.
See Also:
equals(java.lang.Object), Hashtable

get

public boolean get(int pos)
Retrieve the bit at index pos. Grows the BitSet if pos > size.

Parameters:
pos - the index of the bit to be retrieved
Returns:
true if the bit at pos is set, false otherwise
Throws:
java.lang.IndexOutOfBoundsException - when pos < 0
See Also:
clear(int), set(int), clear(), clear(int, int), set(int, boolean), set(int, int), set(int, int, boolean)

get

public BitSet get(int pos1,
                  int pos2)
Retrieves the bits starting from pos1 to pos2 and answers back a new bitset made of these bits. Grows the BitSet if pos2 > size.

Parameters:
pos1 - beginning position
pos2 - ending position
Returns:
new bitset
Throws:
java.lang.IndexOutOfBoundsException - when pos1 or pos2 is negative, or when pos2 is not smaller than pos1
See Also:
get(int)

set

public void set(int pos)
Sets the bit at index pos to 1. Grows the BitSet if pos > size.

Parameters:
pos - the index of the bit to set
Throws:
java.lang.IndexOutOfBoundsException - when pos < 0
See Also:
clear(int), clear(), clear(int, int)

set

public void set(int pos,
                boolean val)
Sets the bit at index pos to the value. Grows the BitSet if pos > size.

Parameters:
pos - the index of the bit to set
val - value to set the bit
Throws:
java.lang.IndexOutOfBoundsException - when pos < 0
See Also:
set(int)

set

public void set(int pos1,
                int pos2)
Sets the bits starting from pos1 to pos2. Grows the BitSet if pos2 > size.

Parameters:
pos1 - beginning position
pos2 - ending position
Throws:
java.lang.IndexOutOfBoundsException - when pos1 or pos2 is negative, or when pos2 is not smaller than pos1
See Also:
set(int)

set

public void set(int pos1,
                int pos2,
                boolean val)
Sets the bits starting from pos1 to pos2 to the given boolean value. Grows the BitSet if pos2 > size.

Parameters:
pos1 - beginning position
pos2 - ending position
val - value to set these bits
Throws:
java.lang.IndexOutOfBoundsException - when pos1 or pos2 is negative, or when pos2 is not smaller than pos1
See Also:
set(int,int)

clear

public void clear()
Clears all the bits in this bitset.

See Also:
clear(int), clear(int, int)

clear

public void clear(int pos)
Clears the bit at index pos. Grows the BitSet if pos > size.

Parameters:
pos - the index of the bit to clear
Throws:
java.lang.IndexOutOfBoundsException - when pos < 0
See Also:
clear(int, int)

clear

public void clear(int pos1,
                  int pos2)
Clears the bits starting from pos1 to pos2. Grows the BitSet if pos2 > size.

Parameters:
pos1 - beginning position
pos2 - ending position
Throws:
java.lang.IndexOutOfBoundsException - when pos1 or pos2 is negative, or when pos2 is not smaller than pos1
See Also:
clear(int)

flip

public void flip(int pos)
Flips the bit at index pos. Grows the BitSet if pos > size.

Parameters:
pos - the index of the bit to flip
Throws:
java.lang.IndexOutOfBoundsException - when pos < 0
See Also:
flip(int, int)

flip

public void flip(int pos1,
                 int pos2)
Flips the bits starting from pos1 to pos2. Grows the BitSet if pos2 > size.

Parameters:
pos1 - beginning position
pos2 - ending position
Throws:
java.lang.IndexOutOfBoundsException - when pos1 or pos2 is negative, or when pos2 is not smaller than pos1
See Also:
flip(int)

intersects

public boolean intersects(BitSet bs)
Checks if these two bitsets have at least one bit set to true in the same position.

Parameters:
bs - BitSet used to calculate intersect
Returns:
true if bs intersects with this BitSet, false otherwise

and

public void and(BitSet bs)
Performs the logical AND of this BitSet with another BitSet.

Parameters:
bs - BitSet to AND with
See Also:
or(oracle.adfnmc.java.util.BitSet), xor(oracle.adfnmc.java.util.BitSet)

andNot

public void andNot(BitSet bs)
Clears all bits in the receiver which are also set in the parameter BitSet.

Parameters:
bs - BitSet to ANDNOT with

or

public void or(BitSet bs)
Performs the logical OR of this BitSet with another BitSet.

Parameters:
bs - BitSet to OR with
See Also:
xor(oracle.adfnmc.java.util.BitSet), and(oracle.adfnmc.java.util.BitSet)

xor

public void xor(BitSet bs)
Performs the logical XOR of this BitSet with another BitSet.

Parameters:
bs - BitSet to XOR with
See Also:
or(oracle.adfnmc.java.util.BitSet), and(oracle.adfnmc.java.util.BitSet)

size

public int size()
Answers the number of bits this bitset has.

Returns:
The number of bits contained in this BitSet.
See Also:
length()

length

public int length()
Returns the number of bits up to and including the highest bit set.

Returns:
the length of the BitSet

toString

public java.lang.String toString()
Answers a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class java.lang.Object
Returns:
A comma delimited list of the indices of all bits that are set.

nextSetBit

public int nextSetBit(int pos)
Answers the position of the first bit that is true on or after pos

Parameters:
pos - the starting position (inclusive)
Returns:
-1 if there is no bits that are set to true on or after pos.

nextClearBit

public int nextClearBit(int pos)
Answers the position of the first bit that is false on or after pos

Parameters:
pos - the starting position (inclusive)
Returns:
the position of the next bit set to false, even if it is further than this bitset's size.

isEmpty

public boolean isEmpty()
Answers true if all the bits in this bitset are set to false.

Returns:
true if the BitSet is empty, false otherwise

cardinality

public int cardinality()
Answers the number of bits that are true in this bitset.

Returns:
the number of true bits in the set

Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile Client
11g Release 1 (11.1.1)

E17503-02

Copyright © 2011, Oracle and/or its affiliates. All rights reserved.