Package io.bytestreams.codec.iso8583
Interface Bitmap
- All Known Implementing Classes:
MultiBlockBitmap,SingleBlockBitmap
public interface Bitmap
Represents a set of bits indicating the presence or absence of data elements in a message. Bit
indices are 1-based.
-
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Returns the total number of bits in the bitmap.intReturns the number of bits that are set.booleanclear(int bit) Clears the given bit.booleanget(int bit) Returns whether the given bit is set.default booleanisExtensionBit(int bit) Returns whether the given bit is an extension indicator.booleanset(int bit) Sets the given bit.stream()Returns a stream of the 1-based indices of all set bits.byte[]Converts the bitmap to a byte array in big-endian bit order (bit 1 is the MSB of byte 0).
-
Method Details
-
capacity
int capacity()Returns the total number of bits in the bitmap.- Returns:
- the total number of bits.
-
get
boolean get(int bit) Returns whether the given bit is set.- Parameters:
bit- the 1-based bit index to check.- Returns:
trueif the bit is set,falseotherwise.- Throws:
IllegalArgumentException- ifbitis less than 1 or greater thancapacity().
-
set
boolean set(int bit) Sets the given bit.- Parameters:
bit- the 1-based bit index to set.- Returns:
trueif the bit was not already set,falseotherwise.- Throws:
IllegalArgumentException- ifbitis less than 1 or greater thancapacity().
-
clear
boolean clear(int bit) Clears the given bit.- Parameters:
bit- the 1-based bit index to clear.- Returns:
trueif the bit was set,falseotherwise.- Throws:
IllegalArgumentException- ifbitis less than 1 or greater thancapacity().
-
cardinality
int cardinality()Returns the number of bits that are set.- Returns:
- the number of bits set.
-
stream
IntStream stream()Returns a stream of the 1-based indices of all set bits.- Returns:
- a stream of set bit indices.
-
toByteArray
byte[] toByteArray()Converts the bitmap to a byte array in big-endian bit order (bit 1 is the MSB of byte 0).- Returns:
- the byte array representation of the bitmap.
-
isExtensionBit
default boolean isExtensionBit(int bit) Returns whether the given bit is an extension indicator. Extension indicators signal that additional bitmap blocks follow and cannot be used as data fields.- Parameters:
bit- the 1-based bit index to check.- Returns:
trueif the bit is an extension indicator,falseotherwise.
-