29
29
30
30
/**
31
31
* Declares that a field or method parameter should be formatted as a
32
- * {@link java.time.Duration}, according to the specified {@code style}.
32
+ * {@link java.time.Duration}, according to the specified {@link #style style}.
33
33
*
34
34
* @author Simon Baslé
35
35
* @since 6.2
40
40
public @interface DurationFormat {
41
41
42
42
/**
43
- * Which {@code Style} to use for parsing and printing a {@code Duration}.
44
- * Defaults to the JDK style ({@link Style#ISO8601}).
43
+ * The {@code Style} to use for parsing and printing a {@code Duration}.
44
+ * <p> Defaults to the JDK style ({@link Style#ISO8601}).
45
45
*/
46
46
Style style () default Style .ISO8601 ;
47
47
48
48
/**
49
- * Define which {@link Unit} to fall back to in case the {@code style()}
50
- * needs a unit for either parsing or printing, and none is explicitly
51
- * provided in the input ({@code Unit. MILLIS} if unspecified) .
49
+ * The {@link Unit} to fall back to in case the {@code style()} needs a unit
50
+ * for either parsing or printing, and none is explicitly provided in the input.
51
+ * <p>Defaults to {@link Unit# MILLIS} if unspecified.
52
52
*/
53
53
Unit defaultUnit () default Unit .MILLIS ;
54
54
@@ -59,14 +59,15 @@ enum Style {
59
59
60
60
/**
61
61
* Simple formatting based on a short suffix, for example '1s'.
62
- * Supported unit suffixes are : {@code ns, us, ms, s, m, h, d}.
63
- * This corresponds to nanoseconds, microseconds, milliseconds, seconds,
64
- * minutes, hours and days respectively.
62
+ * <p> Supported unit suffixes include : {@code ns, us, ms, s, m, h, d}.
63
+ * Those correspond to nanoseconds, microseconds, milliseconds, seconds,
64
+ * minutes, hours, and days, respectively.
65
65
* <p>Note that when printing a {@code Duration}, this style can be
66
66
* lossy if the selected unit is bigger than the resolution of the
67
- * duration. For example, * {@code Duration.ofMillis(5).plusNanos(1234)}
67
+ * duration. For example, {@code Duration.ofMillis(5).plusNanos(1234)}
68
68
* would get truncated to {@code "5ms"} when printing using
69
- * {@code ChronoUnit.MILLIS}. Fractional durations are not supported.
69
+ * {@code ChronoUnit.MILLIS}.
70
+ * <p>Fractional durations are not supported.
70
71
*/
71
72
SIMPLE ,
72
73
@@ -80,22 +81,24 @@ enum Style {
80
81
/**
81
82
* Like {@link #SIMPLE}, but allows multiple segments ordered from
82
83
* largest-to-smallest units of time, like {@code 1h12m27s}.
83
- * <p>
84
- * A single minus sign ({@code -}) is allowed to indicate the whole
84
+ * <p>A single minus sign ({@code -}) is allowed to indicate the whole
85
85
* duration is negative. Spaces are allowed between segments, and a
86
86
* negative duration with spaced segments can optionally be surrounded
87
- * by parenthesis after the minus sign, like so: {@code -(34m 57s)}.
87
+ * by parentheses after the minus sign, like so: {@code -(34m 57s)}.
88
88
*/
89
89
COMPOSITE
90
90
}
91
91
92
92
/**
93
93
* Duration format unit, which mirrors a subset of {@link ChronoUnit} and
94
- * allows conversion to and from supported {@code ChronoUnit} as well as
95
- * converting durations to longs. The enum includes its corresponding suffix
96
- * in the {@link Style#SIMPLE simple} Duration format style.
94
+ * allows conversion to and from a supported {@code ChronoUnit} as well as
95
+ * conversion from durations to longs.
96
+ *
97
+ * <p>The enum includes its corresponding suffix in the {@link Style#SIMPLE simple}
98
+ * {@code Duration} format style.
97
99
*/
98
100
enum Unit {
101
+
99
102
/**
100
103
* Nanoseconds ({@code "ns"}).
101
104
*/
@@ -153,7 +156,7 @@ public ChronoUnit asChronoUnit() {
153
156
154
157
/**
155
158
* Convert this {@code DurationFormat.Unit} to a simple {@code String}
156
- * suffix, suitable for the {@link Style#SIMPLE} style.
159
+ * suffix, suitable for the {@link Style#SIMPLE SIMPLE } style.
157
160
*/
158
161
public String asSuffix () {
159
162
return this .suffix ;
@@ -173,9 +176,9 @@ public Duration parse(String value) {
173
176
* Print a {@code Duration} as a {@code String}, converting it to a long
174
177
* value using this unit's precision via {@link #longValue(Duration)}
175
178
* and appending this unit's simple {@link #asSuffix() suffix}.
176
- * @param value the {@code Duration} to convert to String
179
+ * @param value the {@code Duration} to convert to a String
177
180
* @return the String representation of the {@code Duration} in the
178
- * {@link Style#SIMPLE SIMPLE style}
181
+ * {@link Style#SIMPLE SIMPLE} style
179
182
*/
180
183
public String print (Duration value ) {
181
184
return longValue (value ) + asSuffix ();
@@ -187,17 +190,17 @@ public String print(Duration value) {
187
190
* bigger than the actual resolution of the duration.
188
191
* <p>For example, {@code Duration.ofMillis(5).plusNanos(1234)} would
189
192
* get truncated to {@code 5} for unit {@code MILLIS}.
190
- * @param value the {@code Duration} to convert to long
191
- * @return the long value for the Duration in this Unit
193
+ * @param value the {@code Duration} to convert to a long
194
+ * @return the long value for the {@code Duration} in this {@code Unit}
192
195
*/
193
196
public long longValue (Duration value ) {
194
197
return this .longValue .apply (value );
195
198
}
196
199
197
200
/**
198
201
* Get the {@code Unit} corresponding to the given {@code ChronoUnit}.
199
- * @throws IllegalArgumentException if that particular ChronoUnit isn't
200
- * supported
202
+ * @throws IllegalArgumentException if the given {@code ChronoUnit} is
203
+ * not supported
201
204
*/
202
205
public static Unit fromChronoUnit (@ Nullable ChronoUnit chronoUnit ) {
203
206
if (chronoUnit == null ) {
@@ -208,12 +211,12 @@ public static Unit fromChronoUnit(@Nullable ChronoUnit chronoUnit) {
208
211
return candidate ;
209
212
}
210
213
}
211
- throw new IllegalArgumentException ("No matching Unit for ChronoUnit. " + chronoUnit .name ());
214
+ throw new IllegalArgumentException ("No matching Unit for ChronoUnit: " + chronoUnit .name ());
212
215
}
213
216
214
217
/**
215
218
* Get the {@code Unit} corresponding to the given {@code String} suffix.
216
- * @throws IllegalArgumentException if that particular suffix is unknown
219
+ * @throws IllegalArgumentException if the given suffix is not supported
217
220
*/
218
221
public static Unit fromSuffix (String suffix ) {
219
222
for (Unit candidate : values ()) {
0 commit comments