Class ConvertFunction<R,S,V>

Type Parameters:
R - the type of resources (e.g. Feature) used as inputs.
S - the type of value computed by the wrapped exception. This is the type to convert.
V - the type of value computed by this expression. This is the type after conversion.
All Implemented Interfaces:
Serializable, Function<R,V>, Expression<R,V>, Optimization.OnExpression<R,V>, FeatureExpression<R,V>

final class ConvertFunction<R,S,V> extends UnaryFunction<R,S> implements FeatureExpression<R,V>, Optimization.OnExpression<R,V>
Expression whose results are converted to a different type.
Since:
1.1
Version:
1.2
See Also:
  • Field Details

    • serialVersionUID

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

      private static final org.opengis.util.ScopedName NAME
      Name of this expression.
    • converter

      private final ObjectConverter<? super S,? extends V> converter
      The converter to use.
  • Constructor Details

    • ConvertFunction

      ConvertFunction(Expression<? super R,? extends S> expression, Class<S> source, Class<V> target)
      Creates a new converted expression.
      Parameters:
      expression - the expression providing source values.
      source - the type of value produced by given expression
      target - the desired type for the expression result.
      Throws:
      UnconvertibleObjectException - if no converter is found.
    • ConvertFunction

      private ConvertFunction(ConvertFunction<R,S,V> original, Expression<? super R,? extends S> expression)
      Creates a new converted expression after optimization.
      Parameters:
      expression - the expression providing source values.
      Throws:
      UnconvertibleObjectException - if no converter is found.
  • Method Details

    • recreate

      public Expression<R,V> recreate(Expression<? super R,?>[] effective)
      Creates a new expression of the same type than this expression, but with optimized parameters.
      Specified by:
      recreate in interface Optimization.OnExpression<R,S>
      Parameters:
      effective - the expressions to use as a replacement of this expression parameters.
      Returns:
      the new expression, or this if unsupported.
    • getFunctionName

      public org.opengis.util.ScopedName getFunctionName()
      Returns an identification of this operation.
      Specified by:
      getFunctionName in interface Expression<R,S>
      Returns:
      name of the function to be called.
    • getChildren

      protected Collection<?> getChildren()
      Returns the singleton expression tested by this operator together with the source and target classes.
      Overrides:
      getChildren in class UnaryFunction<R,S>
      Returns:
      the children of this node, or an empty collection if none.
    • apply

      public V apply(R feature)
      Evaluates the expression for producing a result of the given type. If this method cannot produce a value of the given type, then it returns null. This implementation evaluates the expression in the default way, then tries to convert the result to the target type.
      Specified by:
      apply in interface Expression<R,S>
      Specified by:
      apply in interface Function<R,S>
      Parameters:
      feature - the value or feature to evaluate with this expression.
      Returns:
      the result, or null if it cannot be of the specified type.
    • getValueClass

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

      public PropertyTypeBuilder expectedType(DefaultFeatureType valueType, FeatureTypeBuilder addTo)
      Provides the type of values produced by this expression when a feature of the given type is evaluated. May return null if the type cannot be determined.
      Specified by:
      expectedType in interface FeatureExpression<R,S>
      Parameters:
      valueType - 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.
    • toValueType

      public <N> Expression<R,N> toValueType(Class<N> target)
      Returns an expression doing the same evaluation than this method, but returning results as values of the specified type. The result may be this.
      Specified by:
      toValueType in interface Expression<R,S>
      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 target type supported by implementation.