org.opensha.commons.data.function
Class AbstractDiscretizedFunc

java.lang.Object
  extended by org.opensha.commons.data.function.AbstractXY_DataSet
      extended by org.opensha.commons.data.function.AbstractDiscretizedFunc
All Implemented Interfaces:
Serializable, Iterable<Point2D>, DiscretizedFunc, XY_DataSet, Named, PlotElement, XMLSaveable
Direct Known Subclasses:
ArbitrarilyDiscretizedFunc, EvenlyDiscretizedFunc, LightFixedXFunc, UnmodifiableDiscrFunc

public abstract class AbstractDiscretizedFunc
extends AbstractXY_DataSet
implements DiscretizedFunc, Named, Serializable

Title: DiscretizedFunc

Description: Abstract implementation of the DiscretizedFuncAPI. Performs standard simple or default functions so that subclasses don't have to keep reimplementing the same function bodies.

A Discretized Function is a collection of x and y values grouped together as the points that describe a function. A discretized form of a function is the only ways computers can represent functions. Instead of having y=x^2, you would have a sample of possible x and y values.

The basic functions this abstract class implements are:

See the interface documentation for further explanation of this framework

Version:
1.0
Author:
Steven W. Rock
See Also:
Serialized Form

Field Summary
protected static String C
          Class name used for debbuging
protected static boolean D
          if true print out debugging statements
protected  double tolerance
          The tolerance allowed in specifying a x-value near a real x-value, so that the real x-value is used.
static String XML_METADATA_NAME
           
static String XML_METADATA_POINT_NAME
           
static String XML_METADATA_POINTS_NAME
           
 
Fields inherited from class org.opensha.commons.data.function.AbstractXY_DataSet
info, name, xAxisName, yAxisName
 
Constructor Summary
AbstractDiscretizedFunc()
           
 
Method Summary
 double calcSumOfY_Vals()
           
 boolean equals(Object obj)
          Default equals for all Discretized Functions.
static AbstractDiscretizedFunc fromXMLMetadata(Element funcElem)
           
 double getTolerance()
          Returns the tolerance of this function.
static ArbitrarilyDiscretizedFunc loadFuncFromSimpleFile(InputStream is)
           
static ArbitrarilyDiscretizedFunc loadFuncFromSimpleFile(String fileName)
           
 void scale(double val)
          Scales (multiplies) the y-values of this function by the esupplied value.
 void setTolerance(double newTolerance)
          Sets the tolerance of this function.
 Element toXMLMetadata(Element root)
           
 Element toXMLMetadata(Element root, String elementName)
           
static void writeSimpleFuncFile(DiscretizedFunc func, File outFile)
           
static void writeSimpleFuncFile(DiscretizedFunc func, String fileName)
           
 
Methods inherited from class org.opensha.commons.data.function.AbstractXY_DataSet
areAllXValuesInteger, getClosestX, getClosestY, getDatasetsToPlot, getInfo, getName, getPlotNumColorList, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, iterator, setInfo, setName, setXAxisName, setYAxisName, xValues, yValues
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensha.commons.data.function.DiscretizedFunc
deepClone, getFirstInterpolatedX_inLogXLogYDomain, getFirstInterpolatedX, getIndex, getInterpolatedY_inLogXLogYDomain, getInterpolatedY_inLogYDomain, getInterpolatedY, getXIndex, getY
 
Methods inherited from interface org.opensha.commons.data.function.XY_DataSet
areAllXValuesInteger, get, getClosestX, getClosestY, getInfo, getMaxX, getMaxY, getMetadataString, getMinX, getMinY, getNum, getX, getXAxisName, getXValuesIterator, getY, getYAxisName, getYValuesIterator, hasPoint, hasPoint, set, set, set, setInfo, setName, setXAxisName, setYAxisName, toString, xValues, yValues
 
Methods inherited from interface org.opensha.commons.gui.plot.PlotElement
getDatasetsToPlot, getPlotNumColorList
 
Methods inherited from interface org.opensha.commons.data.Named
getName
 
Methods inherited from interface java.lang.Iterable
iterator
 

Field Detail

C

protected static final String C
Class name used for debbuging

See Also:
Constant Field Values

D

protected static final boolean D
if true print out debugging statements

See Also:
Constant Field Values

XML_METADATA_NAME

public static final String XML_METADATA_NAME
See Also:
Constant Field Values

XML_METADATA_POINTS_NAME

public static final String XML_METADATA_POINTS_NAME
See Also:
Constant Field Values

XML_METADATA_POINT_NAME

public static final String XML_METADATA_POINT_NAME
See Also:
Constant Field Values

tolerance

protected double tolerance
The tolerance allowed in specifying a x-value near a real x-value, so that the real x-value is used. Note that the tolerance must be smaller than 1/2 the delta between data points for evenly discretized function, no restriction for arb discretized function, no standard delta.

Constructor Detail

AbstractDiscretizedFunc

public AbstractDiscretizedFunc()
Method Detail

getTolerance

public double getTolerance()
Returns the tolerance of this function.

Specified by:
getTolerance in interface DiscretizedFunc

setTolerance

public void setTolerance(double newTolerance)
                  throws InvalidRangeException
Sets the tolerance of this function. Throws an InvalidRangeException if the tolerance is less than zero, an illegal value.

Specified by:
setTolerance in interface DiscretizedFunc
Throws:
InvalidRangeException

equals

public boolean equals(Object obj)
Default equals for all Discretized Functions. Determines if two functions are the same by comparing that the name, info, and values are the same.

Overrides:
equals in class Object

toXMLMetadata

public Element toXMLMetadata(Element root)
Specified by:
toXMLMetadata in interface XMLSaveable

toXMLMetadata

public Element toXMLMetadata(Element root,
                             String elementName)
Specified by:
toXMLMetadata in interface XY_DataSet

fromXMLMetadata

public static AbstractDiscretizedFunc fromXMLMetadata(Element funcElem)

writeSimpleFuncFile

public static void writeSimpleFuncFile(DiscretizedFunc func,
                                       String fileName)
                                throws IOException
Throws:
IOException

writeSimpleFuncFile

public static void writeSimpleFuncFile(DiscretizedFunc func,
                                       File outFile)
                                throws IOException
Throws:
IOException

loadFuncFromSimpleFile

public static ArbitrarilyDiscretizedFunc loadFuncFromSimpleFile(String fileName)
                                                         throws FileNotFoundException,
                                                                IOException
Throws:
FileNotFoundException
IOException

loadFuncFromSimpleFile

public static ArbitrarilyDiscretizedFunc loadFuncFromSimpleFile(InputStream is)
                                                         throws FileNotFoundException,
                                                                IOException
Throws:
FileNotFoundException
IOException

calcSumOfY_Vals

public double calcSumOfY_Vals()

scale

public void scale(double val)
Description copied from interface: DiscretizedFunc
Scales (multiplies) the y-values of this function by the esupplied value.

Specified by:
scale in interface DiscretizedFunc