All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.horizon.uca.convert.FloatVto Maven / Gradle / Ivy

The newest version!
package io.horizon.uca.convert;

import io.horizon.util.HUt;

import java.math.BigDecimal;
import java.util.Objects;

public class FloatVto implements Vto {

    @Override
    public Float to(final Object value, final Class type) {
        if (Objects.isNull(value)) {

            return -1.0f;
        } else {
            if (Float.class == type) {

                return (Float) value;
            } else if (String.class == type) {

                return HUt.isDecimal(value.toString()) ? Float.parseFloat(value.toString()) : -1.0f;
            } else if (HUt.isInteger(type) || HUt.isDecimal(type)) {

                return Float.parseFloat(value.toString());
            } else if (BigDecimal.class == type) {

                return ((BigDecimal) value).floatValue();
            } else if (Boolean.class == type) {

                final Boolean normalized = (Boolean) value;
                if (normalized) {
                    return 1.0f;
                } else {
                    return 0.0f;
                }
            }
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy