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 {@link #style style}.
32
+ * {@link java.time.Duration}, according to the specified {@link #style Style}
33
+ * and {@link #defaultUnit Unit}.
33
34
*
34
35
* @author Simon Baslé
35
36
* @since 6.2
40
41
public @interface DurationFormat {
41
42
42
43
/**
43
- * The {@code Style} to use for parsing and printing a {@code Duration}.
44
+ * The {@link Style} to use for parsing and printing a {@link Duration}.
44
45
* <p>Defaults to the JDK style ({@link Style#ISO8601}).
45
46
*/
46
47
Style style () default Style .ISO8601 ;
47
48
48
49
/**
49
- * The {@link Unit} to fall back to in case the {@code style() } needs a unit
50
+ * The {@link Unit} to fall back to in case the {@link # style Style } needs a unit
50
51
* for either parsing or printing, and none is explicitly provided in the input.
51
52
* <p>Defaults to {@link Unit#MILLIS} if unspecified.
52
53
*/
53
54
Unit defaultUnit () default Unit .MILLIS ;
54
55
55
56
/**
56
- * Duration format styles.
57
+ * {@link Duration} format styles.
57
58
*/
58
59
enum Style {
59
60
@@ -62,7 +63,7 @@ enum Style {
62
63
* <p>Supported unit suffixes include: {@code ns, us, ms, s, m, h, d}.
63
64
* Those correspond to nanoseconds, microseconds, milliseconds, seconds,
64
65
* minutes, hours, and days, respectively.
65
- * <p>Note that when printing a {@code Duration}, this style can be
66
+ * <p>Note that when printing a {@link Duration}, this style can be
66
67
* lossy if the selected unit is bigger than the resolution of the
67
68
* duration. For example, {@code Duration.ofMillis(5).plusNanos(1234)}
68
69
* would get truncated to {@code "5ms"} when printing using
@@ -73,7 +74,7 @@ enum Style {
73
74
74
75
/**
75
76
* ISO-8601 formatting.
76
- * <p>This is what the JDK uses in {@link java.time. Duration#parse(CharSequence)}
77
+ * <p>This is what the JDK uses in {@link Duration#parse(CharSequence)}
77
78
* and {@link Duration#toString()}.
78
79
*/
79
80
ISO8601 ,
@@ -90,11 +91,11 @@ enum Style {
90
91
}
91
92
92
93
/**
93
- * Duration format unit, which mirrors a subset of {@link ChronoUnit} and
94
+ * {@link Duration} format unit, which mirrors a subset of {@link ChronoUnit} and
94
95
* allows conversion to and from a supported {@code ChronoUnit} as well as
95
96
* conversion from durations to longs.
96
97
*
97
- * <p>The enum includes its corresponding suffix in the {@link Style#SIMPLE simple }
98
+ * <p>The enum includes its corresponding suffix in the {@link Style#SIMPLE SIMPLE }
98
99
* {@code Duration} format style.
99
100
*/
100
101
enum Unit {
@@ -147,49 +148,49 @@ enum Unit {
147
148
}
148
149
149
150
/**
150
- * Convert this {@code DurationFormat.Unit} to its {@link ChronoUnit}
151
- * equivalent.
151
+ * Convert this {@code Unit} to its {@link ChronoUnit} equivalent.
152
152
*/
153
153
public ChronoUnit asChronoUnit () {
154
154
return this .chronoUnit ;
155
155
}
156
156
157
157
/**
158
- * Convert this {@code DurationFormat. Unit} to a simple {@code String}
159
- * suffix, suitable for the {@link Style#SIMPLE SIMPLE} style.
158
+ * Convert this {@code Unit} to a simple {@code String} suffix, suitable
159
+ * for the {@link Style#SIMPLE SIMPLE} style.
160
160
*/
161
161
public String asSuffix () {
162
162
return this .suffix ;
163
163
}
164
164
165
165
/**
166
- * Parse a {@code long} from a {@code String} and interpret it to be a
167
- * {@code Duration} in the current unit.
168
- * @param value the String representation of the long
166
+ * Parse a {@code long} from the given {@link String} and interpret it to be a
167
+ * {@link Duration} in the current unit.
168
+ * @param value the {@code String} representation of the long
169
169
* @return the corresponding {@code Duration}
170
170
*/
171
171
public Duration parse (String value ) {
172
172
return Duration .of (Long .parseLong (value ), asChronoUnit ());
173
173
}
174
174
175
175
/**
176
- * Print a {@code Duration} as a {@code String}, converting it to a long
176
+ * Print the given {@link Duration} as a {@link String}, converting it to a long
177
177
* value using this unit's precision via {@link #longValue(Duration)}
178
178
* and appending this unit's simple {@link #asSuffix() suffix}.
179
- * @param value the {@code Duration} to convert to a String
180
- * @return the String representation of the {@code Duration} in the
179
+ * @param value the {@code Duration} to convert to a {@code String}
180
+ * @return the {@code String} representation of the {@code Duration} in the
181
181
* {@link Style#SIMPLE SIMPLE} style
182
182
*/
183
183
public String print (Duration value ) {
184
184
return longValue (value ) + asSuffix ();
185
185
}
186
186
187
187
/**
188
- * Convert the given {@code Duration} to a long value in the resolution
189
- * of this unit. Note that this can be lossy if the current unit is
190
- * bigger than the actual resolution of the duration.
191
- * <p>For example, {@code Duration.ofMillis(5).plusNanos(1234)} would
192
- * get truncated to {@code 5} for unit {@code MILLIS}.
188
+ * Convert the given {@link Duration} to a long value in the resolution
189
+ * of this unit.
190
+ * <p>Note that this can be lossy if the current unit is bigger than the
191
+ * actual resolution of the duration. For example,
192
+ * {@code Duration.ofMillis(5).plusNanos(1234)} would get truncated to
193
+ * {@code 5} for unit {@code MILLIS}.
193
194
* @param value the {@code Duration} to convert to a long
194
195
* @return the long value for the {@code Duration} in this {@code Unit}
195
196
*/
@@ -198,7 +199,7 @@ public long longValue(Duration value) {
198
199
}
199
200
200
201
/**
201
- * Get the {@code Unit} corresponding to the given {@code ChronoUnit}.
202
+ * Get the {@link Unit} corresponding to the given {@link ChronoUnit}.
202
203
* @throws IllegalArgumentException if the given {@code ChronoUnit} is
203
204
* not supported
204
205
*/
@@ -215,7 +216,7 @@ public static Unit fromChronoUnit(@Nullable ChronoUnit chronoUnit) {
215
216
}
216
217
217
218
/**
218
- * Get the {@code Unit} corresponding to the given {@code String} suffix.
219
+ * Get the {@link Unit} corresponding to the given {@link String} suffix.
219
220
* @throws IllegalArgumentException if the given suffix is not supported
220
221
*/
221
222
public static Unit fromSuffix (String suffix ) {
0 commit comments