AP® Computer Science Marine Biology Simulation

Class MBSFactory

java.lang.Object
  |
  +--MBSFactory

public class MBSFactory
extends java.lang.Object

AP® Computer Science Marine Biology Simulation:
The MBSFactory class provides a set of static methods for constructing objects in the Marine Biology Simulation program, such as fish and environments, as well as tracking the available classes to use in constructing those objects.

The MBSFactory class is copyright© 2002 College Entrance Examination Board (www.collegeboard.com).

Version:
1 August 2002

Constructor Summary
MBSFactory()
           
 
Method Summary
static void addBoundedEnvClassNames(java.lang.String[] classNames)
          Adds bounded environment classes to the set maintained by the factory.
protected static void addClassesToFactory(java.lang.String[] classNames, java.lang.String whichCategory)
          Helper to add new classes to the factory.
static void addEnvObjClassNames(java.lang.String[] classNames)
          Adds environment object classes to the set maintained by the factory.
static void addUnboundedEnvClassNames(java.lang.String[] classNames)
          Adds unbounded environment classes to the set maintained by the factory.
static java.util.Set boundedEnvClasses()
          Returns the set of bounded environment classes known to the factory.
static Environment constructEnv(java.lang.Class cls)
          Creates an instance of an Environment using the default constructor of the given class.
static Environment constructEnv(java.lang.Class cls, int numRows, int numCols)
          Creates an instance of an Environment using the 2-argument constructor of the given class.
static java.lang.Object constructEnvObject(java.lang.Class cls, Environment env, Location loc)
          Creates an instance of the given environment object class using a two-argument constructor that takes an environment and a location.
static java.lang.Object constructEnvObject(java.lang.Class cls, Environment env, Location loc, Direction dir)
          Creates an instance of the given environment object class using a three-argument constructor that takes an environment, a location, and a direction.
static java.lang.Object constructEnvObject(java.lang.Class cls, Environment env, Location loc, Direction dir, java.awt.Color color)
          Creates an instance of the given environment object class using a four-argument constructor that takes an environment, a location, a diredction, and a color.
static java.lang.Object constructObject(java.lang.Class cls, java.lang.Class[] parameterTypes, java.lang.Object[] parameters)
          Creates an object of the given class.
static java.util.Set envObjectClasses()
          Returns the set of environment object classes known to the factory.
protected static boolean hasCorrectCtor(java.lang.Class cls, java.lang.Class requiredCls, java.lang.Class[] ctorParameters)
          Verifies that a class has the required constructor and is properly assignable.
static boolean hasFourArgCtor(java.lang.Class cls)
          Reports wehther a given environment object class has an accessible four-arg constructor that takes Environment, Location, Direction, and Color.
static boolean isValidEnvClass(java.lang.Class cls, java.lang.Class[] ctorParameters)
          Verifies that a class has the required constructor and is properly assignable to Environment.
static boolean isValidEnvObjectClass(java.lang.Class cls, java.lang.Class[] ctorParameters)
          Verifies that a class has the required constructor and is properly assignable to Locatable.
static java.util.Set unboundedEnvClasses()
          Returns the set of unbounded environment classes known to the factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MBSFactory

public MBSFactory()
Method Detail

constructObject

public static java.lang.Object constructObject(java.lang.Class cls,
                                               java.lang.Class[] parameterTypes,
                                               java.lang.Object[] parameters)
Creates an object of the given class.
Parameters:
cls - class of new object
parameterTypes - parameter types expected by constructor for class
parameters - actual parameters to pass to constructor
Returns:
the newly created object
Throws:
MBSException - if an object of the specified class cannot be constructed with the specified parameters

constructEnvObject

public static java.lang.Object constructEnvObject(java.lang.Class cls,
                                                  Environment env,
                                                  Location loc)
Creates an instance of the given environment object class using a two-argument constructor that takes an environment and a location.
Parameters:
cls - class of new environment object
env - environment in which this object will act
loc - location the object will occupy
Returns:
the newly created environment object
Throws:
MBSException - if an object of the specified class cannot be constructed with the specified parameters

constructEnvObject

public static java.lang.Object constructEnvObject(java.lang.Class cls,
                                                  Environment env,
                                                  Location loc,
                                                  Direction dir)
Creates an instance of the given environment object class using a three-argument constructor that takes an environment, a location, and a direction.
Parameters:
cls - class of new environment object
env - environment in which this object will act
loc - location the object will occupy
dir - direction the object will face
Returns:
the newly created environment object
Throws:
MBSException - if an object of the specified class cannot be constructed with the specified parameters

constructEnvObject

