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

com.github.atdixon.vroom.coercion.ToInteger Maven / Gradle / Ivy

Go to download

Work immutably, robustly and in a knowledge-oriented way with Entity maps in Java.

There is a newer version: 0.3.13
Show newest version
package com.github.atdixon.vroom.coercion;

import java.lang.reflect.Type;

public final class ToInteger implements Coercion {

    @Override
    public Integer coerce(Type type, Object value) throws FastCannotCoerceException {
        if (value == null) {
            return null;
        } else if (value instanceof Integer) {
            return (Integer) value;
        } else if (value instanceof Number) {
            return ((Number) value).intValue();
        }
        if (value instanceof String) {
            try {
                return Integer.valueOf((String) value);
            } catch (NumberFormatException e) {/*ok*/}
        }
        throw new FastCannotCoerceException(type, value);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy