noope.input
Class BlockReader

java.lang.Object
  |
  +--noope.input.BlockReader
Direct Known Subclasses:
ArrayBlockReader, StringBlockReader

public abstract class BlockReader
extends java.lang.Object

This is an abstract class used for reading in the law and entity definitions. This might be from a file, but is abstract, so it could be from anything, for example, a GUI editor program. This is a generic class, could be used for anything using this block format. (This is the syntax accepted by StringBlockReader.)

#any whitespace seperates tokens
#string values can use double quote marks to delimit
#use \" to put a quote mark inside a string
#comments start with a # symbol and extend until end of line
#[] denotes optional

header [parameter]
{
key1 value1  # this is an entry
key2 value2
key3 value3
...
keyN valueN
subheader1 [subparameter1]	# this is a block
{
subkey1 subvalue1
...
subsubheader1 [subsubparameter1]
{
...
}
}
header2 [subparameter2]
{
...
}
}
The format used for reading in a Physics object is as follows.
 
# this file is case sensitive
# comments start with hash

physics
{
laws
{
law 
{
[name "string"]
constant1 
constant2 
...
}
}
entities
{
entity []
{
[name "string"]
position 
velocity 
inertialMass 
}

Law1 
{
...
}
Law2
{
...
}
}
}
Here is an example of using the file format:
physics
{
laws
{
law Gravity
{
name "Gravity"
G 6.67e-23
}
}
entities
{
entity
{
# defaults to Entity class
name "Electron" position (0.5,54.5,45.1)
velocity 0	  # promotes to (0,0,0)
inertialMass 9.1e-31

Gravity
{
mass 9.1e-31
}
Electric
{
charge -1.6e-19
}
}
}
}

Version:
Miklos Reiter 19-May-2001: updated javadoc comments Modified by Miklos Reiter 21-Mar-2001: added peekNextEntry and peekNextBlock methods. Modified again by Paul Evans 27-Apr-2001: added toString
Author:
Paul Evans

Constructor Summary
BlockReader()
           
 
Method Summary
 void assertEmpty()
          Throws exception unless BlockReader is empty.
abstract  BlockReaderLocation getBlockLocation()
          Similar to getEntryLocation
abstract  BlockReaderContext getContext(BlockReaderLocation loc)
          Converts a Location into a fully-qualified Context object.
abstract  BlockReaderLocation getEntryLocation()
          Returns a BlockReaderLocation object describing the current Entry location.
abstract  java.lang.String getHeader()
          Returns the header of this block.
abstract  BlockReader getNextBlock()
          Returns the next subblock, which is an instance of BlockReader.
abstract  java.lang.String[] getNextEntry()
          Returns the next Entry, as a string array.
abstract  java.lang.String getParameter()
          Returns the parameter of this block.
abstract  boolean hasMoreBlocks()
          Returns TRUE if this block has more Blocks after the one that was last returned
abstract  boolean hasMoreEntries()
          Returns TRUE if this block has more Entries after the one that was last returned
abstract  BlockReader peekNextBlock()
          This method acts as getNextBlock() but does not advance position
abstract  java.lang.String[] peekNextEntry()
          This method acts as getNextEntry() but does not advance position
abstract  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.
abstract  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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockReader

public BlockReader()
Method Detail

getHeader

public abstract java.lang.String getHeader()
                                    throws BlockReaderException
Returns the header of this block. This is in some sense its "title".

getParameter

public abstract java.lang.String getParameter()
                                       throws BlockReaderException
Returns the parameter of this block.

hasMoreEntries

public abstract boolean hasMoreEntries()
                                throws BlockReaderException
Returns TRUE if this block has more Entries after the one that was last returned

getNextEntry

public abstract java.lang.String[] getNextEntry()
                                         throws BlockReaderException
Returns the next Entry, as a string array.

peekNextEntry

public abstract java.lang.String[] peekNextEntry()
                                          throws BlockReaderException
This method acts as getNextEntry() but does not advance position

seekFirstEntry

public abstract void seekFirstEntry()
                             throws BlockReaderException
Moves the "entry pointer" back to the first Entry, so that the next call to getNextEntry() will return the first one in the block

getEntryLocation

public abstract BlockReaderLocation getEntryLocation()
                                              throws BlockReaderException
Returns a BlockReaderLocation object describing the current Entry location. A BlockReaderLocation does not make sense to anyone, except this BlockReader and its parents.

hasMoreBlocks

public abstract boolean hasMoreBlocks()
                               throws BlockReaderException
Returns TRUE if this block has more Blocks after the one that was last returned

getNextBlock

public abstract BlockReader getNextBlock()
                                  throws BlockReaderException
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.

peekNextBlock

public abstract BlockReader peekNextBlock()
                                   throws BlockReaderException
This method acts as getNextBlock() but does not advance position

seekFirstBlock

public abstract void seekFirstBlock()
                             throws BlockReaderException
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.

getBlockLocation

public abstract BlockReaderLocation getBlockLocation()
                                              throws BlockReaderException
Similar to getEntryLocation

getContext

public abstract BlockReaderContext getContext(BlockReaderLocation loc)
                                       throws BlockReaderException
Converts a Location into a fully-qualified Context object. This means that error messages, reports, etc... can be generated.

assertEmpty

public void assertEmpty()
                 throws BRLoadingException
Throws exception unless BlockReader is empty.