public Object[] getBindPointValues(long cycle){ return dataBindings.getAll(cycle); }
/** * TODO: Doc how this is different, and semantically useful * @param value the spec value, not the generated data value * @return true if the spec exists in the bindings */ @Override public boolean containsValue(Object value) { return bindings.getTemplate().getDataMapperSpecs().contains((String) value); }
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 R bind(long value) { Object[] allGeneratedValues = bindings.getAll(value); try { // Provide bindings context data where it may be useful return valuesArrayBinder.bindValues(context, allGeneratedValues); } catch (Exception e) { throw new RuntimeException("Binding error:" + bindings.getTemplate().toString(allGeneratedValues), e); } } }
@Override public R bind(long value) { Map<String,Object> generatedValues = new HashMap<String,Object>(); bindings.setMap(generatedValues, value); try { // Provide bindings context data where it may be useful return valuesMapBinder.bindValues(context, generatedValues); } catch (Exception e) { throw new RuntimeException("Binding error:" + bindings.getTemplate().toString() + ": " + generatedValues, e); } } }
/** * Generate only the values which have matching keys in the provided * map according to their bind point names, and assign them to the * map under that name. It is an error for a key name to be defined * in the map for which there is no mapper. * * @param donorMap - a user-provided Map<String,Object> * @param input - the input for which to generate the values */ public void updateMap(Map<String, Object> donorMap, long input) { for (String s : donorMap.keySet()) { donorMap.put(s, get(s, input)); } }
/** * @param input The input value for which the values should be generated. * @return {@link Map} of {@link String} to {@link Object} */ public Map<String, Object> getAllMap(long input) { Map<String, Object> values = new HashMap<>(); setMap(values, input); return values; }
/** * This is a version of the {@link #setIteratedSuffixMap(Map, long, int, String[])} which creates * a new map for each call. * @param input The base input value for which the values should be generated * @param count The count of maps that should be added to the final map * @param fieldNames The field names which are used to look up the functions in the binding * @return A newly created map with the generated names and values. */ public Map<String,Object> getIteratedSuffixMap(long input, int count, String... fieldNames) { Map<String, Object> suffixedMap = new LinkedHashMap<>(count * fieldNames.length); setIteratedSuffixMap(suffixedMap, input, count, fieldNames); return suffixedMap; }
/** * Set the values in a provided map, with the bound names suffixed with * an internal iteration value. * * @param donorMap an existing {@link Map} of {@link String} to {@link Object} * @param input the base cycle for which values should be generated * @param count the number of iterations to to generate values and keynames for */ public void setIteratedSuffixMap(Map<String, Object> donorMap, long input, long count) { for (int i = 0; i < count; i++) { setSuffixedMap(donorMap, input + i, String.valueOf(i)); } }
public String bind(long cycleNum) { StringConcatSetter setter = new StringConcatSetter(); dataBindings.setFields(setter,cycleNum); return setter.toString(); }
/** * Use the data mapping library and the specifier to create instances of data mapping functions. * If you need thread-aware mapping, be sure to call this in the proper thread. Each time this method * is called, it creates a new instance. * @return A set of bindings that can be used to yield mapped data values later. */ public Bindings resolveBindings() { List<DataMapper<?>> dataMappers = new ArrayList<>(); for (String specifier : specifiers) { Optional<DataMapper<Object>> optionalDataMapper = VirtData.getOptionalMapper(specifier); if (optionalDataMapper.isPresent()) { dataMappers.add(optionalDataMapper.get()); } else { logAvailableDataMappers(); throw new RuntimeException( "data mapper binding was unsuccessful for " + ", spec:" + specifier + ", see log for known data mapper names."); } } return new Bindings(this, dataMappers); }
@Override public R bind(long value) { Object[] allGeneratedValues = bindings.getAll(value); try { // Provide bindings context data where it may be useful return valuesBinder.bindValues(context, bindings, value); } catch (Exception e) { throw new RuntimeException("Binding error:" + bindings.getTemplate().toString(allGeneratedValues), e); } } }
@Override public String bindValues(StringCompositor context, Bindings bindings, long cycle) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < templateSegments.length; i++) { if (i % 2 == 0) { sb.append(templateSegments[i]); } else { String key = templateSegments[i]; Object value = bindings.get(key, cycle); String valueString = stringfunc.apply(value); sb.append(valueString); } } return sb.toString(); }
for (int i = 0; i < count; i++) { Map<String, Object> suffixedMap = new HashMap<>(); setMap(suffixedMap, input + i); listOfMaps.add(suffixedMap);
/** * Generate a map containing the results from multiple iterations, suffixing * the keys in the map with the iterations from 0 to count-1. * <p>For example, calling getIteratedSuffixMap(5, 3) with generators named * alpha and gamma might yield results like * <ul> * <li>alpha0 -> val1</li> * <li>gamma0 -> val2</li> * <li>alpha1 -> val3</li> * <li>gamma1 -> val4</li> * <li>alpha2 -> val5</li> * <li>gamma2 -> val6</li> * </ul> * * @param input The base input value for which the values should be generated * @param count The count of maps that should be added to the final map * @return {@link Map} of {@link String} to {@link Object} */ public Map<String, Object> getIteratedSuffixMap(long input, int count) { Map<String, Object> suffixedMap = new LinkedHashMap<>(count * this.dataMappers.size()); setIteratedSuffixMap(suffixedMap, input, count); return suffixedMap; }
@Override public boolean isEmpty() { return bindings.getTemplate().getBindPointNames().isEmpty(); }
/** * 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]); } }
for (int i = 0; i < count; i++) { for (String f : fieldNames) { suffixedMap.put(f+i,get(f,input+i));
@Override public boolean containsKey(Object key) { return bindings.getTemplate().getBindPointNames().contains((String) key); }
@Override public String bind(long value) { Object[] all = bindings.getAll(value); StringBuilder sb = new StringBuilder(); for (Object o : all) { sb.append(o.toString()); sb.append(","); } sb.setLength(sb.length()-1); if (sb.length()>bufferlen) { bufferlen=sb.length()+5; } return sb.toString(); } }