java.lang.Object
com.hedera.hashgraph.sdk.Hbar
- All Implemented Interfaces:
Comparable<Hbar>
Represents a quantity of hbar.
Implemented as a wrapper class to force handling of units. Direct interfacing with Hedera accepts amounts in tinybars however the nominal unit is hbar.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHbar(long amount) Constructs a new Hbar of the specified value.Constructs a new hbar of the specified value in the specified unit.Hbar(BigDecimal amount) Constructs a new Hbar of the specified, possibly fractional value.Hbar(BigDecimal amount, HbarUnit unit) Constructs a new hbar of the specified value in the specified unit. -
Method Summary
Modifier and TypeMethodDescriptionintbooleanstatic Hbarfrom(long hbars) Returns an Hbar whose value is equal to the specified long.static HbarReturns an Hbar representing the value in the given units.static Hbarfrom(BigDecimal hbars) Returns an Hbar whose value is equal to the specified long.static Hbarfrom(BigDecimal amount, HbarUnit unit) Returns an Hbar representing the value in the given units.static HbarfromString(CharSequence text) Converts the provided string into an amount of hbars.static HbarfromString(CharSequence text, HbarUnit unit) Converts the provided string into an amount of hbars.static HbarfromTinybars(long tinybars) Returns an Hbar converted from the specified number of tinybars.getValue()Returns the number of Hbars.inthashCode()negated()Returns a Hbar whose value is-this.Convert this hbar value to a different unit.toString()Convert hbar to string representation in specified units.longConvert this hbar value to Tinybars.
-
Field Details
-
ZERO
A constant value of zero hbars. -
MAX
A constant value of the maximum number of hbars. -
MIN
A constant value of the minimum number of hbars.
-
-
Constructor Details
-
Hbar
public Hbar(long amount) Constructs a new Hbar of the specified value.- Parameters:
amount- The amount of Hbar
-
Hbar
Hbar(long amount, HbarUnit unit) Constructs a new hbar of the specified value in the specified unit.HbarUnit- Parameters:
amount- the amountunit- the unit for amount
-
Hbar
Constructs a new Hbar of the specified, possibly fractional value.The equivalent amount in tinybar must be an integer and fit in a
long(64-bit signed integer).E.g.,
1.23456789is a valid amount of hbar but0.123456789is not.- Parameters:
amount- The amount of Hbar
-
Hbar
Hbar(BigDecimal amount, HbarUnit unit) Constructs a new hbar of the specified value in the specified unit.HbarUnit- Parameters:
amount- the amountunit- the unit for amount
-
-
Method Details
-
fromString
Converts the provided string into an amount of hbars.- Parameters:
text- The string representing the amount of Hbar- Returns:
Hbar
-
fromString
Converts the provided string into an amount of hbars.- Parameters:
text- The string representing the amount of set unitsunit- The unit to convert from to Hbar- Returns:
Hbar
-
from
Returns an Hbar whose value is equal to the specified long.- Parameters:
hbars- The value of Hbar- Returns:
Hbar
-
from
Returns an Hbar representing the value in the given units.- Parameters:
amount- The long representing the amount of set unitsunit- The unit to convert from to Hbar- Returns:
Hbar
-
from
Returns an Hbar whose value is equal to the specified long.- Parameters:
hbars- The BigDecimal representing the amount of Hbar- Returns:
Hbar
-
from
Returns an Hbar representing the value in the given units.- Parameters:
amount- The BigDecimal representing the amount of set unitsunit- The unit to convert from to Hbar- Returns:
Hbar
-
fromTinybars
Returns an Hbar converted from the specified number of tinybars.- Parameters:
tinybars- The long representing the amount of tinybar- Returns:
Hbar
-
to
Convert this hbar value to a different unit.- Parameters:
unit- The unit to convert to from Hbar- Returns:
- BigDecimal
-
toTinybars
public long toTinybars()Convert this hbar value to Tinybars.- Returns:
- long
-
getValue
Returns the number of Hbars.- Returns:
- BigDecimal
-
negated
Returns a Hbar whose value is-this.- Returns:
- Hbar
-
toString
-
toString
Convert hbar to string representation in specified units.- Parameters:
unit- the desired unit- Returns:
- the string representation
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<Hbar>
-