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

host.anzo.commons.utils.NumberUtils Maven / Gradle / Ivy

There is a newer version: 1.29
Show newest version
package host.anzo.commons.utils;

import host.anzo.commons.text.formatters.RoundedMetricPrefixFormat;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;

/**
 * @author ANZO
 * @since 9/8/2021
 */
public class NumberUtils {
    private final static RoundedMetricPrefixFormat ROUNDED_METRIC_PREFIX_FORMAT = new RoundedMetricPrefixFormat();

    /**
     * @param number number to convert
     * @return number string in metric prefix format.
     */
    public static @NotNull String toMetricPrefixedString(long number) {
        return ROUNDED_METRIC_PREFIX_FORMAT.format(number);
    }

    /**
     * Pack to integers to long
     *
     * @param int1 first int
     * @param int2 second int
     * @return long number with two specified packed integers
     */
    public static long packIntsToLong(int int1, int int2) {
	    return ((long) int1 << 32) | (int2 & 0xFFFFFFFFL);
    }

    /**
     * Unpack two integers from specified long number
     * @param packedValue long number
     * @return pair of two unpacked integers
     */
    public static Pair unpackIntsFromLong(long packedValue) {
        final int int1 = (int) (packedValue >> 32);
        final int int2 = (int) packedValue;
        return Pair.of(int1, int2);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy