Class DiscreteFunction.Builder

java.lang.Object
nz.org.riskscape.engine.function.DiscreteFunction.Builder
Enclosing class:
DiscreteFunction

public static class DiscreteFunction.Builder extends Object

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 Details

    • Builder

      public Builder()
  • Method Details

    • build

      public DiscreteFunction build()
      Returns:
      a DiscreteFunction based 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 range
      upper - exclusive end of the x range
      function - 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

      public DiscreteFunction.Builder addConstant(double lower, double upper, Number constant)

      Add a constant, applicable for the range (lower >= x > upper)

      Parameters:
      lower - inclusive start of the x range
      upper - exclusive end of the x range
      constant - 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 for
      function - 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

      public DiscreteFunction.Builder addPoint(double at, Number constant)

      Add a constant value, applicable only for the given at value

      Parameters:
      at - single x value that the function is applicable for
      constant - 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 valid Range
      function - 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.Pair to 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

      public DiscreteFunction.Builder withoutUpperBoundClosing()
    • withLinearInterpolation

      public DiscreteFunction.Builder withLinearInterpolation()

      Fill in any gaps between ranges with a linear function that bridges the gap.