io.virtdata.api.DataMapperLibrary Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-curves4 Show documentation
Show all versions of virtdata-lib-curves4 Show documentation
Statistical sampling library for use in virtualdataset libraries, based on apache commons math 4
package io.virtdata.api;
import io.virtdata.core.DataMapperFunctionMapper;
import io.virtdata.core.ResolvedFunction;
import java.util.List;
import java.util.Optional;
/**
*
* A DataMapperLibrary is an independently loadable library of data mapping functions.
*
*/
public interface DataMapperLibrary {
/**
* Return the name for this data mapper implementation, as it can be used in spec strings, etc.
*
* @return Simple lower-case canonical library name
*/
String getLibraryName();
/**
* Find the implementation for and construct an instance of a data mapper function, as described.
*
* @param spec A specifier that describes the type and or parameterization of a data mapping function instance.
* @param The result type produced by the data mapping function.
* @return An optional data mapping function instance
*/
default Optional> getDataMapper(String spec) {
if (canParseSpec(spec)) {
Optional resolvedFunction = resolveFunction(spec);
return resolvedFunction
.map(ResolvedFunction::getFunctionObject)
.map(DataMapperFunctionMapper::map);
}
return Optional.empty();
}
default Optional> getOptionalDataMapper(String spec, Class extends T> clazz) {
return Optional.ofNullable(getDataMapper(spec, clazz));
}
@SuppressWarnings("unchecked")
default DataMapper getDataMapper(String spec, Class extends T> clazz) {
if (!canParseSpec(spec)) {
return null;
}
Optional resolvedFunction = resolveFunction(spec);
if (!resolvedFunction.isPresent()) {
return null;
}
ResolvedFunction rf = resolvedFunction.get();
DataMapper