@Test public void testBindFunction() throws Exception { FunctionLibrary funcLib = new FunctionLibrary(); DialogLibrary dialogLib = new DialogLibrary(); HashMap<Object, Object> context = new HashMap<>(); Function f = new BindFunction(new ValueFunction("test"), new ConfigThingy("", "SET(\"test\" \"value\")"), funcLib, dialogLib, context); assertEquals(0, f.parameters().length); Collection<String> dialogFunctions = new ArrayList<>(); f.getFunctionDialogReferences(dialogFunctions); assertTrue(dialogFunctions.isEmpty()); assertFalse(f.getBoolean(null)); assertEquals("value", f.getString(null)); f = new BindFunction(new ValueFunction("test"), new ConfigThingy("", ""), funcLib, dialogLib, context); Values.SimpleMap values = new Values.SimpleMap(); values.put("test", "value2"); assertEquals(1, f.parameters().length); assertFalse(f.getBoolean(values)); assertEquals("value2", f.getString(values)); f = new BindFunction(new ValueFunction("test"), new ConfigThingy("", "SET(\"test\" VALUE(\"test2\"))"), funcLib, dialogLib, context); values = new Values.SimpleMap(); values.put("test2", FunctionLibrary.ERROR); assertFalse(f.getBoolean(values)); assertEquals(FunctionLibrary.ERROR, f.getString(values)); assertThrows(ConfigurationErrorException.class, () -> new BindFunction(new ValueFunction("test"), new ConfigThingy("", "SET(\"test\" \"value\") SET(\"test\" \"value\")"), funcLib, dialogLib, context)); assertThrows(ConfigurationErrorException.class, () -> new BindFunction(new ValueFunction("test"), new ConfigThingy("", "SET(\"test\")"), funcLib, dialogLib, context)); }
public BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib, DialogLibrary dialogLib, Map<Object, Object> context) { this.func = func; Set<String> myParams = new HashSet<>(Arrays.asList(func.parameters())); Set<String> setFuncParams = new HashSet<>(); ConfigThingy sets = conf.query("SET"); Iterator<ConfigThingy> iter = sets.iterator(); while (iter.hasNext()) { ConfigThingy set = iter.next(); if (set.count() != 2) throw new ConfigurationErrorException( L.m("BIND: SET benötigt genau 2 Parameter")); try { String name = set.getFirstChild().toString(); Function setFunc = FunctionFactory.parse(set.getLastChild(), funcLib, dialogLib, context); if (mapParamNameToSetFunction.containsKey(name)) throw new ConfigurationErrorException( L.m("BIND: Der Parameter %1 wird 2 mal mit SET gebunden", name)); mapParamNameToSetFunction.put(name, setFunc); setFuncParams.addAll(Arrays.asList(setFunc.parameters())); setFunc.getFunctionDialogReferences(functionDialogReferences); myParams.remove(name); } catch (NodeNotFoundException x) { } } myParams.addAll(setFuncParams); params = myParams.toArray(new String[0]); }
BindFunction implements Function { public BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib, DialogLibrary dialogLib, Map<Object, Object> context) { this.func = func; Set<String> myParams = new HashSet<>(Arrays.asList(func.parameters())); Set<String> setFuncParams = new HashSet<>(); ConfigThingy sets = conf.query("SET"); Iterator<ConfigThingy> iter = sets.iterator(); while (iter.hasNext()) { ConfigThingy set = iter.next(); if (set.count() != 2) throw new ConfigurationErrorException( L.m("BIND: SET benötigt genau 2 Parameter")); try { String name = set.getFirstChild().toString(); Function setFunc = FunctionFactory.parse(set.getLastChild(), funcLib, dialogLib, context); if (mapParamNameToSetFunction.containsKey(name)) throw new ConfigurationErrorException( L.m("BIND: Der Parameter %1 wird 2 mal mit SET gebunden", name)); mapParamNameToSetFunction.put(name, setFunc); setFuncParams.addAll(Arrays.asList(setFunc.parameters())); setFunc.getFunctionDialogReferences(functionDialogReferences); myParams.remove(name); } catch (NodeNotFoundException x) { } } myParams.addAll(setFuncParams); params = myParams.toArray(new String[0]); } }
BindFunction implements Function { public BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib, DialogLibrary dialogLib, Map<Object, Object> context) { this.func = func; Set<String> myParams = new HashSet<>(Arrays.asList(func.parameters())); Set<String> setFuncParams = new HashSet<>(); ConfigThingy sets = conf.query("SET"); Iterator<ConfigThingy> iter = sets.iterator(); while (iter.hasNext()) { ConfigThingy set = iter.next(); if (set.count() != 2) throw new ConfigurationErrorException( L.m("BIND: SET benötigt genau 2 Parameter")); try { String name = set.getFirstChild().toString(); Function setFunc = FunctionFactory.parse(set.getLastChild(), funcLib, dialogLib, context); if (mapParamNameToSetFunction.containsKey(name)) throw new ConfigurationErrorException( L.m("BIND: Der Parameter %1 wird 2 mal mit SET gebunden", name)); mapParamNameToSetFunction.put(name, setFunc); setFuncParams.addAll(Arrays.asList(setFunc.parameters())); setFunc.getFunctionDialogReferences(functionDialogReferences); myParams.remove(name); } catch (NodeNotFoundException x) { } } myParams.addAll(setFuncParams); params = myParams.toArray(new String[0]); } BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib,
      DialogLibrary dialogLib, Map<Object, Object> context); }
