Package io.nayuki.qrcodegen
Class BitBuffer
- java.lang.Object
-
- io.nayuki.qrcodegen.BitBuffer
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class BitBuffer extends java.lang.Object implements java.lang.CloneableAn appendable sequence of bits (0s and 1s). Mainly used byQrSegment.
-
-
Constructor Summary
Constructors Constructor Description BitBuffer()Constructs an empty bit buffer (length 0).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendBits(int val, int len)Appends the specified number of low-order bits of the specified value to this buffer.voidappendData(BitBuffer bb)Appends the content of the specified bit buffer to this buffer.intbitLength()Returns the length of this sequence, which is a non-negative value.BitBufferclone()Returns a new copy of this buffer.intgetBit(int index)Returns the bit at the specified index, yielding 0 or 1.
-
-
-
Method Detail
-
bitLength
public int bitLength()
Returns the length of this sequence, which is a non-negative value.- Returns:
- the length of this sequence
-
getBit
public int getBit(int index)
Returns the bit at the specified index, yielding 0 or 1.- Parameters:
index- the index to get the bit at- Returns:
- the bit at the specified index
- Throws:
java.lang.IndexOutOfBoundsException- if index < 0 or index ≥ bitLength
-
appendBits
public void appendBits(int val, int len)Appends the specified number of low-order bits of the specified value to this buffer. Requires 0 ≤ len ≤ 31 and 0 ≤ val < 2len.- Parameters:
val- the value to appendlen- the number of low-order bits in the value to take- Throws:
java.lang.IllegalArgumentException- if the value or number of bits is out of rangejava.lang.IllegalStateException- if appending the data would make bitLength exceed Integer.MAX_VALUE
-
appendData
public void appendData(BitBuffer bb)
Appends the content of the specified bit buffer to this buffer.- Parameters:
bb- the bit buffer whose data to append (notnull)- Throws:
java.lang.NullPointerException- if the bit buffer isnulljava.lang.IllegalStateException- if appending the data would make bitLength exceed Integer.MAX_VALUE
-
clone
public BitBuffer clone()
Returns a new copy of this buffer.- Overrides:
clonein classjava.lang.Object- Returns:
- a new copy of this buffer (not
null)
-
-