public final class FluentBitSet extends Object implements Cloneable, Serializable
BitSet with additional operations.
Originally from Apache Commons VFS with more added to act as a fluent replacement for BitSet.
| Constructor and Description |
|---|
FluentBitSet()
Creates a new bit set.
|
FluentBitSet(BitSet set)
Creates a new instance for the given bit set.
|
FluentBitSet(int nbits)
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range
0
through nbits-1. |
| Modifier and Type | Method and Description |
|---|---|
FluentBitSet |
and(BitSet set)
Performs a logical AND of this target bit set with the argument bit set.
|
FluentBitSet |
and(FluentBitSet set)
Performs a logical AND of this target bit set with the argument bit set.
|
FluentBitSet |
andNot(BitSet set)
|
FluentBitSet |
andNot(FluentBitSet set)
|
BitSet |
bitSet()
Gets the wrapped bit set.
|
int |
cardinality()
Returns the number of bits set to
true in this BitSet. |
FluentBitSet |
clear()
Sets all of the bits in this BitSet to
false. |
FluentBitSet |
clear(int... bitIndexArray)
Sets the bits specified by the indexes to
false. |
FluentBitSet |
clear(int bitIndex)
Sets the bit specified by the index to
false. |
FluentBitSet |
clear(int fromIndex,
int toIndex)
Sets the bits from the specified
fromIndex (inclusive) to the specified toIndex (exclusive) to
false. |
Object |
clone()
|
boolean |
equals(Object obj) |
FluentBitSet |
flip(int bitIndex)
Sets the bit at the specified index to the complement of its current value.
|
FluentBitSet |
flip(int fromIndex,
int toIndex)
Sets each bit from the specified
fromIndex (inclusive) to the specified toIndex (exclusive) to the
complement of its current value. |
boolean |
get(int bitIndex)
Returns the value of the bit with the specified index.
|
FluentBitSet |
get(int fromIndex,
int toIndex)
|
int |
hashCode() |
boolean |
intersects(BitSet set)
|
boolean |
intersects(FluentBitSet set)
|
boolean |
isEmpty()
Returns true if this
BitSet contains no bits that are set to true. |
int |
length()
|
int |
nextClearBit(int fromIndex)
Returns the index of the first bit that is set to
false that occurs on or after the specified starting index. |
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. |
FluentBitSet |
or(BitSet set)
Performs a logical OR of this bit set with the bit set argument.
|
FluentBitSet |
or(FluentBitSet... set)
Performs a logical OR of this bit set with the bit set arguments.
|
FluentBitSet |
or(FluentBitSet set)
Performs a logical OR of this bit set with the bit set argument.
|
int |
previousClearBit(int fromIndex)
Returns the index of the nearest bit that is set to
false that occurs on or before the specified starting
index. |
int |
previousSetBit(int fromIndex)
Returns the index of the nearest bit that is set to
true that occurs on or before the specified starting
index. |
FluentBitSet |
set(int... bitIndexArray)
Sets the bit at the specified indexes to
true. |
FluentBitSet |
set(int bitIndex)
Sets the bit at the specified index to
true. |
FluentBitSet |
set(int bitIndex,
boolean value)
Sets the bit at the specified index to the specified value.
|
FluentBitSet |
set(int fromIndex,
int toIndex)
Sets the bits from the specified
fromIndex (inclusive) to the specified toIndex (exclusive) to
true. |
FluentBitSet |
set(int fromIndex,
int toIndex,
boolean value)
Sets the bits from the specified
fromIndex (inclusive) to the specified toIndex (exclusive) to the
specified value. |
FluentBitSet |
setInclusive(int fromIndex,
int toIndex)
Sets the bits from the specified
fromIndex (inclusive) to the specified toIndex (exclusive) to
true. |
int |
size()
Returns the number of bits of space actually in use by this
BitSet to represent bit values. |
IntStream |
stream()
Returns a stream of indices for which this
BitSet contains a bit in the set state. |
byte[] |
toByteArray()
Returns a new byte array containing all the bits in this bit set.
|
long[] |
toLongArray()
Returns a new byte array containing all the bits in this bit set.
|
String |
toString() |
FluentBitSet |
xor(BitSet set)
Performs a logical XOR of this bit set with the bit set argument.
|
FluentBitSet |
xor(FluentBitSet set)
Performs a logical XOR of this bit set with the bit set argument.
|
public FluentBitSet()
false.public FluentBitSet(BitSet set)
set - The bit set to wrap.public FluentBitSet(int nbits)
0
through nbits-1. All bits are initially false.nbits - the initial size of the bit set.NegativeArraySizeException - if the specified initial size is negative.public FluentBitSet and(BitSet set)
true if and only if it both initially had the value true and the
corresponding bit in the bit set argument also had the value true.set - a bit set.public FluentBitSet and(FluentBitSet set)
true if and only if it both initially had the value true and the
corresponding bit in the bit set argument also had the value true.set - a bit set.public FluentBitSet andNot(BitSet set)
public FluentBitSet andNot(FluentBitSet set)
public int cardinality()
true in this BitSet.true in this BitSet.public FluentBitSet clear()
false.public FluentBitSet clear(int... bitIndexArray)
false.bitIndexArray - the index of the bit to be cleared.IndexOutOfBoundsException - if the specified index is negative.public FluentBitSet clear(int bitIndex)
false.bitIndex - the index of the bit to be cleared.IndexOutOfBoundsException - if the specified index is negative.public FluentBitSet clear(int fromIndex, int toIndex)
fromIndex (inclusive) to the specified toIndex (exclusive) to
false.fromIndex - index of the first bit to be cleared.toIndex - index after the last bit to be cleared.IndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or
fromIndex is larger than toIndex.public FluentBitSet flip(int bitIndex)
bitIndex - the index of the bit to flip.IndexOutOfBoundsException - if the specified index is negative.public FluentBitSet flip(int fromIndex, int toIndex)
fromIndex (inclusive) to the specified toIndex (exclusive) to the
complement of its current value.fromIndex - index of the first bit to flip.toIndex - index after the last bit to flip.IndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or
fromIndex is larger than toIndex.public boolean get(int bitIndex)
true if the bit with the index
bitIndex is currently set in this BitSet; otherwise, the result is false.bitIndex - the bit index.IndexOutOfBoundsException - if the specified index is negative.public FluentBitSet get(int fromIndex, int toIndex)
BitSet composed of bits from this BitSet from fromIndex (inclusive) to
toIndex (exclusive).fromIndex - index of the first bit to include.toIndex - index after the last bit to include.BitSet from a range of this BitSet.IndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or
fromIndex is larger than toIndex.public boolean intersects(BitSet set)
public boolean intersects(FluentBitSet set)
public boolean isEmpty()
BitSet contains no bits that are set to true.BitSet is empty.public int length()
BitSet: the index of the highest set bit in the BitSet plus one.
Returns zero if the BitSet contains no set bits.BitSet.public int nextClearBit(int fromIndex)
false that occurs on or after the specified starting index.fromIndex - the index to start checking from (inclusive).IndexOutOfBoundsException - if the specified index is negative.public int nextSetBit(int fromIndex)
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 in a BitSet, 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
}
}
fromIndex - the index to start checking from (inclusive).-1 if there is no such bit.IndexOutOfBoundsException - if the specified index is negative.public FluentBitSet or(BitSet set)
true if and only if it either already had the value true or the corresponding bit in
the bit set argument has the value true.set - a bit set.public FluentBitSet or(FluentBitSet... set)
true if and only if it either already had the value true or the corresponding bit in
the bit set argument has the value true.set - a bit set.public FluentBitSet or(FluentBitSet set)
true if and only if it either already had the value true or the corresponding bit in
the bit set argument has the value true.set - a bit set.public int previousClearBit(int fromIndex)
false that occurs on or before the specified starting
index. If no such bit exists, or if -1 is given as the starting index, then -1 is returned.fromIndex - the index to start checking from (inclusive).-1 if there is no such bit.IndexOutOfBoundsException - if the specified index is less than -1.public int previousSetBit(int fromIndex)
true that occurs on or before the specified starting
index. If no such bit exists, or if -1 is given as the starting index, then -1 is returned.
To iterate over the true bits in a BitSet, use the following loop:
for (int i = bs.length(); (i = bs.previousSetBit(i-1)) >= 0; ) {
// operate on index i here
}
fromIndex - the index to start checking from (inclusive)-1 if there is no such bitIndexOutOfBoundsException - if the specified index is less than -1public FluentBitSet set(int... bitIndexArray)
true.bitIndexArray - a bit index array.IndexOutOfBoundsException - if the specified index is negative.public FluentBitSet set(int bitIndex)
true.bitIndex - a bit indexIndexOutOfBoundsException - if the specified index is negativepublic FluentBitSet set(int bitIndex, boolean value)
bitIndex - a bit index.value - a boolean value to set.IndexOutOfBoundsException - if the specified index is negative.public FluentBitSet set(int fromIndex, int toIndex)
fromIndex (inclusive) to the specified toIndex (exclusive) to
true.fromIndex - index of the first bit to be set.toIndex - index after the last bit to be set.IndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or
fromIndex is larger than toIndex.public FluentBitSet set(int fromIndex, int toIndex, boolean value)
fromIndex (inclusive) to the specified toIndex (exclusive) to the
specified value.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.IndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or
fromIndex is larger than toIndex.public FluentBitSet setInclusive(int fromIndex, int toIndex)
fromIndex (inclusive) to the specified toIndex (exclusive) to
true.fromIndex - index of the first bit to be settoIndex - index of the last bit to be setIndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or
fromIndex is larger than toIndexpublic int size()
BitSet to represent bit values. The maximum
element in the set is the size - 1st element.public IntStream stream()
BitSet contains 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.
public byte[] toByteArray()
More precisely, if:
byte[] bytes = s.toByteArray();bytes.length == (s.length()+7)/8 ands.get(n) == ((bytes[n/8] & (1<<(n%8))) != 0)n < 8 * bytes.length.public long[] toLongArray()
More precisely, if:
long[] longs = s.toLongArray();longs.length == (s.length()+63)/64 ands.get(n) == ((longs[n/64] & (1L<<(n%64))) != 0)n < 64 * longs.length.public FluentBitSet xor(BitSet set)
true if and only if one of the following statements holds:
true, and the corresponding bit in the argument has the value
false.
false, and the corresponding bit in the argument has the value
true.
set - a bit setpublic FluentBitSet xor(FluentBitSet set)
true if and only if one of the following statements holds:
true, and the corresponding bit in the argument has the value
false.
false, and the corresponding bit in the argument has the value
true.
set - a bit setCopyright © 2001–2023 The Apache Software Foundation. All rights reserved.