Class BitArray

java.lang.Object
org.openhab.core.io.transport.modbus.BitArray
All Implemented Interfaces:
Iterable<Boolean>

@NonNullByDefault public class BitArray extends Object implements Iterable<Boolean>
Class that implements a collection for bits
Author:
Sami Salonen - Initial contribution
  • Constructor Details

    • BitArray

      public BitArray(int nbits)
    • BitArray

      public BitArray(boolean... bits)
    • BitArray

      public BitArray(BitSet wrapped, int length)
  • Method Details

    • getBit

      public boolean getBit(int index)
      Returns the state of the bit at the given index Index 0 matches LSB (rightmost) bit

      Parameters:
      index - the index of the bit to be returned.
      Returns:
      true if the bit at the specified index is set, false otherwise.
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds.
    • setBit

      public void setBit(int index, boolean value)
    • size

      public int size()
      Get number of bits stored in this instance
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • iterator

      public Iterator<Boolean> iterator()
      Specified by:
      iterator in interface Iterable<Boolean>
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • toBinaryString

      public String toBinaryString()
      Get data as binary string For example, 0010
      Returns:
      string representing the data