Class BitField


  • public class BitField
    extends Object
    Container of a byte array representing set and unset bits.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitField​(byte[] bitfield, int size)
      Creates a new BitField that represents size bits as set by the given byte array.
      BitField​(int size)
      Creates a new BitField that represents size unset bits.
    • Constructor Detail

      • BitField

        public BitField​(int size)
        Creates a new BitField that represents size unset bits.
      • BitField

        public BitField​(byte[] bitfield,
                        int size)
        Creates a new BitField that represents size bits as set by the given byte array. This will make a copy of the array. Extra bytes will be ignored.
        Throws:
        IndexOutOfBoundsException - if give byte array is not large enough.
    • Method Detail

      • getFieldBytes

        public byte[] getFieldBytes()
        This returns the actual byte array used. Changes to this array affect this BitField. Note that some bits at the end of the byte array are supposed to be always unset if they represent bits bigger then the size of the bitfield. Caller should synch on this and copy!
      • size

        public int size()
        Return the size of the BitField. The returned value is one bigger then the last valid bit number (since bit numbers are counted from zero).
      • set

        public void set​(int bit)
        Sets the given bit to true.
        Throws:
        IndexOutOfBoundsException - if bit is smaller then zero bigger then size (inclusive).
      • clear

        public void clear​(int bit)
        Sets the given bit to false.
        Throws:
        IndexOutOfBoundsException - if bit is smaller then zero bigger then size (inclusive).
        Since:
        0.9.22
      • setAll

        public void setAll()
        Sets all bits to true.
        Since:
        0.9.21
      • get

        public boolean get​(int bit)
        Return true if the bit is set or false if it is not.
        Throws:
        IndexOutOfBoundsException - if bit is smaller then zero bigger then size (inclusive).
      • count

        public int count()
        Return the number of set bits.
      • complete

        public boolean complete()
        Return true if all bits are set.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
        Since:
        0.9.33
      • equals

        public boolean equals​(Object o)
        Overrides:
        equals in class Object
        Since:
        0.9.33