Search in sources :

Example 21 with AtlasConversionInfo

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;
}
Also used : AtlasConversionException(io.atlasmap.api.AtlasConversionException) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo)

Example 22 with AtlasConversionInfo

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;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo)

Aggregations

AtlasConversionInfo (io.atlasmap.spi.AtlasConversionInfo)22 Method (java.lang.reflect.Method)14 AtlasConversionConcern (io.atlasmap.spi.AtlasConversionConcern)12 Annotation (java.lang.annotation.Annotation)10 Test (org.junit.jupiter.api.Test)9 AtlasConversionException (io.atlasmap.api.AtlasConversionException)7 BigDecimal (java.math.BigDecimal)5 Field (io.atlasmap.v2.Field)4 FieldType (io.atlasmap.v2.FieldType)4 Validation (io.atlasmap.v2.Validation)4 ValidationScope (io.atlasmap.v2.ValidationScope)4 ValidationStatus (io.atlasmap.v2.ValidationStatus)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Optional (java.util.Optional)4 AtlasConversionService (io.atlasmap.api.AtlasConversionService)2 AtlasConverter (io.atlasmap.api.AtlasConverter)2 JavaField (io.atlasmap.java.v2.JavaField)2 AtlasConverter (io.atlasmap.spi.AtlasConverter)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2