use of io.atlasmap.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class CharSequenceConverter method toDouble.
/**
* Converts to {@link Double}.
* @param value value
* @return converted
* @throws AtlasConversionException out of range or not a number
*/
@AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.DOUBLE, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE })
public Double toDouble(CharSequence value) throws AtlasConversionException {
if (value == null) {
return null;
}
String str = value.toString();
double parsedDouble = 0.0d;
try {
parsedDouble = Double.parseDouble(str);
} catch (NumberFormatException nfe) {
throw new AtlasConversionException(nfe);
}
double absParsedDouble = Math.abs(parsedDouble);
if (absParsedDouble == 0.0d) {
return parsedDouble;
}
if (absParsedDouble < Double.MIN_VALUE || absParsedDouble > Double.MAX_VALUE) {
throw new AtlasConversionException(String.format("String %s is greater than Double.MAX_VALUE or less than Double.MIN_VALUE", str));
}
return parsedDouble;
}
use of io.atlasmap.spi.AtlasConversionInfo in project atlasmap by atlasmap.
the class DateConverter method toCalendar.
/**
* Converts to {@link Calendar}.
* @param date value
* @return converted
*/
@AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ)
public Calendar toCalendar(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date.getTime());
return calendar;
}
Aggregations