public ModuloFunction(List<Expression> parameters, Literal fallback) { if (parameters == null) { throw new NullPointerException("parameters must be provided"); } if (parameters.size() != NAME.getArguments().size()) { throw new IllegalArgumentException( NAME.getArguments().size() + " function parameters are required"); } this.functionName = NAME; this.parameters = parameters; this.fallback = fallback; }
public FunctionNameImpl(FunctionName copy) { super(copy); this.functionName = copy.getFunctionName(); this.ret = copy.getReturn(); this.args = copy.getArguments(); }
public AbstractHSLFunction(String name) { this.functionName = new FunctionNameImpl(name, NAME.getReturn(), NAME.getArguments()); }
LinkedHashMap<String, Object> prepped = new LinkedHashMap<String, Object>(); List<Parameter<?>> args = getFunctionName().getArguments(); List<Expression> expr = getParameters();
Parameter<?> parameter = getFunctionName().getArguments().get(argumentIndex); if (params.size() <= argumentIndex) { if (parameter.getMinOccurs() == 0) {
List<Parameter<?>> arguments = function.getFunctionName().getArguments(); Parameter<?> lastArgument = arguments.isEmpty() ? null : arguments.get(arguments.size() - 1);
@Override public Object visit(Function expression, Object extraData) { List old = expression.getParameters(); FunctionName functionName = expression.getFunctionName(); List<Parameter<?>> arguments = null; if (functionName != null) { arguments = functionName.getArguments(); } Expression[] args = new Expression[old.size()]; for (int i = 0; i < old.size(); i++) { Expression exp = (Expression) old.get(i); if (arguments != null && i < arguments.size()) { args[i] = optimize(exp, extraData, arguments.get(i).getType()); } else { args[i] = visit(exp, extraData); } } Function duplicate; if (expression instanceof InternalFunction) { duplicate = ((InternalFunction) expression).duplicate(args); } else { duplicate = getFactory(extraData).function(expression.getName(), args); } return duplicate; }
public void testFunctionName() throws Exception { FunctionName fn = FunctionImpl.functionName( "foo", "bar:Integer", "a", "x:String:1,1", "y:MultiPolygon", "z:java.util.Date:1,"); assertEquals("foo", fn.getName()); check(fn.getReturn(), "bar", Integer.class, 1, 1); check(fn.getArguments().get(0), "a", Object.class, 1, 1); check(fn.getArguments().get(1), "x", String.class, 1, 1); check(fn.getArguments().get(2), "y", MultiPolygon.class, 1, 1); check(fn.getArguments().get(3), "z", Date.class, 1, -1); fn = FunctionImpl.functionName("foo", "a", "geom::1,1", "b:Object:,"); check(fn.getArguments().get(0), "geom", Geometry.class, 1, 1); check(fn.getArguments().get(1), "b", Object.class, -1, -1); fn = FunctionImpl.functionName("foo", "value", "geom::,"); check(fn.getArguments().get(0), "geom", Geometry.class, -1, -1); }
} else if (name.compareToIgnoreCase(CategorizeFunction.NAME.getName()) == 0) { for (int index = 0; index < functionName.getArguments().size() - 1; index++) { parameters.add(index, ff.literal("")); parameters.add(ff.literal(CategorizeFunction.PRECEDING)); } else { List<Parameter<?>> functionParamList = functionName.getArguments();
/** * Gets the number of arguments that are set. * * @return the number of args. */ public int getArgCount(){ if( functionName != null && functionName.getArguments() != null){ return functionName.getArguments().size(); } else { return 0; } }
public ModuloFunction(List<Expression> parameters, Literal fallback) { if (parameters == null) { throw new NullPointerException("parameters must be provided"); } if (parameters.size() != NAME.getArguments().size()) { throw new IllegalArgumentException(NAME.getArguments().size() + " function parameters are required"); } this.functionName = NAME; this.parameters = parameters; this.fallback = fallback; }
/** * Creates the Categorize function. * * @param functionName the function name * @param parameters the parameters */ private static void createCategorizeFunction( FunctionName functionName, List<Expression> parameters) { // CategorizeFunction needs all the fields populated for (int index = 0; index < functionName.getArguments().size() - 1; index++) { parameters.add(index, ff.literal("")); } parameters.remove(parameters.size() - 1); parameters.add(ff.literal(CategorizeFunction.PRECEDING)); } }
public FunctionNameImpl( FunctionName copy ) { super( copy ); this.functionName = copy.getFunctionName(); this.ret = copy.getReturn(); this.args = copy.getArguments(); }
/** * Gets the row count. * * @return the row count */ public int getRowCount() { if (builtInSelected) { if (builtInProcessFunction == null) { return 0; } return builtInProcessFunction.getArguments().size(); } else { if (selectedCustomFunction == null) { return 0; } return selectedCustomFunction.getDataInputs().getInput().size(); } }
/** * Validates the structure of arguments, basically enforcing java conventions for variable * level arguments. */ private void validateArguments() throws IllegalArgumentException { List<Parameter<?>> args = getFunctionName().getArguments(); for (int i = 0; i < args.size(); i++) { Parameter<?> arg = args.get(i); if (arg.getMaxOccurs() == 0) { throw new IllegalArgumentException(String.format("Argument %s has zero max")); } if (arg.getMinOccurs() != 1 || arg.getMaxOccurs() != 1) { //this can only happen for the last argument if (i != args.size()-1) { throw new IllegalArgumentException(String.format("Argument %s(%d,%d) invalid." + " Variable arguments must be the last argument of function.", arg.getName(), arg.getMinOccurs(), arg.getMaxOccurs())); } } } }
@Override public boolean accept(FunctionName functionName) { if (functionName != null) { // Check return type if (allowedGeometryTypeList.contains(functionName.getReturn().getType())) { return false; } // Check all parameters for (Parameter<?> parameter : functionName.getArguments()) { if (allowedGeometryTypeList.contains(parameter.getType())) { return false; } } // Check to see if function name is on the banned list if (disallowedFunctionNameList.contains(functionName.getName())) { return false; } } return true; } }
@Override public Object visit(Function expression, Object data) { FunctionName name = expression.getFunctionName(); if (name != null && name.getArgumentCount() > 0) { List<Parameter<?>> argumentTypes = name.getArguments(); List<Expression> arguments = expression.getParameters(); for (int i = 0; i < Math.min(arguments.size(), argumentTypes.size()); i++) { Expression ex = arguments.get(i); String propertyName = getPropertyName(ex); Parameter<?> argumentType = argumentTypes.get(i); if (propertyName != null && argumentType != null) { aggregator.addType(propertyName, argumentType.getType()); } } } return super.visit(expression, data); }
/** * Extract function attribute. * * @param foundList the found list * @param function the function * @return the class */ private Class<?> extractFunctionAttribute(List<String> foundList, Function function) { Class<?> returnType; FunctionName functionName = function.getFunctionName(); List<Parameter<?>> argumentList = functionName.getArguments(); int index = 0; for (Expression parameterExpression : function.getParameters()) { Parameter<?> parameter = argumentList.get(index); extractAttribute(parameter.getType(), parameterExpression, foundList); if (index < argumentList.size()) { index++; } if (index >= argumentList.size()) { index = argumentList.size() - 1; } } returnType = functionName.getReturn().getType(); return returnType; }
/** Sets the function impl. */ private void setFunctionImpl() { FunctionImpl functionExpression = (FunctionImpl) this.expression; FunctionName functionName = functionExpression.getFunctionName(); TypeManager.getInstance().setDataType(functionName.getReturn().getType()); int maxArgument = Math.abs(functionName.getArgumentCount()); for (int index = 0; index < maxArgument; index++) { ExpressionNode childNode = new ExpressionNode(); Parameter<?> parameter = functionName.getArguments().get(0); childNode.setType(parameter.getType()); childNode.setName(parameter.getName()); if (index < functionExpression.getParameters().size()) { childNode.setExpression(functionExpression.getParameters().get(index)); } this.insert(childNode, this.getChildCount()); } }
/** Sets the function. */ private void setFunction() { Function functionExpression = (Function) this.expression; FunctionName functionName = functionExpression.getFunctionName(); TypeManager.getInstance().setDataType(functionName.getReturn().getType()); int overallIndex = 0; for (Parameter<?> param : functionName.getArguments()) { if (param.getMinOccurs() == 0) { overallIndex = setFunctionOptional(functionExpression, overallIndex, param); } else { overallIndex = setFunctionFixed(functionExpression, overallIndex, param); } } }