Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
themeEclipse
languagejava
titleMEP Function stub
linenumberstrue
public class MyFunction extends AbstractFunction<Double> {

    public static final SDFDatatype[][] accTypes = new SDFDatatype[][] {{ SDFDatatype.DOUBLE },
                                                                        { SDFDatatype.DOUBLE }};

    @Override
    public String getSymbolMyFunction() {
        return super("myFunction", 2, accTypes, SDFDatatype.DOUBLE);
    }

    @Override
    public Double getValue() {
        double a = (double) this.getInputValue(0);
        double b = this.getNumericalInputValue(1);

        return a  +b;
    }

    @Override
    public SDFDatatype getReturnType() {
        return SDFDatatype.DOUBLE;
    }

    @Override
    public int getArity() {
        return 2;
    }

    @Override
    public SDFDatatype[] getAcceptedTypes(int argPos) {
        if (argPos < 0) {
            throw new IllegalArgumentException(
                    "negative argument index not allowed");
        }
        if (argPos > this.getArity()) {
            throw new IllegalArgumentException(this.getSymbol() + " has only " + this.getArity() + " arguments: Two double values.");
        }
        return accTypes[argPos];
    }
    
}

 

Access to function attributes

To Access the attributes of the function you can use the getInputValue or the getNumericalInputValue methods. While the first method returns an object, the second already cast the input value to a double value. Both methods takes the position index of the attribute as an argument. The name of the function, the total number of attributes, and the datatype of the accepted attributes is set in the getAcceptedTypes function constructor. Thus, a MEP  function can handle multiple data types for each attribute. The total number of attributes is set in the getArity method. The last required method is the getSymbol method that sets the name of the function as used in an expression in a processing query.

Access to meta attributes

...