org.opensha.sra.riskmaps.func
Class DiscreteFunction

java.lang.Object
  extended by org.opensha.sra.riskmaps.func.DiscreteFunction
All Implemented Interfaces:
FunctionAPI
Direct Known Subclasses:
DiscreteInterpExterpFunc

public class DiscreteFunction
extends Object
implements FunctionAPI

This class represents the mathematical idea of a discrete function. Discrete functions have discrete domains and ranges. They are eseentially a pairing of x/y values. Once a function is instantiated, that instance become immutable.

 -=* CHANGE LOG *=-
 06/19/2008 -- EMM: Original implementation.

Version:
0.0.1
Author:
Eric Martinez

Field Summary
protected  double[] xvals
          The x-values of this function
protected  double[] yvals
          The y-values of this function
 
Constructor Summary
DiscreteFunction(double[] xvals, double[] yvals)
          Creates a discrete function with the given xvals, yvals, and the DEFAULT_NAME.
DiscreteFunction(double[] xvals, double[] yvals, String name)
          Creates a discrete function with the given xvals, yvals, and name.
 
Method Summary
 boolean equals(Object obj)
          Checks the domain and range of the two functions are the same, and the for each value i in the domain of the functions, f(i) = g(i).
 SetAPI getDomain()
          Gets the domain of this function.
 String getName()
          Gets the name of this function.
 SetAPI getRange()
          Gets the range of this function.
 double[] getXVals()
          Gets the raw xvals array of data.
 double[] getYVals()
          Gets the raw yvals array of data.
 String toString()
           
 double valueOf(double x)
          Gets the function value for the given x input.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

xvals

protected double[] xvals
The x-values of this function


yvals

protected double[] yvals
The y-values of this function

Constructor Detail

DiscreteFunction

public DiscreteFunction(double[] xvals,
                        double[] yvals)
Creates a discrete function with the given xvals, yvals, and the DEFAULT_NAME.

Parameters:
xvals - The x-values of the function.
yvals - The y-values of the function.

DiscreteFunction

public DiscreteFunction(double[] xvals,
                        double[] yvals,
                        String name)
Creates a discrete function with the given xvals, yvals, and name.

Parameters:
xvals - The x-values of the function.
yvals - The y-values of the function.
name - The name of the function.
Method Detail

getDomain

public SetAPI getDomain()
Gets the domain of this function. The domain is the set of unique x-values. In practice, this is exactly the set of x-values since the domain is defined to map each value exactly once. Thus this method may be used interchangeably with the getXVals() function.

Specified by:
getDomain in interface FunctionAPI
Returns:
The domain of this function.

getRange

public SetAPI getRange()
Gets the range of this function. The range is the set of unique y-values. In practice this set may contain fewer values than the raw set of y-values since two values in the range are allowed to map to the same y-value. Thus, that y-value would appear twice in our array of y-values, but would appear only once in the range. Use getYVals() to get the raw array of y-values.

Specified by:
getRange in interface FunctionAPI
Returns:
The range of the function.

getName

public String getName()
Gets the name of this function.

Specified by:
getName in interface FunctionAPI
Returns:
The name of this function.

valueOf

public double valueOf(double x)
Gets the function value for the given x input.

Specified by:
valueOf in interface FunctionAPI
Parameters:
x - The value of which to take f(x).
Returns:
The function value for this function evaluated at x.
Throws:
IllegalArgumentException - If x is not in the domain of the function.

getXVals

public double[] getXVals()
Gets the raw xvals array of data.

Returns:
The primitive array of doubles representing the discrete x-values.

getYVals

public double[] getYVals()
Gets the raw yvals array of data.

Returns:
The primitive array of doubles representing the discrete y-values.

equals

public boolean equals(Object obj)
Checks the domain and range of the two functions are the same, and the for each value i in the domain of the functions, f(i) = g(i).

Overrides:
equals in class Object
Parameters:
func - The function to compare agaist.
Returns:
True if the two functions are logically equal, false otherwise.

toString

public String toString()
Overrides:
toString in class Object