public ValuesCheckerRunnable( long start, long end, int bufsize, int threadNum, String mapperSpec, DataMapper<?> dataMapper, ConcurrentLinkedQueue<Integer> readyQueue, Condition goTime, Lock lock, List<Object> expected ) { this.start = start; this.end = end; this.bufsize = bufsize; this.threadNum = threadNum; this.readyQueue = readyQueue; this.expected = expected; this.goTime = goTime; this.lock = lock; this.mapper = (dataMapper != null) ? dataMapper : VirtData.getMapper(mapperSpec) .orElseThrow( () -> new RuntimeException("unable to resolve mapper for " + mapperSpec) ); }
public static <T> T getFunction(String flowSpec, Class<? extends T> functionType) { Optional<? extends T> optionalFunction = getOptionalFunction(flowSpec, functionType); return optionalFunction.orElseThrow(); }
/** * Instantiate a data mapping function, or throw an exception. * * @param flowSpec The VirtData specifier for the mapping function * @param <T> The parameterized return type of the function * @return A data mapping function * @throws RuntimeException if the function could not be resolved */ public static <T> DataMapper<T> getMapper(String flowSpec) { Optional<DataMapper<T>> optionalMapper = getOptionalMapper(flowSpec); return optionalMapper.orElseThrow(() -> new RuntimeException("Unable to find mapper: " + flowSpec)); }
/** * Create a bindings template from the pair-wise names and specifiers. * Each even-numbered (starting with zero) argument is a binding name, * and each odd-numbered (starting with one) argument is a binding spec. * * @param namesAndSpecs names and specs in "name", "spec", ... form * @return A bindings template that can be used to resolve a bindings instance */ public static BindingsTemplate getTemplate(String... namesAndSpecs) { if ((namesAndSpecs.length % 2) != 0) { throw new RuntimeException( "args must be in 'name','spec', pairs. " + "This can't be true for " + namesAndSpecs.length + "elements."); } Map<String, String> specmap = new HashMap<>(); for (int i = 0; i < namesAndSpecs.length; i += 2) { specmap.put(namesAndSpecs[i], namesAndSpecs[i + 1]); } return getTemplate(specmap); }
.map(m -> VirtData.getFunction(m, LongUnaryOperator.class)) .orElse(null); .map(m -> VirtData.getFunction(m, LongToIntFunction.class)) .ifPresent(f -> this.resultFunc = f);
Optional<DataMapper<String>> func = VirtData.getMapper(expr); funcs.add(func.orElseThrow(() -> new RuntimeException("Unable to resolve function: " + expr)));
/** * Instantiate a data mapping function of the specified type, or throw an error. * * @param flowSpec The VirtData flow specifier for the function to be returned * @param clazz The class of the data mapping function return type * @param <T> The parameterized class of the data mapping return type * @return A new data mapping function. * @throws RuntimeException if the function could not be resolved */ public static <T> DataMapper<T> getMapper(String flowSpec, Class<? extends T> clazz) { Optional<DataMapper<T>> dataMapper = getOptionalMapper(flowSpec, clazz); DataMapper<T> mapper = dataMapper.orElseThrow(() -> new RuntimeException("Unable to find mapper: " + flowSpec)); return mapper; }
/** * 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); }