- java.lang.Object
-
- com.github.akurilov.commons.system.SizeInBytes
-
- All Implemented Interfaces:
java.io.Serializable
public final class SizeInBytes extends java.lang.Object implements java.io.SerializableThe 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 Summary
Fields Modifier and Type Field Description static java.util.regex.PatternPATTERN_SIZEstatic java.lang.StringSIZE_UNITS
-
Constructor Summary
Constructors Constructor Description SizeInBytes(long size)SizeInBytes(long min, long max, double bias)SizeInBytes(SizeInBytes other)Copy constructorSizeInBytes(java.lang.String sizeInfo)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)Compare two sizesstatic java.lang.StringformatFixedSize(long v)Format the size info.longget()longgetAvg()longgetMax()longgetMin()static longtoFixedSize(java.lang.String value)Parse the fixed size info.java.lang.StringtoString()
-
-
-
Field Detail
-
SIZE_UNITS
public static final java.lang.String SIZE_UNITS
- See Also:
- Constant Field Values
-
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.NumberFormatExceptionjava.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.NumberFormatExceptionParse 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:
toStringin classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
Compare two sizes- Overrides:
equalsin classjava.lang.Object- Returns:
- true if fixed sizes are equal either minimums & ranges & biases are equal, false otherwise
-
-