public final class StorageSize extends java.lang.Object implements java.lang.Comparable<StorageSize>, java.io.Serializable
Note: this class has a natural ordering that is inconsistent with equals.
Represents an amount of space in a given unitgetAmount() unless a rounded value is acceptable (which it rarely is). In most
circumstances users are recommended to use getDecimalAmount()| Modifier and Type | Field and Description |
|---|---|
static StorageSize |
ZERO |
| Modifier | Constructor and Description |
|---|---|
|
StorageSize(java.math.BigDecimal amount,
StorageUnit unit)
Creates a new StorageSize where the value is an approximation of the provided value
Since this is an approximation some information may be lost. |
|
StorageSize(java.math.BigInteger amount,
StorageUnit unit)
Creates a new StorageSize where the value is equal to the provided value
If the unit is in BITS then any fractional bytes resulting from the conversion will be discarded (e.g. |
|
StorageSize(long amount,
StorageUnit unit) |
protected |
StorageSize(StorageUnit unit,
java.math.BigInteger bits)
Internal constructor.
|
| Modifier and Type | Method and Description |
|---|---|
StorageSize |
add(StorageSize that)
Adds two storage sizes together, using the smallest unit as the resulting StorageSize's unit
|
int |
compareTo(long amount,
StorageUnit unit)
Performs a comparison based on the number of bits represented
Since this class has a natural ordering that is inconsistent with equals, this method may return 0 where equals would not return 0 - since this compares based on bits but equals tests based on the
unit+amount |
int |
compareTo(StorageSize that)
Performs a comparison based on the number of bits represented
Since this class has a natural ordering that is inconsistent with equals, this method may return 0 where equals would not return 0 - since this compares based on bits but equals tests based on the
unit+amount |
StorageSize |
convert(StorageUnit toUnit)
Convert this StorageSize to use the named unit
|
boolean |
equals(java.lang.Object o)
Determines whether the amount and unit represented by the other object is exactly equal to this object;
N.B. |
java.math.BigInteger |
getAmount()
Deprecated.
|
java.math.BigInteger |
getAmount(StorageUnit unit)
Converts the size of this StorageSize to another unit, rounding the result to an integer
This method may result in the loss of information (due to rounding). |
java.math.BigInteger |
getBits()
The number of bits represented by this object
|
java.math.BigInteger |
getBytes()
Return the number of bytes this StorageSize represents
This method may result in information being lost (e.g. |
java.math.BigDecimal |
getDecimalAmount()
Converts the size of this StorageSize to another unit, returning the result as a real number (using the BigDecimal type)
Uses the default representation unit for this type The calculations may result in minimal loss of precision, however this is unavoidable. |
java.math.BigDecimal |
getDecimalAmount(StorageUnit unit)
Converts the size of this StorageSize to another unit, returning the result as a real number (using the BigDecimal type)
The calculations may result in minimal loss of precision, however this is unavoidable. |
StorageUnit |
getUnit()
The unit which this Storage Size should be expressed by default
|
int |
hashCode() |
boolean |
isZero()
Determines whether this StorageSize represents zero (which is the same in any unit)
|
StorageSize |
multiply(java.math.BigInteger by)
Multiplies the storage size by a certain amount
|
StorageSize |
subtract(StorageSize that)
Subtracts a storage size from the current object, using the smallest unit as the resulting StorageSize's unit
|
java.lang.String |
toPlainString()
Return a String version of this size (e.g.
|
java.lang.String |
toPlainString(StorageUnit unit)
Return a String version of this size (e.g.
|
java.lang.String |
toShortString()
Return a short ISO String version of this size (e.g.
|
java.lang.String |
toShortString(StorageUnit unit)
Return a short ISO String version of this size using the provided unit (e.g.
|
java.lang.String |
toString() |
public static final StorageSize ZERO
public StorageSize(java.math.BigInteger amount,
StorageUnit unit)
amount - the amount component of the space this StorageSize should representunit - the unit that amount is expressed inpublic StorageSize(java.math.BigDecimal amount,
StorageUnit unit)
amount - the amount component of the space this StorageSize should representunit - the unit that amount is expressed in. If the unit is BITS then any fractional bits will be
ignored (i.e. identical to calling the BigInteger constructor with amount.toBigInteger())protected StorageSize(StorageUnit unit, java.math.BigInteger bits)
unit - the unit the user would like to see their StorageSize in by defaultbytes - the number of bytes this StorageSize representspublic StorageSize(long amount,
StorageUnit unit)
public java.math.BigInteger getBytes()
getBits
method if this loss is unacceptablepublic java.math.BigInteger getBits()
public StorageUnit getUnit()
public java.math.BigDecimal getDecimalAmount()
public java.math.BigDecimal getDecimalAmount(StorageUnit unit)
unit - the unit to use (instead of the default StorageSize unit)@Deprecated public java.math.BigInteger getAmount()
public java.math.BigInteger getAmount(StorageUnit unit)
unit - the unit to use (instead of the default StorageSize unit)unit.public boolean isZero()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toPlainString()
public java.lang.String toPlainString(StorageUnit unit)
unit - the desired unitpublic java.lang.String toShortString()
public java.lang.String toShortString(StorageUnit unit)
unit - the unit to represent the amount inpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.ObjectObject.equals(java.lang.Object)public StorageSize convert(StorageUnit toUnit)
toUnit - public StorageSize add(StorageSize that)
that - public StorageSize multiply(java.math.BigInteger by)
that - public StorageSize subtract(StorageSize that)
storage - public int compareTo(StorageSize that)
equals would not return 0 - since this compares based on bits but equals tests based on the
unit+amountcompareTo in interface java.lang.Comparable<StorageSize>that - some other storage amountComparable.compareTo(java.lang.Object)public int compareTo(long amount,
StorageUnit unit)
equals would not return 0 - since this compares based on bits but equals tests based on the
unit+amountamount - the number of units for this amountunit - the unit that amount should be expressed inComparable.compareTo(java.lang.Object)Copyright © 2014. All Rights Reserved.