host.anzo.commons.utils.NumberUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-core Show documentation
Show all versions of commons-core Show documentation
Commons library to make me happy.
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);
}
}