Skip to content

Commit c17e4c4

Browse files
committed
Enhanced example in JavaDoc.
2 parents 88f9b68 + 307192f commit c17e4c4

File tree

1 file changed

+57
-47
lines changed

1 file changed

+57
-47
lines changed

src/main/java/javax/money/MonetaryAdjuster.java

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@
1515
/**
1616
* Strategy for adjusting a monetary amount.
1717
* <p>
18-
* Adjusters are a key tool for modifying monetary amounts.
19-
* They match the strategy design pattern, allowing different types of
20-
* adjustment to be easily captured.
21-
* Examples might be an adjuster that rounds the amount to the nearest 1000,
22-
* or one that performs currency conversion.
18+
* Adjusters are a key tool for modifying monetary amounts. They match the
19+
* strategy design pattern, allowing different types of adjustment to be easily
20+
* captured. Examples might be an adjuster that rounds the amount to the nearest
21+
* 1000, or one that performs currency conversion.
2322
* <p>
24-
* There are two equivalent ways of using a {@code MonetaryAdjuster}.
25-
* The first is to invoke the method on this interface.
26-
* The second is to use {@link MonetaryAmount#with(MonetaryAdjuster)}:
23+
* There are two equivalent ways of using a {@code MonetaryAdjuster}. The first
24+
* is to invoke the method on this interface. The second is to use
25+
* {@link MonetaryAmount#with(MonetaryAdjuster)}, whereas implementations of
26+
* {@link MonetaryAmount#with(MonetaryAdjuster)} must return the concrete type,
27+
* instead of the interface to support a fluent style:
28+
*
2729
* <pre>
28-
* // these two lines are equivalent, but the second approach is recommended
29-
* monetary = thisAdjuster.adjustInto(monetary);
30-
* monetary = monetary.with(thisAdjuster);
30+
* // these two lines are equivalent, but the second approach is recommended
31+
* monetary = thisAdjuster.adjustInto(monetary);
32+
* monetary = anotherAdjuster.adjustInto(monetary);
33+
*
34+
* // second approach, using a fluent API
35+
* monetary = monetary.with(thisAdjuster).with(anotherAdjuster);
3136
* </pre>
37+
*
3238
* It is recommended to use the second approach, {@code with(MonetaryAdjuster)},
3339
* as it is a lot clearer to read in code.
3440
*
@@ -40,42 +46,46 @@
4046
public interface MonetaryAdjuster {
4147

4248
/**
43-
* Adjusts the specified monetary object.
44-
* <p>
45-
* This adjusts the specified monetary object using the logic
46-
* encapsulated in the implementing class.
47-
* Examples might be an adjuster that rounds the amount to the nearest 1000,
48-
* or one that performs currency conversion.
49-
* <p>
50-
* There are two equivalent ways of using a {@code MonetaryAdjuster}.
51-
* The first is to invoke the method on this interface.
52-
* The second is to use {@link MonetaryAmount#with(MonetaryAdjuster)}:
53-
* <pre>
54-
* // these two lines are equivalent, but the second approach is recommended
55-
* monetary = thisAdjuster.adjustInto(monetary);
56-
* monetary = monetary.with(thisAdjuster);
57-
* </pre>
58-
* It is recommended to use the second approach, {@code with(MonetaryAdjuster)},
59-
* as it is a lot clearer to read in code.
60-
*
61-
* <h4>Implementation specification</h4>
62-
* The implementation must take the input object and adjust it.
63-
* The implementation defines the logic of the adjustment and is responsible for
64-
* documenting that logic.
65-
* It may use any method on {@code MonetaryAmount} to determine the result.
66-
* <p>
67-
* The input object must not be altered.
68-
* Instead, an adjusted copy of the original must be returned.
69-
* This provides equivalent, safe behavior for immutable and mutable monetary amounts.
70-
* <p>
71-
* This method may be called from multiple threads in parallel.
72-
* It must be thread-safe when invoked.
73-
*
74-
* @param amount the amount to adjust, not null
75-
* @return a monetary amount with the adjustment made, not null
76-
* @throws MonetaryException if unable to make the adjustment
77-
* @throws ArithmeticException if numeric overflow occurs
78-
*/
49+
* Adjusts the specified monetary object.
50+
* <p>
51+
* This adjusts the specified monetary object using the logic encapsulated
52+
* in the implementing class. Examples might be an adjuster that rounds the
53+
* amount to the nearest 1000, or one that performs currency conversion.
54+
* <p>
55+
* There are two equivalent ways of using a {@code MonetaryAdjuster}. The
56+
* first is to invoke the method on this interface. The second is to use
57+
* {@link MonetaryAmount#with(MonetaryAdjuster)}:
58+
*
59+
* <pre>
60+
* // these two lines are equivalent, but the second approach is recommended
61+
* monetary = thisAdjuster.adjustInto(monetary);
62+
* monetary = monetary.with(thisAdjuster);
63+
* </pre>
64+
*
65+
* It is recommended to use the second approach,
66+
* {@code with(MonetaryAdjuster)}, as it is a lot clearer to read in code.
67+
*
68+
* <h4>Implementation specification</h4>
69+
* The implementation must take the input object and adjust it. The
70+
* implementation defines the logic of the adjustment and is responsible for
71+
* documenting that logic. It may use any method on {@code MonetaryAmount}
72+
* to determine the result.
73+
* <p>
74+
* The input object must not be altered. Instead, an adjusted copy of the
75+
* original must be returned. This provides equivalent, safe behavior for
76+
* immutable and mutable monetary amounts.
77+
* <p>
78+
* This method may be called from multiple threads in parallel. It must be
79+
* thread-safe when invoked.
80+
*
81+
* @param amount
82+
* the amount to adjust, not null
83+
* @return a monetary amount with the adjustment made, not null
84+
* @throws MonetaryException
85+
* if unable to make the adjustment
86+
* @throws ArithmeticException
87+
* if numeric overflow occurs
88+
*/
7989
public MonetaryAmount adjustInto(MonetaryAmount amount);
8090

8191
}

0 commit comments

Comments
 (0)