Package nz.org.riskscape.engine.function
Class DiscreteFunction.Builder
java.lang.Object
nz.org.riskscape.engine.function.DiscreteFunction.Builder
- Enclosing class:
- DiscreteFunction
API For users to build their DiscreteFunction
// 1 : 5
// 2..10 : 5x + 1
// - plus 1..2 gets a line from 5 to 11
builder()
.add(1, 5)
.add(2, 10, Maths.newPolynomial(1, 5))
.withLinearInterpolation()
.build()
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(com.google.common.collect.Range<Double> range, nz.org.riskscape.engine.function.RiskscapeFunction function) Add a function applicable for the given rangeadd(DiscreteFunction.Pair pair) Add an already constructedDiscreteFunction.Pairto the builderaddConstant(double lower, double upper, Number constant) Add a constant, applicable for the range (lower >= x > upper)addFunction(double lower, double upper, nz.org.riskscape.engine.function.RiskscapeFunction function) Add a function, applicable for the range (lower >= x > upper)Add a constant value, applicable only for the given at valueaddPoint(double at, nz.org.riskscape.engine.function.RiskscapeFunction function) Add a function applicable only for the given valuebuild()Fill in any gaps between ranges with a linear function that bridges the gap.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
build
- Returns:
- a
DiscreteFunctionbased on the construction so far.
-
addFunction
public DiscreteFunction.Builder addFunction(double lower, double upper, nz.org.riskscape.engine.function.RiskscapeFunction function) Add a function, applicable for the range (lower >= x > upper)
- Parameters:
lower- inclusive start of the x rangeupper- exclusive end of the x rangefunction- applicable function for the range- Returns:
- the builder, to allow a fluid API
- Throws:
IllegalArgumentException- if the range overlaps, or if any of the function types are not Numeric
-
addConstant
Add a constant, applicable for the range (lower >= x > upper)
- Parameters:
lower- inclusive start of the x rangeupper- exclusive end of the x rangeconstant- value to return for the range- Returns:
- the builder, to allow a fluid API
- Throws:
IllegalArgumentException- if the range overlaps, or if any of the function types are not Numeric
-
addPoint
public DiscreteFunction.Builder addPoint(double at, nz.org.riskscape.engine.function.RiskscapeFunction function) Add a function applicable only for the given value
- Parameters:
at- single xvalue that the function is applicable forfunction- applicable function for the range- Returns:
- the builder, to allow a fluid API
- Throws:
IllegalArgumentException- if the range overlaps, or if any of the function types are not Numeric
-
addPoint
Add a constant value, applicable only for the given at value
- Parameters:
at- single x value that the function is applicable forconstant- the value to return- Returns:
- the builder, to allow a fluid API
- Throws:
IllegalArgumentException- if the range overlaps, or if any of the function types are not Numeric
-
add
public DiscreteFunction.Builder add(com.google.common.collect.Range<Double> range, nz.org.riskscape.engine.function.RiskscapeFunction function) Add a function applicable for the given range
- Parameters:
range- any validRangefunction- applicable function for the range- Returns:
- the builder, to allow a fluid API
- Throws:
IllegalArgumentException- if the range overlaps, or if any of the function types are not Numeric
-
add
Add an already constructed
DiscreteFunction.Pairto the builder- Returns:
- the builder, to allow a fluid API
- Throws:
IllegalArgumentException- if the range overlaps, or if any of the function types are not Numeric
-
withoutUpperBoundClosing
-
withLinearInterpolation
Fill in any gaps between ranges with a linear function that bridges the gap.
-