cox.jmatt.java.MathTools.graphing
Class RenderableImpl

java.lang.Object
  extended by cox.jmatt.java.MathTools.graphing.RenderableImpl
All Implemented Interfaces:
Renderable

public abstract class RenderableImpl
extends java.lang.Object
implements Renderable

This abstract class provides a partial implementation of the Renderable interface. It defines two constructors, one with no arguments and one that takes a String. The second constructor sets a protected field (myName) that subclasses can use, if such is desirable. It also defines the setType() method and provides a protected Object to hold its value. For subclasses that don't need condition testing, an empty testCondition() method is defined: it always returns false.

The setParameter() method actually provides considerable power. It makes sure the String key used to store an Object is not null or blank, and it provides an intuitive way to remove previously-set parameters. The return value is true if and only if: the key String is valid, a value was added successfully, or one was removed successfully. It returns false if the key is null or empty, an add fails, or there was no existing mapping to remove.

This class does NOT define a render() method since that method cannot have a sensible default.


Field Summary
protected  java.lang.String myName
          This String is assigned from the one-argument constructor (String).
protected  java.util.Hashtable<java.lang.String,java.lang.Object> myParameters
          This Hashtable holds parameter key-value pairs.
protected  java.lang.Object myType
          This is the Object set via the setType() method.
 
Constructor Summary
RenderableImpl()
          Create an unnamed instance.
RenderableImpl(java.lang.String pName)
          Create a named instance.
 
Method Summary
 boolean setParameter(java.lang.String pKey, java.lang.Object pValue)
          This method applies some processing to its function.
 boolean setType(java.lang.Object pType)
          Set the value of the 'myType' field.
 boolean testCondition(java.lang.Object pCondition, java.lang.Object pValue)
          This is an empty method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cox.jmatt.java.MathTools.graphing.Renderable
render
 

Field Detail

myName

protected java.lang.String myName
This String is assigned from the one-argument constructor (String). Subclasses can access this field as needed and implementations using such functionality should also define one-argument (String) constructors. The default value is null.


myType

protected java.lang.Object myType
This is the Object set via the setType() method. No verification or filtering is done. The default value is null.


myParameters

protected java.util.Hashtable<java.lang.String,java.lang.Object> myParameters
This Hashtable holds parameter key-value pairs. The setParameter() method ensures no keys or values will be null. Upon creation this field contains an empty table. Subclasses should NOT EVER assign it to be null, otherwise setParameter() will begin throwing nasty NullPointerExceptions!

Constructor Detail

RenderableImpl

public RenderableImpl()
Create an unnamed instance.


RenderableImpl

public RenderableImpl(java.lang.String pName)
Create a named instance. The String name is assigned to the 'myName' field. No verification or filtering is done; the field is assigned whatever value is passed into this method.

Method Detail

setType

public boolean setType(java.lang.Object pType)
Set the value of the 'myType' field. If its (after-assignment) value is null the return value is false. If not null it is true.

Specified by:
setType in interface Renderable
Parameters:
pType - The 'type' of Renderable being used.
Returns:
true if setting this renderable to pType makes sense, false otherwise.

testCondition

public boolean testCondition(java.lang.Object pCondition,
                             java.lang.Object pValue)
This is an empty method. It always returns false.

Specified by:
testCondition in interface Renderable
Parameters:
pCondition - The condition to test against the value.
pValue - The value against which the condition is to be checked.
Returns:
true if the test succeeds, false otherwise.

setParameter

public boolean setParameter(java.lang.String pKey,
                            java.lang.Object pValue)
This method applies some processing to its function. If the String key is null or empty it returns false immediately. If the value Object is not null the method returns true if it was successfully set, false if not. If pValue is null, the method attempts to remove pKey from the parameter table. If a mapping existed and an Object was removed the return value is true. If no mapping existed for pKey the method returns false.

Specified by:
setParameter in interface Renderable
Parameters:
pKey - The name of the Object to add or remove. Must not be null or blank.
pValue - The Object to add or null to remove.
Returns:
false if the key is not valid, an add fails, or no mapping exists to remove; true otherwise.