Skip to content

Commit 0ab9447

Browse files
committed
Add since tags and code style refinements
See gh-27735
1 parent 4b80b0f commit 0ab9447

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

spring-tx/src/main/java/org/springframework/dao/support/DataAccessUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public static <T> T singleResult(@Nullable Collection<T> results) throws Incorre
6868
* @return the single result object, or {@code null} if none
6969
* @throws IncorrectResultSizeDataAccessException if more than one
7070
* element has been found in the given Stream
71+
* @since 6.1
7172
*/
7273
@Nullable
7374
public static <T> T singleResult(@Nullable Stream<T> results) throws IncorrectResultSizeDataAccessException {
@@ -91,13 +92,14 @@ public static <T> T singleResult(@Nullable Stream<T> results) throws IncorrectRe
9192
* @return the single result object, or {@code null} if none
9293
* @throws IncorrectResultSizeDataAccessException if more than one
9394
* element has been found in the given Iterator
95+
* @since 6.1
9496
*/
9597
@Nullable
9698
public static <T> T singleResult(@Nullable Iterator<T> results) throws IncorrectResultSizeDataAccessException {
9799
if (results == null) {
98100
return null;
99101
}
100-
T result = results.hasNext() ? results.next() : null;
102+
T result = (results.hasNext() ? results.next() : null);
101103
if (results.hasNext()) {
102104
throw new IncorrectResultSizeDataAccessException(1);
103105
}
@@ -112,6 +114,7 @@ public static <T> T singleResult(@Nullable Iterator<T> results) throws Incorrect
112114
* @return the single optional result object, or {@code Optional.empty()} if none
113115
* @throws IncorrectResultSizeDataAccessException if more than one
114116
* element has been found in the given Collection
117+
* @since 6.1
115118
*/
116119
public static <T> Optional<T> optionalResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
117120
return Optional.ofNullable(singleResult(results));
@@ -125,6 +128,7 @@ public static <T> Optional<T> optionalResult(@Nullable Collection<T> results) th
125128
* @return the single optional result object, or {@code Optional.empty()} if none
126129
* @throws IncorrectResultSizeDataAccessException if more than one
127130
* element has been found in the given Stream
131+
* @since 6.1
128132
*/
129133
public static <T> Optional<T> optionalResult(@Nullable Stream<T> results) throws IncorrectResultSizeDataAccessException {
130134
return Optional.ofNullable(singleResult(results));
@@ -138,6 +142,7 @@ public static <T> Optional<T> optionalResult(@Nullable Stream<T> results) throws
138142
* @return the single optional result object, or {@code Optional.empty()} if none
139143
* @throws IncorrectResultSizeDataAccessException if more than one
140144
* element has been found in the given Iterator
145+
* @since 6.1
141146
*/
142147
public static <T> Optional<T> optionalResult(@Nullable Iterator<T> results) throws IncorrectResultSizeDataAccessException {
143148
return Optional.ofNullable(singleResult(results));

spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -247,21 +247,21 @@ public void exceptionTranslationWithTranslation() {
247247
assertThat(DataAccessUtils.translateIfNecessary(in, mpet)).isSameAs(out);
248248
}
249249

250+
250251
private <E extends IncorrectResultSizeDataAccessException> Consumer<E> sizeRequirements(
251252
int expectedSize, int actualSize) {
253+
252254
return ex -> {
253255
assertThat(ex.getExpectedSize()).as("expected size").isEqualTo(expectedSize);
254256
assertThat(ex.getActualSize()).as("actual size").isEqualTo(actualSize);
255257
};
256258
}
257259

258-
private <E extends IncorrectResultSizeDataAccessException> Consumer<E> sizeRequirements(
259-
int expectedSize) {
260-
return ex -> {
261-
assertThat(ex.getExpectedSize()).as("expected size").isEqualTo(expectedSize);
262-
};
260+
private <E extends IncorrectResultSizeDataAccessException> Consumer<E> sizeRequirements(int expectedSize) {
261+
return ex -> assertThat(ex.getExpectedSize()).as("expected size").isEqualTo(expectedSize);
263262
}
264263

264+
265265
public static class MapPersistenceExceptionTranslator implements PersistenceExceptionTranslator {
266266

267267
// in to out

0 commit comments

Comments
 (0)