Package org.apache.solr.schema
Class CurrencyValue
java.lang.Object
org.apache.solr.schema.CurrencyValue
- All Implemented Interfaces:
Comparable<CurrencyValue>
Represents a Currency field value, which includes a long amount and ISO currency code.
-
Constructor Summary
ConstructorsConstructorDescriptionCurrencyValue(long amount, String currencyCode) Constructs a new currency value. -
Method Summary
Modifier and TypeMethodDescriptionintstatic longconvertAmount(double exchangeRate, int sourceFractionDigits, long sourceAmount, int targetFractionDigits) Performs a currency conversion & unit conversion.static longconvertAmount(double exchangeRate, String sourceCurrencyCode, long sourceAmount, String targetCurrencyCode) Performs a currency conversion & unit conversion.static longconvertAmount(ExchangeRateProvider exchangeRates, String sourceCurrencyCode, long sourceAmount, String targetCurrencyCode) Performs a currency conversion & unit conversion.convertTo(ExchangeRateProvider exchangeRates, String targetCurrencyCode) Returns a new CurrencyValue that is the conversion of this CurrencyValue to the specified currency.longThe amount of the CurrencyValue.The ISO currency code of the CurrencyValue.static CurrencyValueConstructs a new currency value by parsing the specific input.strValue()Returns a string representing the currency value such as "3.14,USD" for a CurrencyValue of $3.14 USD.toString()
-
Constructor Details
-
CurrencyValue
Constructs a new currency value.- Parameters:
amount- The amount.currencyCode- The currency code.
-
-
Method Details
-
parse
Constructs a new currency value by parsing the specific input.Currency values are expected to be in the format <amount>,<currency code>, for example, "500,USD" would represent 5 U.S. Dollars.
If no currency code is specified, the default is assumed.
- Parameters:
externalVal- The value to parse.defaultCurrency- The default currency.- Returns:
- The parsed CurrencyValue.
-
getAmount
public long getAmount()The amount of the CurrencyValue.- Returns:
- The amount.
-
getCurrencyCode
The ISO currency code of the CurrencyValue.- Returns:
- The currency code.
-
convertAmount
public static long convertAmount(ExchangeRateProvider exchangeRates, String sourceCurrencyCode, long sourceAmount, String targetCurrencyCode) Performs a currency conversion & unit conversion.- Parameters:
exchangeRates- Exchange rates to apply.sourceCurrencyCode- The source currency code.sourceAmount- The source amount.targetCurrencyCode- The target currency code.- Returns:
- The converted indexable units after the exchange rate and currency fraction digits are applied.
-
convertAmount
public static long convertAmount(double exchangeRate, int sourceFractionDigits, long sourceAmount, int targetFractionDigits) Performs a currency conversion & unit conversion.- Parameters:
exchangeRate- Exchange rate to apply.sourceFractionDigits- The fraction digits of the source.sourceAmount- The source amount.targetFractionDigits- The fraction digits of the target.- Returns:
- The converted indexable units after the exchange rate and currency fraction digits are applied.
-
convertAmount
public static long convertAmount(double exchangeRate, String sourceCurrencyCode, long sourceAmount, String targetCurrencyCode) Performs a currency conversion & unit conversion.- Parameters:
exchangeRate- Exchange rate to apply.sourceCurrencyCode- The source currency code.sourceAmount- The source amount.targetCurrencyCode- The target currency code.- Returns:
- The converted indexable units after the exchange rate and currency fraction digits are applied.
-
convertTo
Returns a new CurrencyValue that is the conversion of this CurrencyValue to the specified currency.- Parameters:
exchangeRates- The exchange rate provider.targetCurrencyCode- The target currency code to convert this CurrencyValue to.- Returns:
- The converted CurrencyValue.
-
strValue
Returns a string representing the currency value such as "3.14,USD" for a CurrencyValue of $3.14 USD. -
compareTo
- Specified by:
compareToin interfaceComparable<CurrencyValue>
-
toString
-