rafa.math.gen
Class FunctionStrategy

java.lang.Object
  extended by rafa.math.gen.FunctionStrategy
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, Dependent, GeneratorStrategy

public class FunctionStrategy
extends java.lang.Object
implements GeneratorStrategy, java.beans.PropertyChangeListener, Dependent

Generates values according to a mathematical function.

Author:
rafa

Field Summary
protected  Function function
          The function used to calculate values.
 
Constructor Summary
FunctionStrategy(java.lang.String f)
           
 
Method Summary
 java.util.List<? extends java.lang.Number> generate(int index)
          Generates new numbers.
 java.util.Collection<Dependency> getDependencies(java.lang.Object dep)
          Gets detailed information about the dependencies of this object on a given one.
 java.lang.String getFunction()
          Getter for property function.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Currently, this class only listens to the NAME property of helper generators.
 void reset()
          Resets the strategy to its initial state.
 void setFunction(java.lang.String f)
          Sets the function of this generator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

function

protected Function function
The function used to calculate values. It must be of type
f(x)
, x being the iteration of calculation (a non-negative integer).
Other functions calls for values from other helper generators can be used within this string, as long as they have been defined before.
The default value for the function is "x", i.e. a straight line.
Examples of valid functions are:
x
2*pi*x²

Constructor Detail

FunctionStrategy

public FunctionStrategy(java.lang.String f)
                 throws CircularDependencyException
Parameters:
f - the function used to generate values
Throws:
CircularDependencyException
Method Detail

reset

public void reset()
Description copied from interface: GeneratorStrategy
Resets the strategy to its initial state.

Specified by:
reset in interface GeneratorStrategy

generate

public java.util.List<? extends java.lang.Number> generate(int index)
                                                    throws java.lang.Exception
Description copied from interface: GeneratorStrategy
Generates new numbers.

Specified by:
generate in interface GeneratorStrategy
Parameters:
index - the index of the value within the strategy output. Note that it can be ignored by the implementation, if not needed.
Returns:
A list of numbers, or null if none was generated.
Throws:
java.lang.Exception

setFunction

public void setFunction(java.lang.String f)
                 throws CircularDependencyException
Sets the function of this generator. The function will be validated against the current set of helpers.

Parameters:
f - the function
Throws:
CircularDependencyException

getFunction

public java.lang.String getFunction()
Getter for property function.

Returns:
Value of property function.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Currently, this class only listens to the NAME property of helper generators. RESET of helpers has no effect, as this object does not store any of their values.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getDependencies

public java.util.Collection<Dependency> getDependencies(java.lang.Object dep)
Description copied from interface: Dependent
Gets detailed information about the dependencies of this object on a given one.

Specified by:
getDependencies in interface Dependent
Parameters:
dep - the required object. If null, all of the dependencies will be returned.
Returns:
a collection of Dependency objects pointing to the same object (target), or null if there is no dependency on that object.


Copyright © 2008-2009. All Rights Reserved.