Class ResourceFormatter

java.lang.Object
eu.cloudnetservice.utils.base.resource.ResourceFormatter

public final class ResourceFormatter extends Object
A small utility class to convert resource values between different formats.
Since:
4.0
  • Field Details

  • Constructor Details

    • ResourceFormatter

      private ResourceFormatter()
  • Method Details

    • formatTwoDigitPrecision

      @NonNull public static @NonNull String formatTwoDigitPrecision(double value)
      Formats the given double value with a two digit precision after the decimal point. The integer fraction of the given double is kept untouched.
      Parameters:
      value - the value to format.
      Returns:
      the formatted value.
    • 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 than 0, 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.