Package io.activej.common
Class MemSize
java.lang.Object
io.activej.common.MemSize
- All Implemented Interfaces:
Comparable<MemSize>
Encapsulates a size in bytes as a convenient abstraction
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull MemSizebytes(long bytes) Creates aMemSizeof n bytesintboolean@NotNull Stringformat()Formats thisMemSizeas a stringstatic @NotNull MemSizegigabytes(long gigabytes) Creates aMemSizeof n gigabytesinthashCode()static @NotNull MemSizekilobytes(long kilobytes) Creates aMemSizeof n kilobytes@NotNull MemSizemap(@NotNull LongUnaryOperator fn) static @NotNull MemSizemegabytes(long megabytes) Creates aMemSizeof n megabytesstatic @NotNull MemSizeof(long bytes) Creates aMemSizeof n bytesstatic @NotNull MemSizeterabytes(long terabytes) Creates aMemSizeof n terabytesinttoInt()Returns a number of bytes is thisMemSizeasintlongtoLong()Returns a number of bytes is thisMemSize@NotNull StringtoString()static @NotNull MemSize
-
Field Details
-
ZERO
-
KB
public static final long KB- See Also:
-
MB
public static final long MB- See Also:
-
GB
public static final long GB- See Also:
-
TB
public static final long TB- See Also:
-
-
Method Details
-
of
Creates aMemSizeof n bytes- Parameters:
bytes- a number of bytes- Returns:
- a new instance of
MemSizeof n bytes
-
bytes
Creates aMemSizeof n bytes -
kilobytes
Creates aMemSizeof n kilobytes- Parameters:
kilobytes- a number of kilobytes- Returns:
- a new instance of
MemSizeof n kilobytes
-
megabytes
Creates aMemSizeof n megabytes- Parameters:
megabytes- a number of megabytes- Returns:
- a new instance of
MemSizeof n megabytes
-
gigabytes
Creates aMemSizeof n gigabytes- Parameters:
gigabytes- a number of gigabytes- Returns:
- a new instance of
MemSizeof n gigabytes
-
terabytes
Creates aMemSizeof n terabytes- Parameters:
terabytes- a number of terabytes- Returns:
- a new instance of
MemSizeof n terabytes
-
toLong
public long toLong()Returns a number of bytes is thisMemSize -
toInt
public int toInt()Returns a number of bytes is thisMemSizeasint- Throws:
IllegalStateException- if number of bytes is greater thanInteger.MAX_VALUE
-
map
Returns a newMemSizewhich has a number of bytes equal to the result of a mapping function applied to the number of bytes of thisMemSize- Parameters:
fn- a mapping function that maps current size to a new one- Returns:
- a new
MemSizewith mapped number of bytes
-
valueOf
- Parameters:
string- a string to be parsed- Returns:
- a parsed
MemSize - Throws:
IllegalArgumentException- on malformed string- See Also:
-
format
Formats thisMemSizeas a stringA string format is the same as
valueOf(String)method parses- Returns:
- a string that represents a
MemSize - See Also:
-
compareTo
- Specified by:
compareToin interfaceComparable<MemSize>
-
equals
-
hashCode
public int hashCode() -
toString
-