public static java.lang.Object constructEnvObject(java.lang.Class cls,
                                                  Environment env,
                                                  Location loc,
                                                  Direction dir,
                                                  java.awt.Color color)
Creates an instance of the given environment object class using a four-argument constructor that takes an environment, a location, a diredction, and a color.
Parameters:
cls - class of new environment object
env - environment in which this object will act
loc - location the object will occupy
dir - direction the object will face
color - color of the object
Returns:
the newly created environment object
Throws:
MBSException - if an object of the specified class cannot be constructed with the specified parameters

constructEnv

public static Environment constructEnv(java.lang.Class cls)
Creates an instance of an Environment using the default constructor of the given class. Used to create unbounded environments; no dimensions are specified.
Parameters:
cls - class of new environment
Returns:
the newly created environment
Throws:
MBSException - if an environment of the specified class cannot be constructed

constructEnv

public static Environment constructEnv(java.lang.Class cls,
                                       int numRows,
                                       int numCols)
Creates an instance of an Environment using the 2-argument constructor of the given class. Used to create bounded environments; dimensions must be specified.
Parameters:
cls - class of new environment
Returns:
the newly created environment
Throws:
MBSException - if an environment of the specified class cannot be constructed with the given number of rows and columns

envObjectClasses

public static java.util.Set envObjectClasses()
Returns the set of environment object classes known to the factory. Classes are added to the factory via the addEnvObjClassNames method.
Returns:
the set of environment object classes

boundedEnvClasses

public static java.util.Set boundedEnvClasses()
Returns the set of bounded environment classes known to the factory. Classes are added to the factory via the addBoundedClassNames method.
Returns:
the set of bounded environment classes

unboundedEnvClasses

public static java.util.Set unboundedEnvClasses()
Returns the set of unbounded environment classes known to the factory. Classes are added to the factory via the addUnboundedClassNames method.
Returns:
the set of unbounded environment classes

addClassesToFactory

protected static void addClassesToFactory(java.lang.String[] classNames,
                                          java.lang.String whichCategory)
Helper to add new classes to the factory. Classes are specified by string name. For each name, error-checking is done to ensure the name class exists, is accessible, and has the proper constructor. If all checks out, the class is added to the appropriate set maintained by the factory. On errors, a message is printed and the class is skipped.
Parameters:
classNames - an array of class names
whichCategory - descriptive name for category (e.g., "bounded environment")

addEnvObjClassNames

public static void addEnvObjClassNames(java.lang.String[] classNames)
Adds environment object classes to the set maintained by the factory. If the named class cannot be found or the class is not a proper Locatable object, an error message is printed and the class is not added to the set.
Parameters:
classNames - an array of environment object class names

addBoundedEnvClassNames

public static void addBoundedEnvClassNames(java.lang.String[] classNames)
Adds bounded environment classes to the set maintained by the factory. If the named class cannot be found or the class is not a proper bounded environment, an error message is printed, and that class is not added to the set.
Parameters:
classNames - an array of bounded environment class names

addUnboundedEnvClassNames

public static void addUnboundedEnvClassNames(java.lang.String[] classNames)
Adds unbounded environment classes to the set maintained by the factory. If the named class cannot be found or the class is not a proper unbounded environment, an error message is printed, and that class is not added to the set.
Parameters:
classNames - an array of unbounded environment class names

isValidEnvClass

public static boolean isValidEnvClass(java.lang.Class cls,
                                      java.lang.Class[] ctorParameters)
                               throws java.lang.NoSuchMethodException
Verifies that a class has the required constructor and is properly assignable to Environment. This is used to vet environment classes given to the factory before adding them to the list of known classes.

isValidEnvObjectClass

public static boolean isValidEnvObjectClass(java.lang.Class cls,
                                            java.lang.Class[] ctorParameters)
                                     throws java.lang.NoSuchMethodException
Verifies that a class has the required constructor and is properly assignable to Locatable. This is used to vet environment object classes given to the factory before adding them to the list of known classes.

hasCorrectCtor

protected static boolean hasCorrectCtor(java.lang.Class cls,
                                        java.lang.Class requiredCls,
                                        java.lang.Class[] ctorParameters)
                                 throws java.lang.NoSuchMethodException
Verifies that a class has the required constructor and is properly assignable. This is used to vet fish/environment classes given to the factory before adding them to the list of known classes.

hasFourArgCtor

public static boolean hasFourArgCtor(java.lang.Class cls)
Reports wehther a given environment object class has an accessible four-arg constructor that takes Environment, Location, Direction, and Color.

AP® Computer Science Marine Biology Simulation

Copyright© 2002 College Entrance Examination Board