55 * DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THE
66 * AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE"
77 * BUTTON AT THE BOTTOM OF THIS PAGE.
8- *
8+ *
99 * Specification: JSR-354 Money and Currency API ("Specification")
10- *
10+ *
1111 * Copyright (c) 2012-2015, Credit Suisse All rights reserved.
1212 */
1313package javax .money ;
1414
1515
16+
1617/**
1718 * Represents an operation on a single {@link MonetaryAmount} that produces a
1819 * result of type {@link MonetaryAmount}.
2324 * There are two equivalent ways of using a {@code MonetaryOperator}. The first
2425 * is to invoke the method on this interface. The second is to use
2526 * {@link MonetaryAmount#with(MonetaryOperator)}:
26- *
27+ *
2728 * <pre>
2829 * // these two lines are equivalent, but the second approach is recommended
2930 * monetary = thisOperator.apply(monetary);
3031 * monetary = monetary.with(thisOperator);
3132 * </pre>
32- *
33+ *
3334 * It is recommended to use the second approach, {@code with(MonetaryOperator)},
3435 * as it is a lot clearer to read in code.
35- *
36+ *
3637 * <h4>Implementation specification</h4>
3738 * The implementation must take the input object and apply it. The
3839 * implementation defines the logic of the operator and is responsible for
4546 * <p>
4647 * This method may be called from multiple threads in parallel. It must be
4748 * thread-safe when invoked.
48- *
49+ *
4950 * <p>
5051 * This interface extends {@code java.util.function.UnaryOperator} introduced by Java 8.
51- *
52+ *
5253 * @author Werner Keil
5354 * @author Anatole Tresch
54- *
55+ *
5556 * @version 0.9
5657 */
5758@ FunctionalInterface
@@ -63,4 +64,12 @@ public interface MonetaryOperator{
6364 * @return the applied amount.
6465 */
6566 MonetaryAmount apply (MonetaryAmount amount );
67+
68+ /**
69+ * Returns a function that always returns its input argument.
70+ * @return an operator that always returns its input argument
71+ */
72+ static MonetaryOperator identity () {
73+ return m -> m ;
74+ }
6675}
0 commit comments