noope.input
Class ArrayBlockReader

java.lang.Object
  |
  +--noope.input.BlockReader
        |
        +--noope.input.ArrayBlockReader

public class ArrayBlockReader
extends BlockReader

This class implements the simplest possible BlockReader. I wrote it because I needed something to test Entity with. It is called ArrayBlockReader, because the constructor is passed an array of entries and an array of subblocks, and that's how they're stored. N.B.: Locations and contexts are not implemented (and presumably, won't be, because this is only intended for testing). All other methods are overridden and do exactly what they should according to the specification of BlockReader. If you try to read beyond the end of the Entry/Subblock list, you get an Array:IndexOutOfBounds exception.

Version:
March 21, 2001
Author:
Miklos Reiter

Constructor Summary
ArrayBlockReader(java.lang.String h, java.lang.String p, java.lang.String[][] e, BlockReader[] sub)
          Construct an ArrayBlockReader from strings and string arrays.
 
Method Summary
 BlockReaderLocation getBlockLocation()
          Similar to getEntryLocation
 BlockReaderContext getContext(BlockReaderLocation loc)
          Converts a Location into a fully-qualified Context object.
 BlockReaderLocation getEntryLocation()
          Returns a BlockReaderLocation object describing the current Entry location.
 java.lang.String getHeader()
          Returns the header of this block.
 BlockReader getNextBlock()
          Returns the next subblock, which is an instance of BlockReader.
 java.lang.String[] getNextEntry()
          Returns the next Entry, as a string array.
 java.lang.String getParameter()
          Returns the parameter of this block.
 boolean hasMoreBlocks()
          Returns TRUE if this block has more Blocks after the one that was last returned
 boolean hasMoreEntries()
          Returns TRUE if this block has more Entries after the one that was last returned
 BlockReader peekNextBlock()
          This method acts as getNextBlock() but does not advance position
 java.lang.String[] peekNextEntry()
          This method acts as getNextEntry() but does not advance position
 void seekFirstBlock()
          Resets the subblock position to the beginning, so that the next call to getNextBlock() will return the first subblock (unless there are no subblocks, in which case an exception is thrown, of course.
 void seekFirstEntry()
          Moves the "entry pointer" back to the first Entry, so that the next call to getNextEntry() will return the first one in the block
 java.lang.String toString()
          This method lists the contents of the BlockReader.
 
Methods inherited from class noope.input.BlockReader
assertEmpty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayBlockReader

public ArrayBlockReader(java.lang.String h,
                        java.lang.String p,
                        java.lang.String[][] e,
                        BlockReader[] sub)
Construct an ArrayBlockReader from strings and string arrays.
Parameters:
h - the header of the block
p - the parameter of the block.
e - is the array of entries; each entry is an array of size 2 of Strings.
sub - is the array of subblocks, each of which is a BlockReader.
Method Detail

getHeader

public java.lang.String getHeader()
Description copied from class: BlockReader
Returns the header of this block. This is in some sense its "title".
Overrides:
getHeader in class BlockReader

getParameter

public java.lang.String getParameter()
Description copied from class: BlockReader
Returns the parameter of this block.
Overrides:
getParameter in class BlockReader

hasMoreEntries

public boolean hasMoreEntries()
Description copied from class: BlockReader
Returns TRUE if this block has more Entries after the one that was last returned
Overrides:
hasMoreEntries in class BlockReader

getNextEntry

public java.lang.String[] getNextEntry()
Description copied from class: BlockReader
Returns the next Entry, as a string array.
Overrides:
getNextEntry in class BlockReader

peekNextEntry

public java.lang.String[] peekNextEntry()
Description copied from class: BlockReader
This method acts as getNextEntry() but does not advance position
Overrides:
peekNextEntry in class BlockReader

seekFirstEntry

public void seekFirstEntry()
Description copied from class: BlockReader
Moves the "entry pointer" back to the first Entry, so that the next call to getNextEntry() will return the first one in the block
Overrides:
seekFirstEntry in class BlockReader

getEntryLocation

public BlockReaderLocation getEntryLocation()
Description copied from class: BlockReader
Returns a BlockReaderLocation object describing the current Entry location. A BlockReaderLocation does not make sense to anyone, except this BlockReader and its parents.
Overrides:
getEntryLocation in class BlockReader

hasMoreBlocks

public boolean hasMoreBlocks()
Description copied from class: BlockReader
Returns TRUE if this block has more Blocks after the one that was last returned
Overrides:
hasMoreBlocks in class BlockReader

getNextBlock

public BlockReader getNextBlock()
Description copied from class: BlockReader
Returns the next subblock, which is an instance of BlockReader. The first time called, it returns the first entry, and thereafter, returns successively later entries. If no more exist, it will throw an exception.
Overrides:
getNextBlock in class BlockReader

peekNextBlock

public BlockReader peekNextBlock()
Description copied from class: BlockReader
This method acts as getNextBlock() but does not advance position
Overrides:
peekNextBlock in class BlockReader

seekFirstBlock

public void seekFirstBlock()
Description copied from class: BlockReader
Resets the subblock position to the beginning, so that the next call to getNextBlock() will return the first subblock (unless there are no subblocks, in which case an exception is thrown, of course.
Overrides:
seekFirstBlock in class BlockReader

getBlockLocation

public BlockReaderLocation getBlockLocation()
Description copied from class: BlockReader
Similar to getEntryLocation
Overrides:
getBlockLocation in class BlockReader

getContext

public BlockReaderContext getContext(BlockReaderLocation loc)
Description copied from class: BlockReader
Converts a Location into a fully-qualified Context object. This means that error messages, reports, etc... can be generated.
Overrides:
getContext in class BlockReader

toString

public java.lang.String toString()
This method lists the contents of the BlockReader. N.B.: this resets the Entry and Subblock positions to 0 and is only intended for debugging purposes.
Overrides:
toString in class java.lang.Object