@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; } }
Function f = factory.function(IsInstanceOf.NAME.getFunctionName(), args, null); assertNotNull(f);
private HashMap<Name, FunctionFactory> lookupFunctions() { // get all filter functions via function factory HashMap<Name, FunctionFactory> result = new HashMap<Name, FunctionFactory>(); Set<FunctionFactory> functionFactories = CommonFactoryFinder.getFunctionFactories(null); for (FunctionFactory ff : functionFactories) { for (FunctionName functionName : ff.getFunctionNames()) { result.put(functionName.getFunctionName(), ff); } } return result; } }
public Function function(Name name, List<Expression> args, Literal fallback) { if (PolygonLabelFunction.NAME.getFunctionName().equals(name)) { return new PolygonLabelFunction(args, fallback); } return null; // we do not implement that function } }
public FunctionNameImpl(FunctionName copy) { super(copy); this.functionName = copy.getFunctionName(); this.ret = copy.getReturn(); this.args = copy.getArguments(); }
private Map<Name, FunctionDescriptor> loadFunctions() { Map<Name, FunctionDescriptor> functionMap = new HashMap<Name, FunctionDescriptor>(); Set<Function> functions = CommonFactoryFinder.getFunctions(null); for (Iterator<Function> i = functions.iterator(); i.hasNext(); ) { Function function = (Function) i.next(); FunctionName functionName = getFunctionName(function); Name name = functionName.getFunctionName(); FunctionDescriptor fd = new FunctionDescriptor(functionName, (Class<Function>) function.getClass()); // needed to insert justin's name hack here to ensure consistent lookup Name key = functionName(name); if (functionMap.containsKey(key)) { // conflicted name - probably a cut and paste error when creating functionName FunctionDescriptor conflict = functionMap.get(key); LOGGER.warning( "Function " + key + " clash between " + conflict.clazz.getSimpleName() + " and " + function.getClass().getSimpleName()); } functionMap.put(key, fd); } return functionMap; }
/** * Lookup the FunctionName description. * * @param name Function name; this will need to be an exact match * @return FunctioName description, or null if function is not available */ public FunctionName findFunctionDescription(Name name) { Set<FunctionFactory> functionFactories = CommonFactoryFinder.getFunctionFactories(null); for (FunctionFactory factory : functionFactories) { List<FunctionName> functionNames = factory.getFunctionNames(); for (FunctionName description : functionNames) { if (description.getFunctionName().equals(name)) { return description; } } } return null; // not found }
/** * Creates the function expression with default parameters. * * @param functionName the function name * @return the expression */ private Expression createExpression(FunctionName functionName) { if (functionName == null) { return null; } List<Expression> parameters = new ArrayList<Expression>(); Literal fallback = null; // Retrieve default parameters for function createNewFunctionParameters(functionName, parameters); // Create function expression with supplied parameters Function function = functionFactory.function(functionName.getFunctionName(), parameters, fallback); return function; }
/** 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()); } }
/** Test for helpful exception detail if date is invalid. */ @Test public void invalidDate() { try { ff.function( FormatDateTimezoneFunction.NAME.getFunctionName(), ff.literal(PATTERN), ff.literal("not a valid time"), ff.literal("UTC")) .evaluate(null); Assert.fail("Unexpected success"); } catch (RuntimeException e) { Assert.assertEquals( FormatDateTimezoneFunction.NAME.getFunctionName() + ": could not parse date: not a valid time", e.getMessage()); } }
/** * Return {@link #DAY} formatted according to {@link #PATTERN} in a time zone. * * @param timezone in one of the formats supported by {@link TimeZone} * @return the formatted day */ private String formatTimezone(String timezone) { return (String) ff.function( FormatDateTimezoneFunction.NAME.getFunctionName(), ff.literal(PATTERN), ff.literal(TIME), ff.literal(timezone)) .evaluate(null); }
/** Test that a null pattern causes null to be returned. */ @Test public void nullPattern() { Assert.assertNull( ff.function( FormatDateTimezoneFunction.NAME.getFunctionName(), ff.literal(null), ff.literal(TIME), ff.literal("UTC")) .evaluate(null)); }
/** Test that a null date causes null to be returned. */ @Test public void nullDate() { Assert.assertNull( ff.function( FormatDateTimezoneFunction.NAME.getFunctionName(), ff.literal(PATTERN), ff.literal(null), ff.literal("UTC")) .evaluate(null)); }
/** Test that a null timezone causes null to be returned. */ @Test public void nullTimezone() { Assert.assertNull( ff.function( FormatDateTimezoneFunction.NAME.getFunctionName(), ff.literal(PATTERN), ff.literal(TIME), ff.literal(null)) .evaluate(null)); } }
/** * Creates the expression. * * @param functionName the function name * @return the expression */ @Override public Expression createExpression(FunctionName functionName) { if (functionName == null) { return null; } List<Expression> parameters = null; Literal fallback = null; return functionFactory.function(functionName.getFunctionName(), parameters, fallback); }
private HashMap<Name,FunctionFactory> lookupFunctions() { // get all filter functions via function factory HashMap<Name,FunctionFactory> result = new HashMap<Name,FunctionFactory>(); Set<FunctionFactory> functionFactories = CommonFactoryFinder.getFunctionFactories(null); for (FunctionFactory ff : functionFactories) { for (FunctionName functionName : ff.getFunctionNames()) { result.put(functionName.getFunctionName(), ff); } } return result; }
public FunctionNameImpl( FunctionName copy ) { super( copy ); this.functionName = copy.getFunctionName(); this.ret = copy.getReturn(); this.args = copy.getArguments(); }
/** * Lookup the FunctionName description. * @param name Function name; this will need to be an exact match * @return FunctioName description, or null if function is not available */ public FunctionName findFunctionDescription(Name name ){ Set<FunctionFactory> functionFactories = CommonFactoryFinder.getFunctionFactories(null); for (FunctionFactory factory : functionFactories) { List<FunctionName> functionNames = factory.getFunctionNames(); for( FunctionName description : functionNames ){ if( description.getFunctionName().equals( name )){ return description; } } } return null; // not found }
/** * Creates the expression. * * @param functionName the function name * @return the expression */ @Override public Expression createExpression(FunctionName functionName) { if (functionName == null) { return null; } List<Expression> parameters = new ArrayList<>(); Literal fallback = null; FunctionExpressionInterface.createNewFunction(functionName, parameters); return functionFactory.function(functionName.getFunctionName(), parameters, fallback); }
/** * Gets the function name. * * @return the function name */ public Name getFunctionName() { if (builtInSelected) { if (builtInProcessFunction == null) { return null; } return builtInProcessFunction.getFunctionName(); } else { if (selectedCustomFunction == null) { return null; } return new NameImpl(selectedCustomFunction.getTitle().getValue()); } }