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

com.dimajix.shaded.everit.schema.NumberComparator Maven / Gradle / Ivy

There is a newer version: 1.2.0-synapse3.3-spark3.3-hadoop3.3
Show newest version
package com.dimajix.shaded.everit.schema;

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


public class NumberComparator {

    static BigDecimal getAsBigDecimal(Object number) {
        if (number instanceof BigDecimal) {
            return (BigDecimal) number;
        } else if (number instanceof BigInteger) {
            return new BigDecimal((BigInteger) number);
        } else if (number instanceof Integer || number instanceof Long) {
            return new BigDecimal(((Number) number).longValue());
        } else {
            double d = ((Number) number).doubleValue();
            return BigDecimal.valueOf(d);
        }
    }

    static boolean deepEquals(Number num1, Number num2) {
        if (num1.getClass() != num2.getClass()) {
            return compare(num1, num2) == 0;
        }
        return Objects.equals(num1, num2);
    }

    static int compare(Number num1, Number num2) {
        return getAsBigDecimal(num1).compareTo(getAsBigDecimal(num2));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy