Class ResourceFormatter
java.lang.Object
eu.cloudnetservice.utils.base.resource.ResourceFormatter
A small utility class to convert resource values between different formats.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ThreadLocal<DecimalFormat> private static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longconvertBytesToMb(long bytesToConvert) Converts the given byte count to a megabyte value.static doubleconvertToPercentage(double value) Converts the given double value into a percentage.formatTwoDigitPrecision(double value) Formats the given double value with a two digit precision after the decimal point.
-
Field Details
-
ONE_MB_IN_BYTES
private static final long ONE_MB_IN_BYTES- See Also:
-
DECIMAL_FORMAT_2DIGIT_PRECISION
-
-
Constructor Details
-
ResourceFormatter
private ResourceFormatter()
-
-
Method Details
-
formatTwoDigitPrecision
-
convertToPercentage
public static double convertToPercentage(double value) Converts the given double value into a percentage. This method only works correctly when given a value in the [0.0, 1.0] interval. If the given value is if smaller than0, this method returns-1. Note: the return value is maxed out at 100, even if an invalid value is passed in, this method always returns a value in the interval [-1, 100].- Parameters:
value- the value to convert to a percentage.- Returns:
- the converted value as specified.
-
convertBytesToMb
public static long convertBytesToMb(long bytesToConvert) Converts the given byte count to a megabyte value. This method makes the assumption that the given value is always a meaningful byte count.- Parameters:
bytesToConvert- the byte count to convert to megabytes.- Returns:
- the given byte count, converted to megabytes.
-