Class BitPool

java.lang.Object
io.github.olyutorskii.aletojio.BitPool

public class BitPool extends Object
Bit pool.

Pushing any size of bits to bit-queue tail.

Chopping any size of bits from bit-queue head.

From MSB to LSB.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default bit size.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    BitPool(int bitLength)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Return max available size.
    boolean
    Chop boolean value from head of queue.
    byte
    Chop byte value from head of queue.
    int
    Chop int value from head of queue.
    int
    chopInt(int bitCt)
    Chop bits and store to lower bits of int value from head of queue.
    long
    Chop long value from head of queue.
    long
    chopLong(int bitCt)
    Chop bits and store to lower bits of long value from head of queue.
    void
    clear bit pool.
    boolean
    Return true if has remaining spaces.
    boolean
    Return true if empty.
    void
    pushBoolean(boolean bool)
    Push boolean value to tail of queue.
    void
    pushByte(byte bArg)
    Push byte value to tail of queue.
    void
    pushInt(int iArg)
    Push int value to tail of queue.
    void
    pushInt(int iArg, int bitCt)
    Push lower bits of int value to tail of queue.
    void
    pushLong(long lArg)
    Push long value to tail of queue.
    void
    pushLong(long lArg, int bitCt)
    Push lower bits of long value to tail of queue.
    int
    Return remaining spaces.
    int
    Resturn bit size.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • BitPool

      public BitPool()
      Constructor.

      bit size is 512.

    • BitPool

      public BitPool(int bitLength) throws IllegalArgumentException
      Constructor.
      Parameters:
      bitLength - bit length
      Throws:
      IllegalArgumentException - length is not positive value
  • Method Details

    • size

      public int size()
      Resturn bit size.
      Returns:
      bit size
    • capacity

      public int capacity()
      Return max available size.
      Returns:
      capacity size
    • isEmpty

      public boolean isEmpty()
      Return true if empty.
      Returns:
      true if empty
    • remaining

      public int remaining()
      Return remaining spaces.
      Returns:
      remaining spaces.
    • hasRemaining

      public boolean hasRemaining()
      Return true if has remaining spaces.
      Returns:
      true if has remaining spaces
    • clear

      public void clear()
      clear bit pool.
    • pushBoolean

      public void pushBoolean(boolean bool) throws IndexOutOfBoundsException
      Push boolean value to tail of queue.
      Parameters:
      bool - boolean value
      Throws:
      IndexOutOfBoundsException - no more space
    • chopBoolean

      public boolean chopBoolean() throws IndexOutOfBoundsException
      Chop boolean value from head of queue.
      Returns:
      boolean value
      Throws:
      IndexOutOfBoundsException - not enough bits
    • pushInt

      public void pushInt(int iArg) throws IndexOutOfBoundsException
      Push int value to tail of queue.
      Parameters:
      iArg - int value
      Throws:
      IndexOutOfBoundsException - no more space
    • pushInt

      public void pushInt(int iArg, int bitCt) throws IndexOutOfBoundsException
      Push lower bits of int value to tail of queue.
      Parameters:
      iArg - int value
      bitCt - bits from LSB
      Throws:
      IndexOutOfBoundsException - bits is not positive or no more space or over 32
    • chopInt

      public int chopInt() throws IndexOutOfBoundsException
      Chop int value from head of queue.
      Returns:
      int value
      Throws:
      IndexOutOfBoundsException - not enough bits
    • chopInt

      public int chopInt(int bitCt) throws IndexOutOfBoundsException
      Chop bits and store to lower bits of int value from head of queue.
      Parameters:
      bitCt - bits
      Returns:
      lower bits filled int value
      Throws:
      IndexOutOfBoundsException - not enough bits or bits is not positive or over 32
    • pushLong

      public void pushLong(long lArg) throws IndexOutOfBoundsException
      Push long value to tail of queue.
      Parameters:
      lArg - long value
      Throws:
      IndexOutOfBoundsException - no more space
    • pushLong

      public void pushLong(long lArg, int bitCt) throws IndexOutOfBoundsException
      Push lower bits of long value to tail of queue.
      Parameters:
      lArg - long value
      bitCt - bits from LSB
      Throws:
      IndexOutOfBoundsException - bits is not positive or no more space or over 64
    • chopLong

      public long chopLong() throws IndexOutOfBoundsException
      Chop long value from head of queue.
      Returns:
      long value
      Throws:
      IndexOutOfBoundsException - not enough bits
    • chopLong

      public long chopLong(int bitCt) throws IndexOutOfBoundsException
      Chop bits and store to lower bits of long value from head of queue.
      Parameters:
      bitCt - bits
      Returns:
      lower bits filled long value
      Throws:
      IndexOutOfBoundsException - not enough bits or bits is not positive or over 64
    • pushByte

      public void pushByte(byte bArg) throws IndexOutOfBoundsException
      Push byte value to tail of queue.
      Parameters:
      bArg - byte value
      Throws:
      IndexOutOfBoundsException - no more space
    • chopByte

      public byte chopByte() throws IndexOutOfBoundsException
      Chop byte value from head of queue.
      Returns:
      byte value
      Throws:
      IndexOutOfBoundsException - not enough bits