-
- All Known Subinterfaces:
CurrencyConversion,MonetaryRounding
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface MonetaryOperatorRepresents an operation on a singleMonetaryAmountthat produces a result of typeMonetaryAmount.Examples might be an operator that rounds the amount to the nearest 1000, or one that performs currency conversion.
There are two equivalent ways of using a
MonetaryOperator. The first is to invoke the method on this interface. The second is to useMonetaryAmount.with(MonetaryOperator):
It is recommended to use the second approach,// these two lines are equivalent, but the second approach is recommended monetary = thisOperator.apply(monetary); monetary = monetary.with(thisOperator);with(MonetaryOperator), as it is a lot clearer to read in code.Implementation specification
The implementation must take the input object and apply it. The implementation defines the logic of the operator and is responsible for documenting that logic. It may use any method on
MonetaryAmountto determine the result.The input object must not be altered. Instead, an altered copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable monetary amounts.
This method may be called from multiple threads in parallel. It must be thread-safe when invoked.
- Version:
- 1.0
- Author:
- Werner Keil, Anatole Tresch
-
-
Method Summary
Modifier and Type Method Description MonetaryAmountapply(MonetaryAmount amount)Applies the operator on the given amount.
-
-
-
Method Detail
-
apply
MonetaryAmount apply(MonetaryAmount amount)
Applies the operator on the given amount.- Parameters:
amount- the amount to be operated on.- Returns:
- the applied amount.
-
-