Add since tags and code style refinements

See gh-27735
This commit is contained in:
Juergen Hoeller
2023-07-14 11:48:37 +02:00
parent 4b80b0f490
commit 0ab94478fe
2 changed files with 12 additions and 7 deletions

View File

@@ -68,6 +68,7 @@ public abstract class DataAccessUtils {
* @return the single result object, or {@code null} if none
* @throws IncorrectResultSizeDataAccessException if more than one
* element has been found in the given Stream
* @since 6.1
*/
@Nullable
public static <T> T singleResult(@Nullable Stream<T> results) throws IncorrectResultSizeDataAccessException {
@@ -91,13 +92,14 @@ public abstract class DataAccessUtils {
* @return the single result object, or {@code null} if none
* @throws IncorrectResultSizeDataAccessException if more than one
* element has been found in the given Iterator
* @since 6.1
*/
@Nullable
public static <T> T singleResult(@Nullable Iterator<T> results) throws IncorrectResultSizeDataAccessException {
if (results == null) {
return null;
}
T result = results.hasNext() ? results.next() : null;
T result = (results.hasNext() ? results.next() : null);
if (results.hasNext()) {
throw new IncorrectResultSizeDataAccessException(1);
}
@@ -112,6 +114,7 @@ public abstract class DataAccessUtils {
* @return the single optional result object, or {@code Optional.empty()} if none
* @throws IncorrectResultSizeDataAccessException if more than one
* element has been found in the given Collection
* @since 6.1
*/
public static <T> Optional<T> optionalResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
return Optional.ofNullable(singleResult(results));
@@ -125,6 +128,7 @@ public abstract class DataAccessUtils {
* @return the single optional result object, or {@code Optional.empty()} if none
* @throws IncorrectResultSizeDataAccessException if more than one
* element has been found in the given Stream
* @since 6.1
*/
public static <T> Optional<T> optionalResult(@Nullable Stream<T> results) throws IncorrectResultSizeDataAccessException {
return Optional.ofNullable(singleResult(results));
@@ -138,6 +142,7 @@ public abstract class DataAccessUtils {
* @return the single optional result object, or {@code Optional.empty()} if none
* @throws IncorrectResultSizeDataAccessException if more than one
* element has been found in the given Iterator
* @since 6.1
*/
public static <T> Optional<T> optionalResult(@Nullable Iterator<T> results) throws IncorrectResultSizeDataAccessException {
return Optional.ofNullable(singleResult(results));