Class Storage


  • public class Storage
    extends java.lang.Object
    • Constructor Detail

      • Storage

        public Storage​(long amount,
                       Storage.Unit unit)
      • Storage

        public Storage​(long amount)
    • Method Detail

      • getSize

        public long getSize()
        Returns the amount of storage represented, in Bytes
      • deepCopy

        @NonNull
        public Storage deepCopy()
      • getSizeAsUnit

        public long getSizeAsUnit​(@NonNull
                                  Storage.Unit unit)
        Return the amount of storage represented by the instance in the given unit
        Parameters:
        unit - The unit of the result.
        Returns:
        The size of the storage in the given unit.
      • getPreciseSizeAsUnit

        public double getPreciseSizeAsUnit​(@NonNull
                                           Storage.Unit unit)
        Returns the amount of storage represented by the instance in the given unit as a double to get a more precise result
        Parameters:
        unit - The unit of the result.
        Returns:
        The size of the storage in the given unit.
      • getStorageFromString

        @Nullable
        public static Storage getStorageFromString​(@Nullable
                                                   java.lang.String storageString)
        Decodes the given string and returns a Storage of the corresponding size. The input string can look like these: "2" "2B" "2MB" "2 M" "2 MB" But NOT like these: "2m" "2.6" "2 MiB"
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • lessThan

        public boolean lessThan​(java.lang.Object other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getAppropriateUnits

        @NonNull
        public Storage.Unit getAppropriateUnits()
        Finds the largest Storage.Unit which can display the storage value as a positive integer with no loss of accuracy.
        Returns:
        The most appropriate Storage.Unit.
      • getLargestReasonableUnits

        @NonNull
        public Storage.Unit getLargestReasonableUnits()
        Finds the largest Storage.Unit which can display the storage value with non-zero integer part. This might be useful for displaying in user interface where full precision is not critical and can be sacrificed in favor of better UX.
        Returns:
        The largest Storage.Unit such that getSize()/Unit.getNumberOfBytes() is not zero.
      • toString

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toUiString

        public java.lang.String toUiString()
        Represents a Storage as a string suitable for displaying in the UI.
      • toUiString

        public java.lang.String toUiString​(int precision)
        Represents a Storage as a string suitable for displaying in the UI.
        Parameters:
        precision - The number of digits after decimal point to display.
      • toIniString

        @NonNull
        public java.lang.String toIniString()
        Represents a Storage as a string suitable for use in an INI file.