tapeutils.impl
Class SimpleBitProcessor

java.lang.Object
  extended bytapeutils.impl.SimpleBitProcessor
All Implemented Interfaces:
BitProcessor

public class SimpleBitProcessor
extends java.lang.Object
implements BitProcessor

This class provides a processor for bit values.

This implementation collects the bits up into a byte (assume MSB first) and then calls the byte processor for each complete byte.

Author:
hldswrth

Constructor Summary
SimpleBitProcessor(SampleAnalyzer analyzer, ByteProcessor processor)
          Construct the bit processor.
 
Method Summary
 void addBit(int bitStart, int bitEnd, int bitValue)
          Add the bit to the current byte.
 int getBitEndIndex(int number)
          Get the index of the end of the given bit number.
 void getBitNumber(int index, int[] pos)
          Get the bit number at the given position in the sample.
 int getBitStartIndex(int number)
          Get the index of the start of the given bit number.
 int getBitValue(int index)
          Get the bit value at the given position in the sample.
 int getFirstBitStartIndex()
          Get the index of the start of the first bit found in the sample.
 int getLastBitEndIndex()
          Get the index of the end of the last bit extracted from the sample.
 int getLastBitValue()
          Get the value of the last bit extracted.
 int getNumberOfBits()
          Get the number of bits processed.
 void initialize()
          Initialize this object ready for processing a sample.
 int undoLastBit()
          Undo the last bit that was processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleBitProcessor

public SimpleBitProcessor(SampleAnalyzer analyzer,
                          ByteProcessor processor)
Construct the bit processor.

Parameters:
analyzer - The sample analyzer.
processor - The byte processor.
Method Detail

initialize

public void initialize()
Initialize this object ready for processing a sample.

Specified by:
initialize in interface BitProcessor

addBit

public void addBit(int bitStart,
                   int bitEnd,
                   int bitValue)
Add the bit to the current byte.

Specified by:
addBit in interface BitProcessor
Parameters:
bitStart - The start of the bit.
bitEnd - The end of the bit.
bitValue - The bit value.

undoLastBit

public int undoLastBit()
Undo the last bit that was processed.

Specified by:
undoLastBit in interface BitProcessor
Returns:
The index of the end of the bit before last.

getBitValue

public int getBitValue(int index)
Get the bit value at the given position in the sample.

Specified by:
getBitValue in interface BitProcessor
Parameters:
index - The index.
Returns:
The bit value, as 0 or 1, or -1 for no value.

getBitNumber

public void getBitNumber(int index,
                         int[] pos)
Get the bit number at the given position in the sample.

Specified by:
getBitNumber in interface BitProcessor
Parameters:
index - The index.
pos - An array which will contain the bit number and offset from the start of the bit.

getBitStartIndex

public int getBitStartIndex(int number)
Get the index of the start of the given bit number.

Specified by:
getBitStartIndex in interface BitProcessor
Parameters:
number - The bit number.
Returns:
The index.

getBitEndIndex

public int getBitEndIndex(int number)
Get the index of the end of the given bit number.

Specified by:
getBitEndIndex in interface BitProcessor
Parameters:
number - The bit number.
Returns:
The index.

getLastBitValue

public int getLastBitValue()
Get the value of the last bit extracted.

Specified by:
getLastBitValue in interface BitProcessor
Returns:
The last bit value.

getFirstBitStartIndex

public int getFirstBitStartIndex()
Get the index of the start of the first bit found in the sample.

Specified by:
getFirstBitStartIndex in interface BitProcessor
Returns:
The index of the start of the first bit.

getLastBitEndIndex

public int getLastBitEndIndex()
Get the index of the end of the last bit extracted from the sample.

Specified by:
getLastBitEndIndex in interface BitProcessor
Returns:
The index of the end of the last bit.

getNumberOfBits

public int getNumberOfBits()
Get the number of bits processed.

Specified by:
getNumberOfBits in interface BitProcessor
Returns:
The number of bits.