FluentBitSet
- public final class org.apache.commons.lang3.util.FluentBitSet implements Cloneable, Serializable[source]
A fluent
BitSetwith additional operations.Originally from Apache Commons VFS with more added to act as a fluent replacement for
java.util.BitSet.- Since:
3.13.0
Constructors
Creates a new bit set. |
|
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range |
|
Creates a new instance for the given bit set. |
- public FluentBitSet(int nbits)[source]
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range
0throughnbits-1. All bits are initiallyfalse.- Parameters:
nbits – The initial size of the bit set.
- Throws:
java.lang.NegativeArraySizeException – Thrown if the specified initial size is negative.
Methods
Performs a logical AND of this target bit set with the argument bit set. |
|
Performs a logical AND of this target bit set with the argument bit set. |
|
Clears all of the bits in this |
|
Clears all of the bits in this |
|
Gets the wrapped bit set. |
|
Returns the number of bits set to |
|
Sets all of the bits in this BitSet to |
|
Sets the bit specified by the index to |
|
Sets the bits from the specified |
|
Sets the bits specified by the indexes to |
|
Cloning this |
|
Sets the bit at the specified index to the complement of its current value. |
|
Sets each bit from the specified |
|
Gets the value of the bit with the specified index. |
|
Gets a new |
|
Returns true if the specified |
|
Returns true if the specified |
|
Tests whether if this |
|
Returns the “logical size” of this |
|
Returns the index of the first bit that is set to |
|
Returns the index of the first bit that is set to |
|
Performs a logical OR of this bit set with the bit set argument. |
|
Performs a logical OR of this bit set with the bit set argument. |
|
Performs a logical OR of this bit set with the bit set arguments. |
|
Returns the index of the nearest bit that is set to |
|
Returns the index of the nearest bit that is set to |
|
Sets the bit at the specified index to |
|
Sets the bit at the specified index to the specified value. |
|
Sets the bits from the specified |
|
Sets the bits from the specified |
|
Sets the bit at the specified indexes to |
|
Sets the bits from the specified |
|
Returns the number of bits of space actually in use by this |
|
Returns a stream of indices for which this |
|
Returns a new byte array containing all the bits in this bit set. |
|
Returns a new byte array containing all the bits in this bit set. |
|
Performs a logical XOR of this bit set with the bit set argument. |
|
Performs a logical XOR of this bit set with the bit set argument. |
- public FluentBitSet and(BitSet set)[source]
Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value
trueif and only if it both initially had the valuetrueand the corresponding bit in the bit set argument also had the valuetrue.- Parameters:
set – A bit set.
- Returns:
thisinstance.
- public FluentBitSet and(FluentBitSet set)[source]
Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value
trueif and only if it both initially had the valuetrueand the corresponding bit in the bit set argument also had the valuetrue.- Parameters:
set – A bit set.
- Returns:
thisinstance.
- public FluentBitSet andNot(BitSet set)[source]
Clears all of the bits in this
BitSetwhose corresponding bit is set in the specifiedBitSet.
- public FluentBitSet andNot(FluentBitSet set)[source]
Clears all of the bits in this
BitSetwhose corresponding bit is set in the specifiedBitSet.
- public int cardinality()[source]
Returns the number of bits set to
truein thisBitSet.- Returns:
The number of bits set to
truein thisBitSet.
- public FluentBitSet clear()[source]
Sets all of the bits in this BitSet to
false.- Returns:
thisinstance.
- public FluentBitSet clear(int bitIndex)[source]
Sets the bit specified by the index to
false.- Parameters:
bitIndex – The index of the bit to be cleared.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- Returns:
thisinstance.
- public FluentBitSet clear(int fromIndex, int toIndex)[source]
Sets the bits from the specified
fromIndex(inclusive) to the specifiedtoIndex(exclusive) tofalse.- Parameters:
fromIndex – index of the first bit to be cleared.
toIndex – index after the last bit to be cleared.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
fromIndexis negative, ortoIndexis negative, orfromIndexis larger thantoIndex.- Returns:
thisinstance.
- public FluentBitSet clear(int... bitIndexArray)[source]
Sets the bits specified by the indexes to
false.- Parameters:
bitIndexArray – The index of the bit to be cleared.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- Returns:
thisinstance.
- @Override public Object clone()[source]
Cloning this
BitSetproduces a newBitSetthat is equal to it. The clone of the bit set is another bit set that has exactly the same bits set totrueas this bit set.- Returns:
A clone of this bit set
- See also:
- public FluentBitSet flip(int bitIndex)[source]
Sets the bit at the specified index to the complement of its current value.
- Parameters:
bitIndex – The index of the bit to flip.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- Returns:
thisinstance.
- public FluentBitSet flip(int fromIndex, int toIndex)[source]
Sets each bit from the specified
fromIndex(inclusive) to the specifiedtoIndex(exclusive) to the complement of its current value.- Parameters:
fromIndex – index of the first bit to flip.
toIndex – index after the last bit to flip.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
fromIndexis negative, ortoIndexis negative, orfromIndexis larger thantoIndex.- Returns:
thisinstance.
- public boolean get(int bitIndex)[source]
Gets the value of the bit with the specified index. The value is
trueif the bit with the indexbitIndexis currently set in thisBitSet; otherwise, the result isfalse.- Parameters:
bitIndex – The bit index.
- Returns:
The value of the bit with the specified index.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- public FluentBitSet get(int fromIndex, int toIndex)[source]
Gets a new
BitSetcomposed of bits from thisBitSetfromfromIndex(inclusive) totoIndex(exclusive).
- public boolean intersects(BitSet set)[source]
Returns true if the specified
BitSethas any bits set totruethat are also set totruein thisBitSet.
- public boolean intersects(FluentBitSet set)[source]
Returns true if the specified
BitSethas any bits set totruethat are also set totruein thisBitSet.
- public boolean isEmpty()[source]
Tests whether if this
BitSetcontains no bits that are set totrue.- Returns:
boolean indicating whether this
BitSetis empty.
- public int length()[source]
Returns the “logical size” of this
BitSet: the index of the highest set bit in theBitSetplus one. Returns zero if theBitSetcontains no set bits.- Returns:
The logical size of this
BitSet.
- public int nextClearBit(int fromIndex)[source]
Returns the index of the first bit that is set to
falsethat occurs on or after the specified starting index.- Parameters:
fromIndex – The index to start checking from (inclusive).
- Returns:
The index of the next clear bit.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- public int nextSetBit(int fromIndex)[source]
Returns the index of the first bit that is set to
truethat occurs on or after the specified starting index. If no such bit exists then-1is returned.To iterate over the
truebits in aBitSet, use the following loop:for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) { // operate on index i here if (i == Integer.MAX_VALUE) { break; // or (i+1) would overflow } }
- Parameters:
fromIndex – The index to start checking from (inclusive).
- Returns:
The index of the next set bit, or
-1if there is no such bit.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- public FluentBitSet or(BitSet set)[source]
Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
trueif and only if it either already had the valuetrueor the corresponding bit in the bit set argument has the valuetrue.- Parameters:
set – A bit set.
- Returns:
thisinstance.
- public FluentBitSet or(FluentBitSet set)[source]
Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
trueif and only if it either already had the valuetrueor the corresponding bit in the bit set argument has the valuetrue.- Parameters:
set – A bit set.
- Returns:
thisinstance.
- public FluentBitSet or(FluentBitSet... set)[source]
Performs a logical OR of this bit set with the bit set arguments. This bit set is modified so that a bit in it has the value
trueif and only if it either already had the valuetrueor the corresponding bit in the bit set argument has the valuetrue.- Parameters:
set – A bit set.
- Returns:
thisinstance.
- public int previousClearBit(int fromIndex)[source]
Returns the index of the nearest bit that is set to
falsethat occurs on or before the specified starting index. If no such bit exists, or if-1is given as the starting index, then-1is returned.- Parameters:
fromIndex – The index to start checking from (inclusive).
- Returns:
The index of the previous clear bit, or
-1if there is no such bit.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is less than
-1.
- public int previousSetBit(int fromIndex)[source]
Returns the index of the nearest bit that is set to
truethat occurs on or before the specified starting index. If no such bit exists, or if-1is given as the starting index, then-1is returned.To iterate over the
truebits in aBitSet, use the following loop:for (int i = bs.length(); (i = bs.previousSetBit(i-1)) >= 0; ) { // operate on index i here }
- Parameters:
fromIndex – The index to start checking from (inclusive)
- Returns:
The index of the previous set bit, or
-1if there is no such bit- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is less than
-1.
- public FluentBitSet set(int bitIndex)[source]
Sets the bit at the specified index to
true.- Parameters:
bitIndex – A bit index
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- Returns:
thisinstance.
- public FluentBitSet set(int bitIndex, boolean value)[source]
Sets the bit at the specified index to the specified value.
- Parameters:
bitIndex – A bit index.
value – A boolean value to set.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- Returns:
thisinstance.
- public FluentBitSet set(int fromIndex, int toIndex)[source]
Sets the bits from the specified
fromIndex(inclusive) to the specifiedtoIndex(exclusive) totrue.- Parameters:
fromIndex – index of the first bit to be set.
toIndex – index after the last bit to be set.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
fromIndexis negative, ortoIndexis negative, orfromIndexis larger thantoIndex.- Returns:
thisinstance.
- public FluentBitSet set(int fromIndex, int toIndex, boolean value)[source]
Sets the bits from the specified
fromIndex(inclusive) to the specifiedtoIndex(exclusive) to the specified value.- Parameters:
fromIndex – index of the first bit to be set.
toIndex – index after the last bit to be set.
value – value to set the selected bits to.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
fromIndexis negative, ortoIndexis negative, orfromIndexis larger thantoIndex.- Returns:
thisinstance.
- public FluentBitSet set(int... bitIndexArray)[source]
Sets the bit at the specified indexes to
true.- Parameters:
bitIndexArray – A bit index array.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the specified index is negative.
- Returns:
thisinstance.
- public FluentBitSet setInclusive(int fromIndex, int toIndex)[source]
Sets the bits from the specified
fromIndex(inclusive) to the specifiedtoIndex(inclusive) totrue.- Parameters:
fromIndex – index of the first bit to be set
toIndex – index of the last bit to be set
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
fromIndexis negative, ortoIndexis negative, orfromIndexis larger thantoIndex.- Returns:
thisinstance.
- public int size()[source]
Returns the number of bits of space actually in use by this
BitSetto represent bit values. The maximum element in the set is the size - 1st element.- Returns:
The number of bits currently in this bit set.
- public IntStream stream()[source]
Returns a stream of indices for which this
BitSetcontains a bit in the set state. The indices are returned in order, from lowest to highest. The size of the stream is the number of bits in the set state, equal to the value returned by the#cardinality()method.The bit set must remain constant during the execution of the terminal stream operation. Otherwise, the result of the terminal stream operation is undefined.
- Returns:
A stream of integers representing set indices.
- Since:
1.8
- public byte[] toByteArray()[source]
Returns a new byte array containing all the bits in this bit set.
More precisely, if:
byte[] bytes = s.toByteArray();then
bytes.length == (s.length()+7)/8ands.get(n) == ((bytes[n/8] & (1<<(n%8))) != 0)for all
n < 8 * bytes.length.
- Returns:
A byte array containing a little-endian representation of all the bits in this bit set
- public long[] toLongArray()[source]
Returns a new byte array containing all the bits in this bit set.
More precisely, if:
long[] longs = s.toLongArray();then
longs.length == (s.length()+63)/64ands.get(n) == ((longs[n/64] & (1L<<(n%64))) != 0)for all
n < 64 * longs.length.
- Returns:
A byte array containing a little-endian representation of all the bits in this bit set
- public FluentBitSet xor(BitSet set)[source]
Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
trueif and only if one of the following statements holds:The bit initially has the value
true, and the corresponding bit in the argument has the valuefalse.The bit initially has the value
false, and the corresponding bit in the argument has the valuetrue.
- Parameters:
set – A bit set
- Returns:
thisinstance.
- public FluentBitSet xor(FluentBitSet set)[source]
Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
trueif and only if one of the following statements holds:The bit initially has the value
true, and the corresponding bit in the argument has the valuefalse.The bit initially has the value
false, and the corresponding bit in the argument has the valuetrue.
- Parameters:
set – A bit set
- Returns:
thisinstance.