public class Value
Class that models a generic monetary value. A Value object is immutable. All changing operations yield a new Value object and do not affect the original object.
Modifier and Type | Class and Description |
---|---|
static class |
Value.Companion
Contains static methods
|
Modifier and Type | Field and Description |
---|---|
static Value.Companion |
Companion
Contains static methods
|
Constructor and Description |
---|
Value(java.math.BigDecimal value,
Currency currency)
Class that models a generic monetary value.
A Value object is immutable.
All changing operations yield a new Value object and do not affect the original object.
|
Value(java.lang.String value,
Currency currency)
Generates a Value object from a String and a currency.
|
Modifier and Type | Method and Description |
---|---|
java.math.BigDecimal |
component1()
:
|
Currency |
component2()
:
|
Value |
convert(Currency currency)
Converts this Value to another currency
|
Value |
copy(java.math.BigDecimal value,
Currency currency)
Class that models a generic monetary value.
A Value object is immutable.
All changing operations yield a new Value object and do not affect the original object.
|
boolean |
equals(java.lang.Object other)
Overrides the data class equals method to use the compareTo instead of equals method of the BigDecimal
class. This ensures that 0.00 and 0.0 are treated the same.
|
java.lang.String |
format(boolean useCurrencySymbol,
java.lang.String decimalSymbol,
boolean currencySymbolPositionBack,
java.lang.Integer overrideAccuracy)
Formats the value into a configurable human-readable String
|
Currency |
getCurrency()
:
|
java.math.BigDecimal |
getValue()
:
|
int |
hashCode() |
Value |
minus(Value value)
Subtracts a value from this value and returns the result
|
Value |
not()
Negates the value of this Value object. Equivalent to multiplying with -1
|
Value |
plus(Value value)
Adds two Values and returns the sum
|
java.lang.String |
serialize()
Serializes the value
|
Value |
times(int multiplicand)
Multiplies the value by an integer value
|
java.lang.String |
toString()
Creates a string representation of the value that is automatically used in string interpolation
|
public static Value.Companion Companion
Contains static methods
public Value(java.math.BigDecimal value, Currency currency)
Class that models a generic monetary value. A Value object is immutable. All changing operations yield a new Value object and do not affect the original object.
value
- : The value of the Value as a BigDecimal, which allows arbitrary precision without rounding errorscurrency
- : The currency of the Valuevalue
- : The value of the Value as a BigDecimal, which allows arbitrary precision without rounding errorscurrency
- : The currency of the Valuepublic Value(java.lang.String value, Currency currency)
Generates a Value object from a String and a currency.
value
- : The String to parse a value fromcurrency
- : The currency of the valuepublic Value plus(Value value)
Adds two Values and returns the sum
value
- : The value with which to create a sum withpublic Value minus(Value value)
Subtracts a value from this value and returns the result
value
- : The value to subtract from this valuepublic Value times(int multiplicand)
Multiplies the value by an integer value
multiplicand
- : The value with which to multiply this valuepublic Value not()
Negates the value of this Value object. Equivalent to multiplying with -1
public boolean equals(java.lang.Object other)
Overrides the data class equals method to use the compareTo instead of equals method of the BigDecimal class. This ensures that 0.00 and 0.0 are treated the same.
other
- : The object to compare topublic Value convert(Currency currency)
Converts this Value to another currency
currency
- : The currency to which to convert topublic java.lang.String format(boolean useCurrencySymbol, java.lang.String decimalSymbol, boolean currencySymbolPositionBack, java.lang.Integer overrideAccuracy)
Formats the value into a configurable human-readable String
useCurrencySymbol
- : Specifies if the currency's symbol (e.g. €) should be used or the currency's name (EUR)decimalSymbol
- : The symbol to use as a decimal point. Defaults to a decimal point.currencySymbolPositionBack
- : Specifies if the currency symbol is displayed before or after the valueoverrideAccuracy
- : Overrides the inherent accuracy of a currencypublic java.lang.String toString()
Creates a string representation of the value that is automatically used in string interpolation
public java.lang.String serialize()
Serializes the value
public java.math.BigDecimal getValue()
:
The value of the Value as a BigDecimal, which allows arbitrary precision without rounding errors
public Currency getCurrency()
:
The currency of the Value
public java.math.BigDecimal component1()
:
The value of the Value as a BigDecimal, which allows arbitrary precision without rounding errors
public Currency component2()
:
The currency of the Value
public Value copy(java.math.BigDecimal value, Currency currency)
Class that models a generic monetary value. A Value object is immutable. All changing operations yield a new Value object and do not affect the original object.
value
- : The value of the Value as a BigDecimal, which allows arbitrary precision without rounding errorscurrency
- : The currency of the Valuepublic int hashCode()