Enum SizeUnit

    • Enum Constant Detail

      • BYTE

        public static final SizeUnit BYTE
      • KILOBYTE

        public static final SizeUnit KILOBYTE
      • MEGABYTE

        public static final SizeUnit MEGABYTE
      • GIGABYTE

        public static final SizeUnit GIGABYTE
      • TERABYTE

        public static final SizeUnit TERABYTE
      • PETABYTE

        public static final SizeUnit PETABYTE
      • EXABYTE

        public static final SizeUnit EXABYTE
    • Method Detail

      • values

        public static SizeUnit[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SizeUnit c : SizeUnit.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SizeUnit valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • abbreviation

        public String abbreviation()
        Returns the abbreviation for the unit.
        Returns:
        the abbreviation for the unit
      • toBytes

        public long toBytes​(long size)
        Converts the given size to bytes from this unit. For example SizeUnit.KILOBYTES.toBytes(1L) would return 1024.
        Parameters:
        size - the size to convert
        Returns:
        the size in bytes
      • convert

        public double convert​(long size,
                              SizeUnit unit)
        Converts the given size to the given unit to this unit.
        Parameters:
        size - the size to convert
        unit - the unit to convert the size to
        Returns:
        the converted units
      • toString

        public String toString​(long size)
        Converts the size to a human-readable string format.

        For example SizeUnit.KILOBYTE.toString(1024L) would return "1 KB".

        Parameters:
        size - the size, in bytes
        Returns:
        a human-readable size
      • parent

        public SizeUnit parent()
        Returns the parent, previous, unit for this unit.
        Returns:
        the parent unit or null in the case of BYTE
      • toHumanReadable

        public static String toHumanReadable​(long size)
        Converts the size, in bytes, to a human-readable form. For example 1024 bytes return "1 KB".
        Parameters:
        size - the size, in bytes, to convert
        Returns:
        a human-readable size