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

org.kaizen4j.common.util.ObjectUtils Maven / Gradle / Ivy

package org.kaizen4j.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ObjectUtils {

    private static final Logger logger = LoggerFactory.getLogger(ObjectUtils.class);

    public static int intValue(Object result) {
        if (result instanceof Long) {
            Long longObject = (Long) result;
            return longObject.intValue();
        } else if (result instanceof Integer) {
            Integer intObject = (Integer) result;
            return intObject.intValue();
        } else {
            throw new RuntimeException("The argument 'result' should be a Integer or Long, but was [" + result + "]");
        }
    }

    public static long longValue(Object result) {
        if (result instanceof Long) {
            Long longObject = (Long) result;
            return longObject.longValue();
        } else if (result instanceof Integer) {
            Integer intObject = (Integer) result;
            return intObject.longValue();
        } else {
            throw new RuntimeException("The argument 'result' should be a Integer or Long, but was [" + result + "]");
        }
    }

    public static float floatValue(Object result) {
        if (result instanceof Double) {
            Double doubleObject = (Double) result;
            return doubleObject.floatValue();
        } else if (result instanceof Float) {
            Float floatObject = (Float) result;
            return floatObject.floatValue();
        } else {
            throw new RuntimeException("The argument 'result' should be a Float or Double, but was [" + result + "]");
        }
    }

    public static double doubleValue(Object result) {
        if (result instanceof Double) {
            Double doubleObject = (Double) result;
            return doubleObject.doubleValue();
        } else if (result instanceof Float) {
            Float floatObject = (Float) result;
            return floatObject.doubleValue();
        } else {
            throw new RuntimeException("The argument 'result' should be a Float or Double, but was [" + result + "]");
        }
    }

    public static boolean booleanValue(Object result) {
        if (result instanceof Boolean) {
            Boolean booleanObject = (Boolean) result;
            return booleanObject.booleanValue();
        } else {
            throw new RuntimeException("The argument 'result' should be a Boolean, but was [" + result + "]");
        }
    }

    public static String toString(Object object) {
        if (null == object) {
            logger.warn("The argument 'object' should be not Null");
            return "Null";
        }
        return object.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy