Skip to content

Commit 8d4a8cb

Browse files
committed
Merge branch '6.2.x'
2 parents 409bf5f + f5c3f35 commit 8d4a8cb

File tree

6 files changed

+89
-87
lines changed

6 files changed

+89
-87
lines changed

spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java

+26-25
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
/**
3131
* 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}.
3334
*
3435
* @author Simon Baslé
3536
* @since 6.2
@@ -40,20 +41,20 @@
4041
public @interface DurationFormat {
4142

4243
/**
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}.
4445
* <p>Defaults to the JDK style ({@link Style#ISO8601}).
4546
*/
4647
Style style() default Style.ISO8601;
4748

4849
/**
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
5051
* for either parsing or printing, and none is explicitly provided in the input.
5152
* <p>Defaults to {@link Unit#MILLIS} if unspecified.
5253
*/
5354
Unit defaultUnit() default Unit.MILLIS;
5455

5556
/**
56-
* Duration format styles.
57+
* {@link Duration} format styles.
5758
*/
5859
enum Style {
5960

@@ -62,7 +63,7 @@ enum Style {
6263
* <p>Supported unit suffixes include: {@code ns, us, ms, s, m, h, d}.
6364
* Those correspond to nanoseconds, microseconds, milliseconds, seconds,
6465
* 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
6667
* lossy if the selected unit is bigger than the resolution of the
6768
* duration. For example, {@code Duration.ofMillis(5).plusNanos(1234)}
6869
* would get truncated to {@code "5ms"} when printing using
@@ -73,7 +74,7 @@ enum Style {
7374

7475
/**
7576
* 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)}
7778
* and {@link Duration#toString()}.
7879
*/
7980
ISO8601,
@@ -90,11 +91,11 @@ enum Style {
9091
}
9192

9293
/**
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
9495
* allows conversion to and from a supported {@code ChronoUnit} as well as
9596
* conversion from durations to longs.
9697
*
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}
9899
* {@code Duration} format style.
99100
*/
100101
enum Unit {
@@ -147,49 +148,49 @@ enum Unit {
147148
}
148149

149150
/**
150-
* Convert this {@code DurationFormat.Unit} to its {@link ChronoUnit}
151-
* equivalent.
151+
* Convert this {@code Unit} to its {@link ChronoUnit} equivalent.
152152
*/
153153
public ChronoUnit asChronoUnit() {
154154
return this.chronoUnit;
155155
}
156156

157157
/**
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.
160160
*/
161161
public String asSuffix() {
162162
return this.suffix;
163163
}
164164

165165
/**
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
169169
* @return the corresponding {@code Duration}
170170
*/
171171
public Duration parse(String value) {
172172
return Duration.of(Long.parseLong(value), asChronoUnit());
173173
}
174174

175175
/**
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
177177
* value using this unit's precision via {@link #longValue(Duration)}
178178
* 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
181181
* {@link Style#SIMPLE SIMPLE} style
182182
*/
183183
public String print(Duration value) {
184184
return longValue(value) + asSuffix();
185185
}
186186

187187
/**
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}.
193194
* @param value the {@code Duration} to convert to a long
194195
* @return the long value for the {@code Duration} in this {@code Unit}
195196
*/
@@ -198,7 +199,7 @@ public long longValue(Duration value) {
198199
}
199200

200201
/**
201-
* Get the {@code Unit} corresponding to the given {@code ChronoUnit}.
202+
* Get the {@link Unit} corresponding to the given {@link ChronoUnit}.
202203
* @throws IllegalArgumentException if the given {@code ChronoUnit} is
203204
* not supported
204205
*/
@@ -215,7 +216,7 @@ public static Unit fromChronoUnit(@Nullable ChronoUnit chronoUnit) {
215216
}
216217

217218
/**
218-
* Get the {@code Unit} corresponding to the given {@code String} suffix.
219+
* Get the {@link Unit} corresponding to the given {@link String} suffix.
219220
* @throws IllegalArgumentException if the given suffix is not supported
220221
*/
221222
public static Unit fromSuffix(String suffix) {

spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
class DurationFormatterUtilsTests {
4343

4444
@ParameterizedTest
45-
@EnumSource(DurationFormat.Style.class)
45+
@EnumSource
4646
void parseEmptyStringFailsWithDedicatedException(DurationFormat.Style style) {
4747
assertThatIllegalArgumentException()
4848
.isThrownBy(() -> DurationFormatterUtils.parse("", style))
4949
.withMessage("Value must not be empty");
5050
}
5151

5252
@ParameterizedTest
53-
@EnumSource(DurationFormat.Style.class)
53+
@EnumSource
5454
void parseNullStringFailsWithDedicatedException(DurationFormat.Style style) {
5555
assertThatIllegalArgumentException()
5656
.isThrownBy(() -> DurationFormatterUtils.parse(null, style))
@@ -113,29 +113,30 @@ void parseSimpleThrows() {
113113

114114
@Test
115115
void parseIsoNoChronoUnit() {
116-
//these are based on the examples given in Duration.parse
117-
// "PT20.345S" -- parses as "20.345 seconds"
116+
// These are based on the examples given in Duration.parse.
117+
118+
// "PT20.345S" -- parses as "20.345 seconds"
118119
assertThat(DurationFormatterUtils.parse("PT20.345S", ISO8601))
119120
.hasMillis(20345);
120-
// "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds)
121+
// "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds)
121122
assertThat(DurationFormatterUtils.parse("PT15M", ISO8601))
122123
.hasSeconds(15*60);
123-
// "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds)
124+
// "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds)
124125
assertThat(DurationFormatterUtils.parse("PT10H", ISO8601))
125126
.hasHours(10);
126-
// "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
127+
// "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
127128
assertThat(DurationFormatterUtils.parse("P2D", ISO8601))
128129
.hasDays(2);
129-
// "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes"
130+
// "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes"
130131
assertThat(DurationFormatterUtils.parse("P2DT3H4M", ISO8601))
131132
.isEqualTo(Duration.ofDays(2).plusHours(3).plusMinutes(4));
132-
// "PT-6H3M" -- parses as "-6 hours and +3 minutes"
133+
// "PT-6H3M" -- parses as "-6 hours and +3 minutes"
133134
assertThat(DurationFormatterUtils.parse("PT-6H3M", ISO8601))
134135
.isEqualTo(Duration.ofHours(-6).plusMinutes(3));
135-
// "-PT6H3M" -- parses as "-6 hours and -3 minutes"
136+
// "-PT6H3M" -- parses as "-6 hours and -3 minutes"
136137
assertThat(DurationFormatterUtils.parse("-PT6H3M", ISO8601))
137138
.isEqualTo(Duration.ofHours(-6).plusMinutes(-3));
138-
// "-PT-6H+3M" -- parses as "+6 hours and -3 minutes"
139+
// "-PT-6H+3M" -- parses as "+6 hours and -3 minutes"
139140
assertThat(DurationFormatterUtils.parse("-PT-6H+3M", ISO8601))
140141
.isEqualTo(Duration.ofHours(6).plusMinutes(-3));
141142
}
@@ -189,7 +190,7 @@ void parseCompositePartialWithSpaces() {
189190
.isEqualTo(Duration.ofMinutes(34).plusSeconds(57));
190191
}
191192

192-
@Test //Kotlin style compatibility
193+
@Test // Kotlin style compatibility
193194
void parseCompositeNegativeWithSpacesAndParenthesis() {
194195
assertThat(DurationFormatterUtils.parse("-(34m 57s)", COMPOSITE))
195196
.isEqualTo(Duration.ofMinutes(-34).plusSeconds(-57));
@@ -315,7 +316,7 @@ void detect() {
315316

316317
assertThat(DurationFormatterUtils.detect("-(1d 2h 34m 2ns)"))
317318
.as("COMPOSITE")
318-
.isEqualTo(COMPOSITE);
319+
.isEqualTo(COMPOSITE);
319320

320321
assertThatIllegalArgumentException().isThrownBy(() -> DurationFormatterUtils.detect("WPT2H-4M"))
321322
.withMessage("'WPT2H-4M' is not a valid duration, cannot detect any known style")

spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void incrementsSequenceUsingH2EmbeddedDatabaseConfigurer() {
6767
* Tests that the incrementer works when using all supported H2 <em>compatibility modes</em>.
6868
*/
6969
@ParameterizedTest
70-
@EnumSource(ModeEnum.class)
70+
@EnumSource
7171
void incrementsSequenceWithExplicitH2CompatibilityMode(ModeEnum mode) {
7272
String connectionUrl = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false;MODE=%s", UUID.randomUUID(), mode);
7373
DataSource dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", "");

spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)