Skip to content

Commit 839a8e4

Browse files
author
otaviojava
committed
Add identity method in MonetaryOperator
1 parent ff432ba commit 839a8e4

File tree

3 files changed

+24
-31
lines changed

3 files changed

+24
-31
lines changed

src/etc/jsr354-api clean install.launch

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/javax/money/DefaultMonetaryRoundingsSingletonSpi.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public RoundingQueryBuilder createRoundingQueryBuilder() {
5858
*
5959
* @return the default rounding, never null.
6060
*/
61-
public MonetaryRounding getDefaultRounding() {
61+
@Override
62+
public MonetaryRounding getDefaultRounding() {
6263
return DEFAULT_ROUNDING;
6364
}
6465

@@ -132,7 +133,8 @@ public List<String> getDefaultProviderChain() {
132133
* #getDefaultProviders is used, not null.
133134
* @return the set of custom rounding ids, never {@code null}.
134135
*/
135-
public Set<String> getRoundingNames(String... providers) {
136+
@Override
137+
public Set<String> getRoundingNames(String... providers) {
136138
Set<String> result = new HashSet<>();
137139
String[] providerNames = providers;
138140
if (providerNames.length == 0) {
@@ -161,7 +163,9 @@ public Set<String> getRoundingNames(String... providers) {
161163
*/
162164
private static final class DefaultCurrencyRounding implements MonetaryRounding, Serializable {
163165

164-
private static final RoundingContext ROUNDING_CONTEXT = RoundingContextBuilder.of("default", "default").build();
166+
private static final long serialVersionUID = 8641545296538357839L;
167+
168+
private static final RoundingContext ROUNDING_CONTEXT = RoundingContextBuilder.of("default", "default").build();
165169

166170
@Override
167171
public MonetaryAmount apply(MonetaryAmount amount) {

src/main/java/javax/money/MonetaryOperator.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
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
*/
1313
package javax.money;
1414

1515

16+
1617
/**
1718
* Represents an operation on a single {@link MonetaryAmount} that produces a
1819
* result of type {@link MonetaryAmount}.
@@ -23,16 +24,16 @@
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
@@ -45,13 +46,13 @@
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

Comments
 (0)