Refine search
private FunctionName getFunctionName(Function function) { String name = function.getName(); FunctionName functionName = function.getFunctionName(); if (functionName == null && function instanceof FunctionExpressionImpl) { functionName = function.getFunctionName(); } if (functionName == null) { int argc; argc = function.getParameters().size(); functionName = filterFactory.functionName(name, argc); if (!functionName.getName().equals(name)) { LOGGER.warning( function.getClass() + " FunctionName was null, used for etArgumentCount(): " + functionName); } } else { if (!functionName.getName().equals(name)) { LOGGER.warning( function.getClass() + " has name conflict betwee '" + name + "' and '" + functionName.getName() + "'"); } } return functionName; }
public FunctionNameImpl(FunctionName copy) { super(copy); this.functionName = copy.getFunctionName(); this.ret = copy.getReturn(); this.args = copy.getArguments(); }
public Element encode(Object object, Document document, Element value) throws Exception { FunctionName function = (FunctionName) object; value.appendChild(document.createTextNode(function.getName())); value.setAttributeNS("", "nArgs", function.getArgumentCount() + ""); return value; } }
Function f = factory.function(IsInstanceOf.NAME.getFunctionName(), args, null); assertNotNull(f); f = factory.function(IsInstanceOf.NAME.getName(), args, null); assertNotNull(f); f = factory.function(IsInstanceOf.NAME.getName(), args, null); } catch (IllegalArgumentException e) { catchedException = true; try { f = factory.function(IsInstanceOf.NAME.getName(), null, null); } catch (NullPointerException e) { catchedException = true;
FilterFunction_min_4 min_4 = (FilterFunction_min_4) ff.function("min_4", new org.opengis.filter.expression.Expression[2]); assertEquals("Name is, ", "min_4", min_4.getName()); assertEquals("Number of arguments, ", 2, min_4.getFunctionName().getArgumentCount()); Function min_4Function = ff.function("min_4", literal_1, literal_m1); assertEquals( "min of (1.0,-1.0):", (long) Math.min(1.0, -1.0), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001); min_4Function = ff.function("min_4", literal_m1, literal_2); assertEquals( "min of (-1.0,2.0):", (long) Math.min(-1.0, 2.0), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001); "min of (2.0,-2.0):", (long) Math.min(2.0, -2.0), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001);
String name = functionName.getName(); parameters.add(ff.property("geom")); } 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();
public void testSumAreaWithGroupBy() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyName p = ff.property(aname("geom")); GroupByVisitor v = new GroupByVisitorBuilder() .withAggregateAttribute(ff.function("area2", p)) .withAggregateVisitor("SumArea") .withGroupByAttributes( Collections.singleton(aname("name")), dataStore.getSchema(tname("aggregate"))) .build(); dataStore.getFeatureSource(tname("aggregate")).accepts(Query.ALL, v, null); if (dataStore.getSupportedFunctions().containsKey(FilterFunction_area.NAME.getName())) { assertFalse(visited); } List groups = v.getResult().toList(); assertEquals(20.0, (Double) ((Object[]) groups.get(0))[1], 0.01); assertEquals(10.0, (Double) ((Object[]) groups.get(1))[1], 0.01); }
@Override public Object visit(Function f, Object extraData) { FunctionName fn = f.getFunctionName(); if (fn != null && fn.getReturn() != null && fn.getReturn().getType() != Object.class) { return fn.getReturn().getType(); } else if (f instanceof FilterFunction_Convert) { // special case for the convert function, which has the return type as // a parameter return f.getParameters().get(1).evaluate(null, Class.class); } return null; }
logger.debug(function.getName()); functionNameMap.put(function.getName(), function); for (int index = 0; index < function.getArgumentCount(); index++) { if (!classList.contains(function.getArguments().get(index).getType())) { classList.add(function.getArguments().get(index).getType()); + function.getArgumentNames().get(index) + "\t" + function.getArguments().get(index).getType().getName() + "\t\t" + function.getArguments().get(index).getMinOccurs() + "\t" + function.getArguments().get(index).getMaxOccurs()); if (!classList.contains(function.getReturn().getType())) { classList.add(function.getReturn().getType()); logger.debug("\tRet : " + function.getReturn().getType().getName());
@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; }
/** * 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)); } }
@Override public String getName() { return NAME.getName(); }
/** Test for helpful exception detail if wrong number of parameters. */ @Test public void wrongNumberOfParameters() { try { ff.function( FormatDateTimezoneFunction.NAME.getFunctionName(), ff.literal(PATTERN), ff.literal(TIME)) .evaluate(null); Assert.fail("Unexpected success"); } catch (RuntimeException e) { Assert.assertEquals( FormatDateTimezoneFunction.NAME.getFunctionName() + ": wrong number of parameters (2 not 3)", e.getMessage()); } }
@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); }
} else { try { List<Expression> parameters = function.getParameters(); List<Parameter<?>> arguments = function.getFunctionName().getArguments(); Parameter<?> lastArgument = arguments.isEmpty() ? null : arguments.get(arguments.size() - 1);
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); }
@Override public Object visit(Function expression, Object extraData) { FunctionName name = expression.getFunctionName(); if (name != null && name.getReturn() != null) { return name.getReturn().getType(); } else { return Object.class; } }
public void testrandom() { try { FilterFunction_random randomFunction = (FilterFunction_random) ff.function("random", new org.opengis.filter.expression.Expression[0]); assertEquals("Name is, ", "random", randomFunction.getName()); assertEquals( "Number of arguments, ", 0, randomFunction.getFunctionName().getArgumentCount()); } catch (FactoryRegistryException e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); fail("Unexpected exception: " + e.getMessage()); } }
public int getArgCount() { return NAME.getArgumentCount(); }
@Override public Function function(Name name, List<Expression> args, Literal fallback) { // Check if the name belongs to the IsInstanceOf NAME, otherwise null // is returned if (IsInstanceOf.NAME.getFunctionName().equals(name)) { return new IsInstanceOf(args, fallback); } return null; } }