Class ArithmeticFunction<R>

Type Parameters:
R - the type of resources (e.g. Feature) used as inputs.
All Implemented Interfaces:
Serializable, Function<R,Number>, Expression<R,Number>, Optimization.OnExpression<R,Number>, FeatureExpression<R,Number>
Direct Known Subclasses:
ArithmeticFunction.Add, ArithmeticFunction.Divide, ArithmeticFunction.Multiply, ArithmeticFunction.Subtract

abstract class ArithmeticFunction<R> extends BinaryFunction<R,Number,Number> implements FeatureExpression<R,Number>, Optimization.OnExpression<R,Number>
Arithmetic operations between two numerical values. The nature of the operation depends on the subclass.
Since:
1.1
Version:
1.1
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
  • Constructor Details

    • ArithmeticFunction

      ArithmeticFunction(Expression<? super R,? extends Number> expression1, Expression<? super R,? extends Number> expression2)
      Creates a new arithmetic function.
  • Method Details

    • createNumericType

      static DefaultAttributeType<Number> createNumericType(String name)
      Creates an attribute type for numeric values of the given name. The attribute is mandatory, unbounded and has no default value.
      Parameters:
      name - name of the attribute to create.
      Returns:
      an attribute of the given name for numbers.
    • expectedType

      protected abstract DefaultAttributeType<Number> expectedType()
      Returns the type of results computed by this arithmetic function.
    • getValueClass

      public final Class<?> getValueClass()
      Returns the type of values computed by this expression.
      Specified by:
      getValueClass in interface FeatureExpression<R,Number>
      Returns:
      the type of values computed by this expression.
    • expectedType

      public final PropertyTypeBuilder expectedType(DefaultFeatureType ignored, FeatureTypeBuilder addTo)
      Provides the type of results computed by this expression. That type depends only on the ArithmeticFunction subclass and is given by expectedType().
      Specified by:
      expectedType in interface FeatureExpression<R,Number>
      Parameters:
      ignored - the type of features to be evaluated by the given expression.
      addTo - where to add the type of properties evaluated by this expression.
      Returns:
      builder of the added property, or null if this method cannot add a property.
    • apply

      public final Number apply(R feature)
      Evaluates the expression for producing a result of numeric type. This method delegates to one of the applyAs(…) methods. If no applyAs(…) implementations can return null values, this this method never return null.
      Specified by:
      apply in interface Expression<R,Number>
      Specified by:
      apply in interface Function<R,Number>
      Parameters:
      feature - the object to be evaluated by the expression. Can be null if this expression allows null values.
      Returns:
      value computed by the expression.
    • toValueType

      public <N> Expression<R,N> toValueType(Class<N> target)
      Returns this if this expression provides values of the specified type, or otherwise returns an expression doing conversions on-the-fly.
      Specified by:
      toValueType in interface Expression<R,Number>
      Type Parameters:
      N - compile-time value of type.
      Parameters:
      target - desired type of expression results.
      Returns:
      expression doing the same operation this this expression but with results of the specified type.
      Throws:
      ClassCastException - if the specified type is not a supported target type.