Class SizeInBytes

  • All Implemented Interfaces:
    java.io.Serializable

    public final class SizeInBytes
    extends java.lang.Object
    implements java.io.Serializable
    The class to represent some size data. A size may be formatted into the form like "1.234MB". Also the size may be not fixed but describe some size range with the given bias.
    See Also:
    Serialized Form
    • Field Detail

      • PATTERN_SIZE

        public static final java.util.regex.Pattern PATTERN_SIZE
    • Constructor Detail

      • SizeInBytes

        public SizeInBytes​(java.lang.String sizeInfo)
                    throws java.lang.NumberFormatException,
                           java.lang.IllegalArgumentException
        Throws:
        java.lang.NumberFormatException
        java.lang.IllegalArgumentException
      • SizeInBytes

        public SizeInBytes​(long size)
      • SizeInBytes

        public SizeInBytes​(long min,
                           long max,
                           double bias)
      • SizeInBytes

        public SizeInBytes​(SizeInBytes other)
        Copy constructor
    • Method Detail

      • toFixedSize

        public static long toFixedSize​(java.lang.String value)
                                throws java.lang.NumberFormatException
        Parse the fixed size info. Example "16MB" -> 16777216
        Returns:
        the numeric size
        Throws:
        java.lang.NumberFormatException
      • formatFixedSize

        public static java.lang.String formatFixedSize​(long v)
        Format the size info. Example: 16777216 -> "16MB"
        Parameters:
        v - the numeric size
        Returns:
        the formatted size info
      • get

        public long get()
        Returns:
        the numeric size if fixed, the random size in the specified range if not fixed (the bias also used)
      • getMin

        public long getMin()
      • getMax

        public long getMax()
      • getAvg

        public final long getAvg()
        Returns:
        the average fixed size value for 1st 100 returned by get() size values
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public final boolean equals​(java.lang.Object o)
        Compare two sizes
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if fixed sizes are equal either minimums & ranges & biases are equal, false otherwise