From f261220372d01e931f45e85a0bc1acd324a210b4 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 24 Sep 2020 14:48:46 +0200 Subject: [PATCH] DATACMNS-1762 - Polishing. Update JavaDoc, remove unused imports and reduce method visibility. Original Pull Request: #459 --- .../model/PreferredConstructorDiscoverer.java | 1 - .../ProjectingMethodInterceptor.java | 2 +- ...erredRepositoryInitializationListener.java | 1 - .../RepositoryConfigurationDelegate.java | 2 -- .../core/support/MethodLookups.java | 6 ++---- .../support/QueryExecutionResultHandler.java | 7 ++++--- .../util/QueryExecutionConverters.java | 19 +++++++------------ .../data/util/NullableWrapper.java | 4 ++-- .../data/util/NullableWrapperConverters.java | 15 +++++++-------- ...gedResourcesAssemblerArgumentResolver.java | 2 -- 10 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java b/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java index b788f9cd4..edb8b030e 100644 --- a/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java +++ b/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java @@ -35,7 +35,6 @@ import org.springframework.data.mapping.PreferredConstructor; import org.springframework.data.mapping.PreferredConstructor.Parameter; import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.KotlinReflectionUtils; -import org.springframework.data.util.ReflectionUtils; import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; import org.springframework.util.Assert; diff --git a/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java b/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java index 063b3d64e..97215859b 100644 --- a/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java +++ b/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java @@ -182,7 +182,7 @@ class ProjectingMethodInterceptor implements MethodInterceptor { * a single-element collection. * * @param source must not be {@literal null}. - * @return + * @return never {@literal null}. */ private static Collection asCollection(Object source) { diff --git a/src/main/java/org/springframework/data/repository/config/DeferredRepositoryInitializationListener.java b/src/main/java/org/springframework/data/repository/config/DeferredRepositoryInitializationListener.java index a266f584b..bb835b42a 100644 --- a/src/main/java/org/springframework/data/repository/config/DeferredRepositoryInitializationListener.java +++ b/src/main/java/org/springframework/data/repository/config/DeferredRepositoryInitializationListener.java @@ -23,7 +23,6 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.core.Ordered; import org.springframework.data.repository.Repository; -import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport; /** * {@link ApplicationListener} to trigger the initialization of Spring Data repositories right before the application diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java index b77d4b0d3..b67f6e070 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java @@ -25,7 +25,6 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.slf4j.Logger; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.parsing.BeanComponentDefinition; @@ -41,7 +40,6 @@ import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.core.log.LogMessage; -import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport; import org.springframework.data.repository.core.support.RepositoryFactorySupport; import org.springframework.lang.Nullable; import org.springframework.util.Assert; diff --git a/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java b/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java index 4fccfa885..9b32f82de 100644 --- a/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java +++ b/src/main/java/org/springframework/data/repository/core/support/MethodLookups.java @@ -15,8 +15,6 @@ */ package org.springframework.data.repository.core.support; -import static org.springframework.core.GenericTypeResolver.*; - import java.lang.reflect.GenericDeclaration; import java.lang.reflect.Method; import java.lang.reflect.Type; @@ -322,8 +320,8 @@ interface MethodLookups { * Returns a candidate method from the base class for the given one or the method given in the first place if none * one the base class matches. * - * @param method must not be {@literal null}. - * @param baseClass must not be {@literal null}. + * @param invokedMethod must not be {@literal null}. + * @param candidate must not be {@literal null}. * @param predicate must not be {@literal null}. * @return */ diff --git a/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java b/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java index 9ad58352b..1424c7a2d 100644 --- a/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java +++ b/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java @@ -54,7 +54,7 @@ class QueryExecutionResultHandler { /** * Creates a new {@link QueryExecutionResultHandler}. */ - public QueryExecutionResultHandler(GenericConversionService conversionService) { + QueryExecutionResultHandler(GenericConversionService conversionService) { this.conversionService = conversionService; } @@ -66,7 +66,7 @@ class QueryExecutionResultHandler { * @return */ @Nullable - public Object postProcessInvocationResult(@Nullable Object result, Method method) { + Object postProcessInvocationResult(@Nullable Object result, Method method) { if (!processingRequired(result, method.getReturnType())) { return result; @@ -172,6 +172,7 @@ class QueryExecutionResultHandler { : null; } + private boolean requiresConversion(Collection collection, Class expectedReturnType, @Nullable TypeDescriptor elementDescriptor) { @@ -276,7 +277,7 @@ class QueryExecutionResultHandler { * @see TypeDescriptor#nested(MethodParameter, int) */ @Nullable - public TypeDescriptor getReturnTypeDescriptor(int nestingLevel) { + TypeDescriptor getReturnTypeDescriptor(int nestingLevel) { // optimizing for nesting level 0 and 1 (Optional, List) // nesting level 2 (Optional>) uses the slow path. diff --git a/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java b/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java index 74cf4abeb..d646716b6 100644 --- a/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java +++ b/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java @@ -257,7 +257,7 @@ public abstract class QueryExecutionConverters { * Returns the {@link ExecutionAdapter} to be used for the given return type. * * @param returnType must not be {@literal null}. - * @return + * @return can be {@literal null}. */ @Nullable public static ExecutionAdapter getExecutionAdapter(Class returnType) { @@ -289,10 +289,9 @@ public abstract class QueryExecutionConverters { /** * Creates a new {@link AbstractWrapperTypeConverter} using the given {@link ConversionService} and wrapper type. * - * @param conversionService must not be {@literal null}. * @param nullValue must not be {@literal null}. */ - protected AbstractWrapperTypeConverter(Object nullValue) { + AbstractWrapperTypeConverter(Object nullValue) { Assert.notNull(nullValue, "Null value must not be null!"); @@ -300,7 +299,7 @@ public abstract class QueryExecutionConverters { this.wrapperTypes = Collections.singleton(nullValue.getClass()); } - public AbstractWrapperTypeConverter(Object nullValue, + AbstractWrapperTypeConverter(Object nullValue, Iterable> wrapperTypes) { this.nullValue = nullValue; this.wrapperTypes = wrapperTypes; @@ -356,10 +355,8 @@ public abstract class QueryExecutionConverters { /** * Creates a new {@link NullableWrapperToFutureConverter} using the given {@link ConversionService}. - * - * @param conversionService must not be {@literal null}. */ - public NullableWrapperToFutureConverter() { + NullableWrapperToFutureConverter() { super(new AsyncResult<>(null), Arrays.asList(Future.class, ListenableFuture.class)); } @@ -382,10 +379,8 @@ public abstract class QueryExecutionConverters { /** * Creates a new {@link NullableWrapperToCompletableFutureConverter} using the given {@link ConversionService}. - * - * @param conversionService must not be {@literal null}. */ - public NullableWrapperToCompletableFutureConverter() { + NullableWrapperToCompletableFutureConverter() { super(CompletableFuture.completedFuture(null)); } @@ -398,7 +393,7 @@ public abstract class QueryExecutionConverters { return source instanceof CompletableFuture ? source : CompletableFuture.completedFuture(source); } - public static WrapperType getWrapperType() { + static WrapperType getWrapperType() { return WrapperType.singleValue(CompletableFuture.class); } } @@ -438,7 +433,7 @@ public abstract class QueryExecutionConverters { private final Map targetTypeCache = new ConcurrentHashMap<>(); private final ConversionService conversionService = DefaultConversionService.getSharedInstance(); - public IterableToStreamableConverter() {} + IterableToStreamableConverter() {} /* * (non-Javadoc) diff --git a/src/main/java/org/springframework/data/util/NullableWrapper.java b/src/main/java/org/springframework/data/util/NullableWrapper.java index 3dbadd0bf..bea6f75a1 100644 --- a/src/main/java/org/springframework/data/util/NullableWrapper.java +++ b/src/main/java/org/springframework/data/util/NullableWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2020 the original author or authors. + * Copyright 2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ public class NullableWrapper { } /** - * Returns the type of the contained value. WIll fall back to {@link Object} in case the value is {@literal null}. + * Returns the type of the contained value. Will fall back to {@link Object} in case the value is {@literal null}. * * @return will never be {@literal null}. */ diff --git a/src/main/java/org/springframework/data/util/NullableWrapperConverters.java b/src/main/java/org/springframework/data/util/NullableWrapperConverters.java index 2312d9a1c..2619f1a53 100644 --- a/src/main/java/org/springframework/data/util/NullableWrapperConverters.java +++ b/src/main/java/org/springframework/data/util/NullableWrapperConverters.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2020 the original author or authors. + * Copyright 2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -228,7 +228,6 @@ public abstract class NullableWrapperConverters { /** * Creates a new {@link AbstractWrapperTypeConverter} using the given wrapper type. * - * @param conversionService must not be {@literal null}. * @param nullValue must not be {@literal null}. */ protected AbstractWrapperTypeConverter(Object nullValue) { @@ -501,11 +500,11 @@ public abstract class NullableWrapperConverters { this.cardinality = cardinality; } - public Class getType() { + Class getType() { return this.type; } - public Cardinality getCardinality() { + Cardinality getCardinality() { return cardinality; } @@ -560,19 +559,19 @@ public abstract class NullableWrapperConverters { private final Class type; private final Cardinality cardinality; - public static WrapperType singleValue(Class type) { + static WrapperType singleValue(Class type) { return new WrapperType(type, Cardinality.SINGLE); } - public static WrapperType multiValue(Class type) { + static WrapperType multiValue(Class type) { return new WrapperType(type, Cardinality.MULTI); } - public static WrapperType noValue(Class type) { + static WrapperType noValue(Class type) { return new WrapperType(type, Cardinality.NONE); } - public boolean isSingleValue() { + boolean isSingleValue() { return cardinality.equals(Cardinality.SINGLE); } } diff --git a/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java b/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java index d9b547931..adc7c591a 100644 --- a/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java +++ b/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java @@ -22,8 +22,6 @@ import javax.annotation.Nonnull; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.MethodParameter; import org.springframework.core.log.LogMessage;