use of com.ibm.streamsx.health.prepare.uomconverter.converters.AbstractUOMConverter in project streamsx.health by IBMStreams.
the class ConverterFactory method createConverter.
public AbstractUOMConverter createConverter(String inputUOM, String outputUOM) throws NoConverterFoundException {
for (Class<? extends AbstractUOMConverter> converterClass : supportedConverters) {
SupportedUOM supportedUoms = converterClass.getAnnotation(SupportedUOM.class);
List<String> inputUOMList = Arrays.asList(supportedUoms.inputUOM());
List<String> outputUOMList = Arrays.asList(supportedUoms.outputUOM());
if (inputUOMList.contains(inputUOM) && outputUOMList.contains(outputUOM)) {
try {
Constructor<? extends AbstractUOMConverter> constructor = converterClass.getConstructor(String.class, String.class);
AbstractUOMConverter converter = constructor.newInstance(inputUOM, outputUOM);
registerConverter(converter);
return converter;
} catch (Exception e) {
e.printStackTrace();
continue;
}
}
}
throw new NoConverterFoundException(inputUOM, outputUOM);
}
use of com.ibm.streamsx.health.prepare.uomconverter.converters.AbstractUOMConverter in project streamsx.health by IBMStreams.
the class ConverterFactory method convert.
public ConversionResult convert(double value, String inputUOM) throws UnconvertibleException {
AbstractUOMConverter converter = converterMap.get(inputUOM);
if (converter == null) {
throw new UnconvertibleException("No converter found for UOM: '" + inputUOM + "'");
}
double convertedValue = converter.convert(value);
String outputUOM = converter.getOutputUOM();
return new ConversionResult(inputUOM, outputUOM, convertedValue);
}
Aggregations