@Override public boolean containsKey(Object key) { return bindings.getTemplate().getBindPointNames().contains((String) key); }
/** * Generate all values in the bindings template, and set each of them in * the map according to their bind point name. * * @param donorMap - a user-provided Map<String,Object> * @param cycle - the cycle for which to generate the values */ public void setMap(Map<String, Object> donorMap, long cycle) { Object[] all = getAll(cycle); for (int i = 0; i < all.length; i++) { donorMap.put(template.getBindPointNames().get(i), all[i]); } }
@Override public boolean isEmpty() { return bindings.getTemplate().getBindPointNames().isEmpty(); }
public List<String> getBindPointNames() { return dataBindings.getTemplate().getBindPointNames(); }
@Override public int size() { return bindings.getTemplate().getBindPointNames().size(); }
/** * Set the values in a provided map, with bound names suffixed with * some value. No non-overlapping keys in the map will be affected. * * @param donorMap an existing {@link Map} of {@link String} to {@link Object} * @param cycle the cycle for which values should be generated * @param suffix a string suffix to be appended to any map keys */ public void setSuffixedMap(Map<String, Object> donorMap, long cycle, String suffix) { Object[] all = getAll(cycle); for (int i = 0; i < all.length; i++) { donorMap.put(template.getBindPointNames().get(i) + suffix, all[i]); } }
private Object getFieldValue(String fieldName, long coordinate) { int i = bindings.getTemplate().getBindPointNames().indexOf(fieldName); if (i<0) { throw new RuntimeException("field name '" + fieldName + "' does not exist in bindings:" + bindings); } Object o = bindings.get(i, coordinate); return o; }
@Override public Set<String> keySet() { return Collections.unmodifiableSet(new HashSet<String>() {{ addAll(bindings.getTemplate().getBindPointNames()); }}); }
/** * Generate all the values named in the bind point names, then call the user-provided * field setter for each name and object generated. * * @param fieldSetter user-provided object that implements {@link FieldSetter} * @param input the input for which to generate values */ public void setAllFields(FieldSetter fieldSetter, long input) { Object[] all = getAll(input); for (int i = 0; i < all.length; i++) { fieldSetter.setField(template.getBindPointNames().get(i), all[i]); } }
/** * Generate all the values named in the bindings for a number of iterations, calling * a user-provided field setter for each name and object generated, with the * iteration number appended to the fieldName. * * @param fieldSetter user-provided object that implements {@link FieldSetter} * @param input the base input value for which the objects should be generated * @param count the number of iterations to generate values and names for */ public void setAllFieldsIterated(FieldSetter fieldSetter, long input, int count) { for (int i = 0; i < count; i++) { Object[] all = getAll(input+i); for (int j = 0; j < all.length; j++) { fieldSetter.setField(template.getBindPointNames().get(i) + i, all[i]); } } }
/** * Create a new instance of {@link StringBindings}, preferably in the thread context that will use it. * @return a new StringBindings */ public StringBindings resolve() { StringCompositor compositor = new StringCompositor(stringTemplate); HashSet<String> unqualifiedNames = new HashSet<>(compositor.getBindPointNames()); unqualifiedNames.removeAll(new HashSet<>(bindingsTemplate.getBindPointNames())); if (unqualifiedNames.size()>0) { throw new RuntimeException("Named anchors were specified in the template which were not provided in the bindings: " + unqualifiedNames.toString()); } Bindings bindings = bindingsTemplate.resolveBindings(); return new StringBindings(compositor,bindings); } }