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

org.vertexium.cypher.functions.scalar.ToIntegerFunction Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cypher.functions.scalar;

import org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException;
import org.vertexium.cypher.functions.TypeConversionFunction;

public class ToIntegerFunction extends TypeConversionFunction {
    @Override
    protected Object convert(Object value) {
        if (value == null) {
            return null;
        }
        if (value instanceof Number) {
            return ((Number) value).intValue();
        }
        if (value instanceof String) {
            String str = ((String) value).trim();
            try {
                return Integer.parseInt(str);
            } catch (NumberFormatException ex1) {
                try {
                    return new Double(str).intValue();
                } catch (NumberFormatException ex2) {
                    return null;
                }
            }
        }
        throw new VertexiumCypherTypeErrorException("InvalidArgumentValue: " + value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy