@PublicEvolving public class MemorySize extends Object implements Serializable, Comparable<MemorySize>
The size can be parsed from a text expression. If the expression is a pure number, the value will be interpreted as bytes.
Modifier and Type | Class and Description |
---|---|
static class |
MemorySize.MemoryUnit
Enum which defines memory unit, mostly used to parse value from configuration file.
|
Modifier and Type | Field and Description |
---|---|
static MemorySize |
MAX_VALUE |
static MemorySize |
ZERO |
Constructor and Description |
---|
MemorySize(long bytes)
Constructs a new MemorySize.
|
Modifier and Type | Method and Description |
---|---|
MemorySize |
add(MemorySize that) |
int |
compareTo(MemorySize that) |
MemorySize |
divide(long by) |
boolean |
equals(Object obj) |
long |
getBytes()
Gets the memory size in bytes.
|
long |
getGibiBytes()
Gets the memory size in Gibibytes (= 1024 Mebibytes).
|
long |
getKibiBytes()
Gets the memory size in Kibibytes (= 1024 bytes).
|
int |
getMebiBytes()
Gets the memory size in Mebibytes (= 1024 Kibibytes).
|
long |
getTebiBytes()
Gets the memory size in Tebibytes (= 1024 Gibibytes).
|
int |
hashCode() |
MemorySize |
multiply(double multiplier) |
static MemorySize |
ofMebiBytes(long mebiBytes) |
static MemorySize |
parse(String text)
Parses the given string as as MemorySize.
|
static MemorySize |
parse(String text,
MemorySize.MemoryUnit defaultUnit)
Parses the given string with a default unit.
|
static long |
parseBytes(String text)
Parses the given string as bytes.
|
MemorySize |
subtract(MemorySize that) |
String |
toHumanReadableString() |
String |
toString() |
public static final MemorySize ZERO
public static final MemorySize MAX_VALUE
public MemorySize(long bytes)
bytes
- The size, in bytes. Must be zero or larger.public static MemorySize ofMebiBytes(long mebiBytes)
public long getBytes()
public long getKibiBytes()
public int getMebiBytes()
public long getGibiBytes()
public long getTebiBytes()
public String toHumanReadableString()
public int compareTo(MemorySize that)
compareTo
in interface Comparable<MemorySize>
public MemorySize add(MemorySize that)
public MemorySize subtract(MemorySize that)
public MemorySize multiply(double multiplier)
public MemorySize divide(long by)
public static MemorySize parse(String text) throws IllegalArgumentException
text
- The string to parseIllegalArgumentException
- Thrown, if the expression cannot be parsed.public static MemorySize parse(String text, MemorySize.MemoryUnit defaultUnit) throws IllegalArgumentException
text
- The string to parse.defaultUnit
- specify the default unit.IllegalArgumentException
- Thrown, if the expression cannot be parsed.public static long parseBytes(String text) throws IllegalArgumentException
MemorySize
.text
- The string to parseIllegalArgumentException
- Thrown, if the expression cannot be parsed.Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.