BindFunction implements Function { public BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib, DialogLibrary dialogLib, Map<Object, Object> context) { this.func = func; Set<String> myParams = new HashSet<>(Arrays.asList(func.parameters())); Set<String> setFuncParams = new HashSet<>(); ConfigThingy sets = conf.query("SET"); Iterator<ConfigThingy> iter = sets.iterator(); while (iter.hasNext()) { ConfigThingy set = iter.next(); if (set.count() != 2) throw new ConfigurationErrorException( L.m("BIND: SET benötigt genau 2 Parameter")); try { String name = set.getFirstChild().toString(); Function setFunc = FunctionFactory.parse(set.getLastChild(), funcLib, dialogLib, context); if (mapParamNameToSetFunction.containsKey(name)) throw new ConfigurationErrorException( L.m("BIND: Der Parameter %1 wird 2 mal mit SET gebunden", name)); mapParamNameToSetFunction.put(name, setFunc); setFuncParams.addAll(Arrays.asList(setFunc.parameters())); setFunc.getFunctionDialogReferences(functionDialogReferences); myParams.remove(name); } catch (NodeNotFoundException x) { } } myParams.addAll(setFuncParams); params = myParams.toArray(new String[0]); } BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib,
      DialogLibrary dialogLib, Map<Object, Object> context); @Override String[] parameters(); @Override void getFunctionDialogReferences(Collection<String> set); @Override String getString(Values parameters); @Override boolean getBoolean(Values parameters); }
BindFunction implements Function { public BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib, DialogLibrary dialogLib, Map<Object, Object> context) { this.func = func; Set<String> myParams = new HashSet<>(Arrays.asList(func.parameters())); Set<String> setFuncParams = new HashSet<>(); ConfigThingy sets = conf.query("SET"); Iterator<ConfigThingy> iter = sets.iterator(); while (iter.hasNext()) { ConfigThingy set = iter.next(); if (set.count() != 2) throw new ConfigurationErrorException( L.m("BIND: SET benötigt genau 2 Parameter")); try { String name = set.getFirstChild().toString(); Function setFunc = FunctionFactory.parse(set.getLastChild(), funcLib, dialogLib, context); if (mapParamNameToSetFunction.containsKey(name)) throw new ConfigurationErrorException( L.m("BIND: Der Parameter %1 wird 2 mal mit SET gebunden", name)); mapParamNameToSetFunction.put(name, setFunc); setFuncParams.addAll(Arrays.asList(setFunc.parameters())); setFunc.getFunctionDialogReferences(functionDialogReferences); myParams.remove(name); } catch (NodeNotFoundException x) { } } myParams.addAll(setFuncParams); params = myParams.toArray(new String[0]); } BindFunction(Function func, ConfigThingy conf, FunctionLibrary funcLib,
      DialogLibrary dialogLib, Map<Object, Object> context); @Override String[] parameters(); @Override void getFunctionDialogReferences(Collection<String> set); @Override String getString(Values parameters); @Override boolean getBoolean(Values parameters);  }