/** * 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)); }
/** * 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); }