Class BitString

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected BitSet bitSet
      Set of bit values.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitString()
      Constructs a new BitString that has no bits set.
      BitString​(int nbits)
      Constructs a new BitString that has no bits set, initialised to accommodate the given number of bits.
    • Field Detail

      • bitSet

        protected BitSet bitSet
        Set of bit values.
    • Constructor Detail

      • BitString

        public BitString()
        Constructs a new BitString that has no bits set.
      • BitString

        public BitString​(int nbits)
        Constructs a new BitString that has no bits set, initialised to accommodate the given number of bits.
        Parameters:
        nbits - initial number of bits
    • Method Detail

      • length

        public int length()
        Returns the number of bits represented by this bit string.
        Returns:
        int length
      • get

        public boolean get​(int bitInteger)
        Gets whether the bit for the given number is set or not.
        Parameters:
        bitInteger - the number of the bit to be got
        Returns:
        whether the bit is set
      • set

        public BitString set​(int bitInteger)
        Sets the bit for the given number to true.
        Parameters:
        bitInteger - the number of the bit to be set
        Returns:
        this
      • clear

        public BitString clear()
        Clears all bits in this bit string.
        Returns:
        this
      • clear

        public BitString clear​(int bitInteger)
        Clears the bit for the given number to false.
        Parameters:
        bitInteger - the number of the bit to be cleared
        Returns:
        this
      • nextSetBit

        public 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. 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 }
      • toString

        public String toString()
        Returns a string describing this set of bits, using numbers for bits. For example, "{1,3,4}" could be the string for a set of four bits in which the second bit is currently not set. The bits are described in order.
        Overrides:
        toString in class Object
        Returns:
        String that describes this object
      • equals

        public boolean equals​(Object obj)
        Compares some other object to this one for equality by value (not reference).
        Overrides:
        equals in class Object
        Parameters:
        obj - other object
        Returns:
        whether this object has the same value as obj
      • hashCode

        public int hashCode()
        Gets a hash code value for this object.
        Overrides:
        hashCode in class Object
        Returns:
        hash code of the value
      • clone

        public BitString clone()
        Constructs a copy of this.
        Specified by:
        clone in interface DataObject
        Specified by:
        clone in class AbstractDataObject
        Returns:
        a new object that is a deep copy of this object; for immutable objects, the same object may optionally be returned.
      • copyOf

        public static BitString copyOf​(BitString from)
        Creates a new object of this type, initialising its field values from those of the given object.
        Parameters:
        from - the object from which to copy
        Returns:
        new BitString