@FunctionalInterface public interface MonetaryOperator
MonetaryAmount
that produces a
result of type MonetaryAmount
.
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 use
MonetaryAmount.with(MonetaryOperator)
:
// these two lines are equivalent, but the second approach is recommended monetary = thisOperator.apply(monetary); monetary = monetary.with(thisOperator);It is recommended to use the second approach,
with(MonetaryOperator)
,
as it is a lot clearer to read in code.
MonetaryAmount
to
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.
This interface extends java.util.function.UnaryOperator
introduced by Java 8.
Modifier and Type | Method and Description |
---|---|
MonetaryAmount |
apply(MonetaryAmount amount)
Applies the operator on the given amount.
|
MonetaryAmount apply(MonetaryAmount amount)
amount
- the amount to be operated on.Copyright © 2012–2016 JSR 354 - Expert Group. All rights reserved.