Breakout Problem Set Javadocs

breakout
Class LoaderUtils

java.lang.Object
  extended bybreakout.LoaderUtils

public class LoaderUtils
extends java.lang.Object

Utility class to help Loader process information in a boardfile.


Constructor Summary
LoaderUtils()
           
 
Method Summary
static java.util.Vector extractArgs(java.lang.String line, java.lang.String label)
          Given the label "fooArgs", extracts "5" "4" and "%" out of the string, [foo p="5" q="0" fooArgs="5, 4, %foo"].
static java.util.Vector extractClassObjectArrays(java.util.Vector args, Board board)
          Extracts a Class[] and a Object[] out of a Vector of constructor arguments, and returns them in a Vector as elements 0 and 1, respectively.
static java.lang.String extractValue(java.lang.String line, java.lang.String label)
          Given the label "q", extracts "0" out of the string, [foo p="5" q="0"]
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoaderUtils

public LoaderUtils()
Method Detail

extractValue

public static java.lang.String extractValue(java.lang.String line,
                                            java.lang.String label)
                                     throws BadBoardFormatException
Given the label "q", extracts "0" out of the string, [foo p="5" q="0"]

Parameters:
line - The line of text to be parsed for the value of label
label - The String labeling the desired value in the line of text.
Returns:
A String containing the value labeled by label.
Throws:
BadBoardFormatException - if the label can't be found in the string, or if the value trails off the end of the string before encountering a closing double-quote(").

extractArgs

public static java.util.Vector extractArgs(java.lang.String line,
                                           java.lang.String label)
                                    throws BadBoardFormatException,
                                           java.lang.NumberFormatException
Given the label "fooArgs", extracts "5" "4" and "%" out of the string, [foo p="5" q="0" fooArgs="5, 4, %foo"].

Casts all arguments not beginning with a percent sign(%) into Integers. Arguments beginning with a percent sign(%) become simply the String "%". Arguments must be comma-delimited; spaces between arguments don't matter.

Parameters:
line - The line of text to be parsed for the args labeled with label
label - The String labeling the desired args in the line of text.
Returns:
A Vector of String and Integer objects found labeled by label.
Throws:
BadBoardFormatException - if label cannot be found in the string, or if the group of arguments labeled by label trails off the end of the string before the closing double-quote(").
java.lang.NumberFormatException - if one of the comma-delimited arguments does not begin with a percent sign(%) and cannot be cast into an Integer.

extractClassObjectArrays

public static java.util.Vector extractClassObjectArrays(java.util.Vector args,
                                                        Board board)
Extracts a Class[] and a Object[] out of a Vector of constructor arguments, and returns them in a Vector as elements 0 and 1, respectively.

This is useful when trying to get an instance of a class whose name you do not know explicitly, but can read from a file, and whose arguments you have recorded in a Vector. The getConstructor method of class Class takes an array of Class objects defining the order and types of the arguments passed to the desired constructor. Once in ownership of the desired Constructor object, an instance is obtained using the getInstance method, which takes an array of Object objects as the actual arguments to be passed to the constructor.

This method assumes you have previously used LoaderUtils.extractArgs(String line, String label) to get a Vector of arguments. This method takes that Vector, and hands you back the corresponding Class[] and Object[].

Parameters:
args - A Vector containing only Integer objects and String objects starting with "%"
board - The board this object will eventually be added to; into which "%" becomes translated.
Returns:
A Vector whose first element(index 0) is a Class[] and whose second element(1) is a Object[].

Breakout Problem Set Javadocs