From 97be53bd858089818aae64dc843ba74603e6a2ed Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 13 Nov 2023 14:39:07 +0100 Subject: [PATCH] Remove superfluous `@NonNull` annotations. Closes #2976 --- .../data/convert/CustomConversions.java | 185 +++++++++--------- .../PropertyValueConversionService.java | 3 +- .../data/convert/PropertyValueConverter.java | 29 ++- .../PropertyValueConverterFactories.java | 2 + .../PropertyValueConverterRegistrar.java | 11 +- .../SimplePropertyValueConversions.java | 32 ++- .../data/convert/ValueConversionContext.java | 13 +- .../data/repository/util/ClassUtils.java | 3 +- 8 files changed, 131 insertions(+), 147 deletions(-) diff --git a/src/main/java/org/springframework/data/convert/CustomConversions.java b/src/main/java/org/springframework/data/convert/CustomConversions.java index ae439bda19..1f89361911 100644 --- a/src/main/java/org/springframework/data/convert/CustomConversions.java +++ b/src/main/java/org/springframework/data/convert/CustomConversions.java @@ -16,7 +16,16 @@ package org.springframework.data.convert; import java.lang.annotation.Annotation; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Predicate; @@ -38,7 +47,6 @@ import org.springframework.data.util.CustomCollections; import org.springframework.data.util.Predicates; import org.springframework.data.util.Streamable; -import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -99,24 +107,20 @@ public class CustomConversions { private final Function> getRawWriteTarget = convertiblePair -> getCustomTarget( convertiblePair.getSourceType(), null, writingPairs); - @Nullable - private final PropertyValueConversions propertyValueConversions; + @Nullable private final PropertyValueConversions propertyValueConversions; /** * @param converterConfiguration the {@link ConverterConfiguration} to apply. * @since 2.3 */ - public CustomConversions(@NonNull ConverterConfiguration converterConfiguration) { + public CustomConversions(ConverterConfiguration converterConfiguration) { this.converterConfiguration = converterConfiguration; List registeredConverters = collectPotentialConverterRegistrations( converterConfiguration.getStoreConversions(), converterConfiguration.getUserConverters()).stream() - .filter(this::isSupportedConverter) - .filter(this::shouldRegister) - .map(ConverterRegistrationIntent::getConverterRegistration) - .map(this::register) - .distinct() + .filter(this::isSupportedConverter).filter(this::shouldRegister) + .map(ConverterRegistrationIntent::getConverterRegistration).map(this::register).distinct() .collect(Collectors.toList()); Collections.reverse(registeredConverters); @@ -136,40 +140,47 @@ public CustomConversions(@NonNull ConverterConfiguration converterConfiguration) * @param storeConversions must not be {@literal null}. * @param converters must not be {@literal null}. */ - public CustomConversions(@NonNull StoreConversions storeConversions, @NonNull Collection converters) { + public CustomConversions(StoreConversions storeConversions, Collection converters) { this(new ConverterConfiguration(storeConversions, new ArrayList<>(converters))); } + private static boolean hasAssignableSourceType(ConvertiblePair pair, Class sourceType) { + return pair.getSourceType().isAssignableFrom(sourceType); + } + + private static boolean requestedTargetTypeIsAssignable(@Nullable Class requestedTargetType, Class targetType) { + + return requestedTargetType == null || targetType.isAssignableFrom(requestedTargetType); + } + /** * Returns the underlying {@link SimpleTypeHolder}. * * @return the underlying {@link SimpleTypeHolder}. * @see SimpleTypeHolder */ - public @NonNull SimpleTypeHolder getSimpleTypeHolder() { + public SimpleTypeHolder getSimpleTypeHolder() { return simpleTypeHolder; } /** * Determines whether the given, required {@link PersistentProperty property} has a value-specific converter - * registered. Returns {@literal false} if no {@link PropertyValueConversions} have been configured for the - * underlying store. + * registered. Returns {@literal false} if no {@link PropertyValueConversions} have been configured for the underlying + * store. *

- * This method protects against {@literal null} when not {@link PropertyValueConversions} have been configured for - * the underlying data store, and is a shortcut for: - * - * + * This method protects against {@literal null} when not {@link PropertyValueConversions} have been configured for the + * underlying data store, and is a shortcut for: * customConversions.getPropertyValueConversions().hasValueConverter(property); * * * @param property {@link PersistentProperty} to evaluate; must not be {@literal null}. - * @return a boolean value indicating whether {@link PropertyValueConverter} has been configured and registered - * for the {@link PersistentProperty property}. + * @return a boolean value indicating whether {@link PropertyValueConverter} has been configured and registered for + * the {@link PersistentProperty property}. * @see PropertyValueConversions#hasValueConverter(PersistentProperty) * @see #getPropertyValueConversions() * @see PersistentProperty */ - public boolean hasValueConverter(@NonNull PersistentProperty property) { + public boolean hasValueConverter(PersistentProperty property) { PropertyValueConversions propertyValueConversions = getPropertyValueConversions(); @@ -184,10 +195,11 @@ public boolean hasValueConverter(@NonNull PersistentProperty property) { * @param type {@link Class} to evaluate as a simple type, such as a primitive type. * @return a boolean value indicating whether the given, required {@link Class type} is simple. */ - // TODO: Technically, an 'isXyz(..)' method (returning a boolean to answer a user's question should not throw an Exception). - // Rather, a null Class type argument should simply return false to indicate it is clearly not a "simple type". - // How much data store specific code relies on the existing behavior? - public boolean isSimpleType(@NonNull Class type) { + // TODO: Technically, an 'isXyz(..)' method (returning a boolean to answer a user's question should not throw an + // Exception). + // Rather, a null Class type argument should simply return false to indicate it is clearly not a "simple type". + // How much data store specific code relies on the existing behavior? + public boolean isSimpleType(Class type) { Assert.notNull(type, "Type must not be null"); @@ -200,7 +212,7 @@ public boolean isSimpleType(@NonNull Class type) { * @param conversionService {@link ConverterRegistry} to populate; must not be {@literal null}. * @see ConverterRegistry */ - public void registerConvertersIn(@NonNull ConverterRegistry conversionService) { + public void registerConvertersIn(ConverterRegistry conversionService) { Assert.notNull(conversionService, "ConversionService must not be null"); @@ -209,11 +221,32 @@ public void registerConvertersIn(@NonNull ConverterRegistry conversionService) { } /** - * Gets a reference to the configured {@link PropertyValueConversions} if property value conversions - * are supported by the underlying data store. + * Registers the given converter in the given {@link GenericConversionService}. * - * @return a reference to the configured {@link PropertyValueConversions}; may be {@literal null} - * if the underlying data store does not support property value conversions. + * @param candidate must not be {@literal null}. + * @param conversionService must not be {@literal null}. + */ + private void registerConverterIn(Object candidate, ConverterRegistry conversionService) { + + if (candidate instanceof Converter converter) { + conversionService.addConverter(converter); + } else if (candidate instanceof ConverterFactory converterFactory) { + conversionService.addConverterFactory(converterFactory); + } else if (candidate instanceof GenericConverter genericConverter) { + conversionService.addConverter(genericConverter); + } else if (candidate instanceof ConverterAware converterAware) { + converterAware.getConverters().forEach(it -> registerConverterIn(it, conversionService)); + } else { + throw new IllegalArgumentException(String.format(NOT_A_CONVERTER, candidate)); + } + } + + /** + * Gets a reference to the configured {@link PropertyValueConversions} if property value conversions are supported by + * the underlying data store. + * + * @return a reference to the configured {@link PropertyValueConversions}; may be {@literal null} if the underlying + * data store does not support property value conversions. * @see PropertyValueConversions */ @Nullable @@ -230,53 +263,24 @@ public PropertyValueConversions getPropertyValueConversions() { * @see ConverterRegistration * @since 2.3 */ - private List collectPotentialConverterRegistrations( - @NonNull StoreConversions storeConversions, @NonNull Collection converters) { + private List collectPotentialConverterRegistrations(StoreConversions storeConversions, + Collection converters) { List converterRegistrations = new ArrayList<>(); - converters.stream() - .map(storeConversions::getRegistrationsFor) - .flatMap(Streamable::stream) - .map(ConverterRegistrationIntent::userConverters) - .forEach(converterRegistrations::add); + converters.stream().map(storeConversions::getRegistrationsFor).flatMap(Streamable::stream) + .map(ConverterRegistrationIntent::userConverters).forEach(converterRegistrations::add); - storeConversions.getStoreConverters().stream() - .map(storeConversions::getRegistrationsFor) - .flatMap(Streamable::stream) - .map(ConverterRegistrationIntent::storeConverters) + storeConversions.getStoreConverters().stream().map(storeConversions::getRegistrationsFor) + .flatMap(Streamable::stream).map(ConverterRegistrationIntent::storeConverters) .forEach(converterRegistrations::add); - DEFAULT_CONVERTERS.stream() - .map(storeConversions::getRegistrationsFor) - .flatMap(Streamable::stream) - .map(ConverterRegistrationIntent::defaultConverters) - .forEach(converterRegistrations::add); + DEFAULT_CONVERTERS.stream().map(storeConversions::getRegistrationsFor).flatMap(Streamable::stream) + .map(ConverterRegistrationIntent::defaultConverters).forEach(converterRegistrations::add); return converterRegistrations; } - /** - * Registers the given converter in the given {@link GenericConversionService}. - * - * @param candidate must not be {@literal null}. - * @param conversionService must not be {@literal null}. - */ - private void registerConverterIn(Object candidate, ConverterRegistry conversionService) { - - if (candidate instanceof Converter converter) { - conversionService.addConverter(converter); - } else if (candidate instanceof ConverterFactory converterFactory) { - conversionService.addConverterFactory(converterFactory); - } else if (candidate instanceof GenericConverter genericConverter) { - conversionService.addConverter(genericConverter); - } else if (candidate instanceof ConverterAware converterAware) { - converterAware.getConverters().forEach(it -> registerConverterIn(it, conversionService)); - } else { - throw new IllegalArgumentException(String.format(NOT_A_CONVERTER, candidate)); - } - } - /** * Registers the given {@link ConvertiblePair} as reading or writing pair depending on the type sides being basic * types. @@ -284,7 +288,7 @@ private void registerConverterIn(Object candidate, ConverterRegistry conversionS * @param converterRegistration {@link ConverterRegistration} to register; must not be {@literal null}. * @see ConverterRegistration */ - private Object register(@NonNull ConverterRegistration converterRegistration) { + private Object register(ConverterRegistration converterRegistration) { Assert.notNull(converterRegistration, "Converter registration must not be null"); @@ -321,7 +325,7 @@ private Object register(@NonNull ConverterRegistration converterRegistration) { * @return {@literal true} if supported. * @since 2.3 */ - private boolean isSupportedConverter(@NonNull ConverterRegistrationIntent registrationIntent) { + private boolean isSupportedConverter(ConverterRegistrationIntent registrationIntent) { boolean register = registrationIntent.isUserConverter() || registrationIntent.isStoreConverter() || (registrationIntent.isReading() && registrationIntent.isSimpleSourceType()) @@ -348,7 +352,7 @@ private boolean isSupportedConverter(@NonNull ConverterRegistrationIntent regist * @return {@literal false} if the given {@link ConverterRegistration} shall be skipped. * @since 2.3 */ - private boolean shouldRegister(@NonNull ConverterRegistrationIntent intent) { + private boolean shouldRegister(ConverterRegistrationIntent intent) { return !intent.isDefaultConverter() || converterConfiguration.shouldRegister(intent.getConverterRegistration().getConvertiblePair()); } @@ -359,9 +363,9 @@ private boolean shouldRegister(@NonNull ConverterRegistrationIntent intent) { * * @param sourceType must not be {@literal null} * @return the target type to convert to in case we have a custom conversion registered to convert the given source - * type into a store native one. + * type into a store native one. */ - public Optional> getCustomWriteTarget(@NonNull Class sourceType) { + public Optional> getCustomWriteTarget(Class sourceType) { Assert.notNull(sourceType, "Source type must not be null"); @@ -379,7 +383,7 @@ public Optional> getCustomWriteTarget(@NonNull Class sourceType) { * @param requestedTargetType must not be {@literal null}. * @return the target type we can read an inject of the given source type to. */ - public Optional> getCustomWriteTarget(@NonNull Class sourceType, @NonNull Class requestedTargetType) { + public Optional> getCustomWriteTarget(Class sourceType, Class requestedTargetType) { Assert.notNull(sourceType, "Source type must not be null"); Assert.notNull(requestedTargetType, "Target type must not be null"); @@ -396,7 +400,7 @@ public Optional> getCustomWriteTarget(@NonNull Class sourceType, @No * @param sourceType must not be {@literal null} * @return whether we have a custom conversion registered to read {@code sourceType} into a native type. */ - public boolean hasCustomWriteTarget(@NonNull Class sourceType) { + public boolean hasCustomWriteTarget(Class sourceType) { Assert.notNull(sourceType, "Source type must not be null"); @@ -409,10 +413,10 @@ public boolean hasCustomWriteTarget(@NonNull Class sourceType) { * * @param sourceType must not be {@literal null}. * @param targetType must not be {@literal null}. - * @return whether we have a custom conversion registered to read an object of the given source type into an object - * of the given native target type. + * @return whether we have a custom conversion registered to read an object of the given source type into an object of + * the given native target type. */ - public boolean hasCustomWriteTarget(@NonNull Class sourceType, @NonNull Class targetType) { + public boolean hasCustomWriteTarget(Class sourceType, Class targetType) { Assert.notNull(sourceType, "Source type must not be null"); Assert.notNull(targetType, "Target type must not be null"); @@ -427,7 +431,7 @@ public boolean hasCustomWriteTarget(@NonNull Class sourceType, @NonNull Class * @param targetType must not be {@literal null} * @return whether we have a custom conversion registered to read the given source into the given target type. */ - public boolean hasCustomReadTarget(@NonNull Class sourceType, @NonNull Class targetType) { + public boolean hasCustomReadTarget(Class sourceType, Class targetType) { Assert.notNull(sourceType, "Source type must not be null"); Assert.notNull(targetType, "Target type must not be null"); @@ -444,7 +448,7 @@ public boolean hasCustomReadTarget(@NonNull Class sourceType, @NonNull Class< * @return the actual target type for the given {@code sourceType} and {@code targetType}. */ @Nullable - private Class getCustomReadTarget(@NonNull Class sourceType, @NonNull Class targetType) { + private Class getCustomReadTarget(Class sourceType, Class targetType) { return customReadTargetTypes.computeIfAbsent(sourceType, targetType, getReadTarget); } @@ -458,7 +462,7 @@ private Class getCustomReadTarget(@NonNull Class sourceType, @NonNull Clas * @return the base {@link Class type} for the (requested) {@link Class target type} if present. */ @Nullable - private Class getCustomTarget(@NonNull Class sourceType, @Nullable Class targetType, + private Class getCustomTarget(Class sourceType, @Nullable Class targetType, Collection pairs) { if (targetType != null && pairs.contains(new ConvertiblePair(sourceType, targetType))) { @@ -483,16 +487,6 @@ private Class getCustomTarget(@NonNull Class sourceType, @Nullable Class sourceType) { - return pair.getSourceType().isAssignableFrom(sourceType); - } - - private static boolean requestedTargetTypeIsAssignable(@Nullable Class requestedTargetType, - @NonNull Class targetType) { - - return requestedTargetType == null || targetType.isAssignableFrom(requestedTargetType); - } - /** * Value object to cache custom conversion targets. * @@ -803,15 +797,14 @@ public Streamable getRegistrationsFor(Object converter) { if (converter instanceof ConverterAware converterAware) { - return Streamable.of(() -> converterAware.getConverters().stream() - .flatMap(it -> getRegistrationsFor(it).stream())); + return Streamable + .of(() -> converterAware.getConverters().stream().flatMap(it -> getRegistrationsFor(it).stream())); } else if (converter instanceof GenericConverter genericConverter) { Set convertibleTypes = genericConverter.getConvertibleTypes(); - return convertibleTypes == null - ? Streamable.empty() + return convertibleTypes == null ? Streamable.empty() : Streamable.of(convertibleTypes).map(it -> register(converter, it, isReading, isWriting)); } else if (converter instanceof ConverterFactory) { @@ -951,8 +944,8 @@ public ConverterConfiguration(StoreConversions storeConversions, List userCon * @param propertyValueConversions can be {@literal null}. * @since 2.7 */ - public ConverterConfiguration(@NonNull StoreConversions storeConversions, @NonNull List userConverters, - @NonNull Predicate converterRegistrationFilter, + public ConverterConfiguration(StoreConversions storeConversions, List userConverters, + Predicate converterRegistrationFilter, @Nullable PropertyValueConversions propertyValueConversions) { this.storeConversions = storeConversions; diff --git a/src/main/java/org/springframework/data/convert/PropertyValueConversionService.java b/src/main/java/org/springframework/data/convert/PropertyValueConversionService.java index 9ed5f21414..d6aa0df296 100644 --- a/src/main/java/org/springframework/data/convert/PropertyValueConversionService.java +++ b/src/main/java/org/springframework/data/convert/PropertyValueConversionService.java @@ -16,7 +16,6 @@ package org.springframework.data.convert; import org.springframework.data.mapping.PersistentProperty; -import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -42,7 +41,7 @@ public class PropertyValueConversionService { * @throws IllegalArgumentException if {@link CustomConversions} is {@literal null}. * @see CustomConversions */ - public PropertyValueConversionService(@NonNull CustomConversions conversions) { + public PropertyValueConversionService(CustomConversions conversions) { Assert.notNull(conversions, "CustomConversions must not be null"); diff --git a/src/main/java/org/springframework/data/convert/PropertyValueConverter.java b/src/main/java/org/springframework/data/convert/PropertyValueConverter.java index e645e32f16..90dd41de26 100644 --- a/src/main/java/org/springframework/data/convert/PropertyValueConverter.java +++ b/src/main/java/org/springframework/data/convert/PropertyValueConverter.java @@ -18,7 +18,6 @@ import java.util.function.BiFunction; import org.springframework.data.mapping.PersistentProperty; -import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; /** @@ -48,8 +47,8 @@ public interface PropertyValueConverter> private final BiFunction, SV> writer; private final BiFunction, DV> reader; - public FunctionPropertyValueConverter(@NonNull BiFunction, SV> writer, - @NonNull BiFunction, DV> reader) { + public FunctionPropertyValueConverter(BiFunction, SV> writer, + BiFunction, DV> reader) { this.writer = writer; this.reader = reader; @@ -136,23 +135,23 @@ public FunctionPropertyValueConverter(@NonNull BiFunction context) { + public SV write(@Nullable DV value, ValueConversionContext

context) { return writer.apply(value, context); } @Override - public SV writeNull(@NonNull ValueConversionContext

context) { + public SV writeNull(ValueConversionContext

context) { return writer.apply(null, context); } @Nullable @Override - public DV read(@Nullable SV value, @NonNull ValueConversionContext

context) { + public DV read(@Nullable SV value, ValueConversionContext

context) { return reader.apply(value, context); } @Override - public DV readNull(@NonNull ValueConversionContext

context) { + public DV readNull(ValueConversionContext

context) { return reader.apply(null, context); } } diff --git a/src/main/java/org/springframework/data/convert/PropertyValueConverterFactories.java b/src/main/java/org/springframework/data/convert/PropertyValueConverterFactories.java index 3d1cf360a1..529023e9b6 100644 --- a/src/main/java/org/springframework/data/convert/PropertyValueConverterFactories.java +++ b/src/main/java/org/springframework/data/convert/PropertyValueConverterFactories.java @@ -215,10 +215,12 @@ static class Cache { Map, Optional>>> perPropertyCache = new ConcurrentHashMap<>(); Map, Optional>>> typeCache = new ConcurrentHashMap<>(); + @Nullable Optional>> get(PersistentProperty property) { return perPropertyCache.get(property); } + @Nullable Optional>> get(Class type) { return typeCache.get(type); } diff --git a/src/main/java/org/springframework/data/convert/PropertyValueConverterRegistrar.java b/src/main/java/org/springframework/data/convert/PropertyValueConverterRegistrar.java index 9d9e70ca50..07154b6cf9 100644 --- a/src/main/java/org/springframework/data/convert/PropertyValueConverterRegistrar.java +++ b/src/main/java/org/springframework/data/convert/PropertyValueConverterRegistrar.java @@ -22,7 +22,6 @@ import org.springframework.data.convert.PropertyValueConverter.FunctionPropertyValueConverter; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.util.MethodInvocationRecorder; -import org.springframework.lang.NonNull; import org.springframework.util.Assert; /** @@ -106,7 +105,7 @@ public PropertyValueConverterRegistrar

registerConverter(Class type, Strin * @throws IllegalArgumentException if the {@link ValueConverterRegistry} is {@literal null}. * @see ValueConverterRegistry */ - public void registerConvertersIn(@NonNull ValueConverterRegistry

target) { + public void registerConvertersIn(ValueConverterRegistry

target) { Assert.notNull(target, "Target registry must not be null"); @@ -119,7 +118,7 @@ public void registerConvertersIn(@NonNull ValueConverterRegistry

target) { * * @return new instance of {@link SimplePropertyValueConverterRegistry}. */ - @NonNull + public ValueConverterRegistry

buildRegistry() { return new SimplePropertyValueConverterRegistry<>(registry); } @@ -135,7 +134,7 @@ public static class WritingConverterRegistrationBuilder config; WritingConverterRegistrationBuilder(Class type, String property, - @NonNull PropertyValueConverterRegistrar

config) { + PropertyValueConverterRegistrar

config) { this.config = config; this.registration = converter -> config.registerConverter(type, property, converter); @@ -173,8 +172,8 @@ public static class ReadingConverterRegistrationBuilder origin; private final BiFunction, R> writer; - ReadingConverterRegistrationBuilder(@NonNull WritingConverterRegistrationBuilder origin, - @NonNull BiFunction, R> writer) { + ReadingConverterRegistrationBuilder(WritingConverterRegistrationBuilder origin, + BiFunction, R> writer) { this.origin = origin; this.writer = writer; diff --git a/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java b/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java index 484fc2e190..9236efa669 100644 --- a/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java +++ b/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java @@ -22,7 +22,6 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.data.convert.PropertyValueConverterFactories.ChainedPropertyValueConverterFactory; import org.springframework.data.mapping.PersistentProperty; -import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -44,8 +43,7 @@ */ public class SimplePropertyValueConversions implements PropertyValueConversions, InitializingBean { - private static final String NO_CONVERTER_FACTORY_ERROR_MESSAGE = - "PropertyValueConverterFactory is not set; Make sure to either set the converter factory or call afterPropertiesSet() to initialize the object"; + private static final String NO_CONVERTER_FACTORY_ERROR_MESSAGE = "PropertyValueConverterFactory is not set; Make sure to either set the converter factory or call afterPropertiesSet() to initialize the object"; private boolean converterCacheEnabled = true; @@ -57,7 +55,7 @@ public class SimplePropertyValueConversions implements PropertyValueConversions, * Set the {@link PropertyValueConverterFactory} responsible for creating the actual {@link PropertyValueConverter}. * * @param converterFactory {@link PropertyValueConverterFactory} used to create the actual - * {@link PropertyValueConverter}. + * {@link PropertyValueConverter}. * @see PropertyValueConverterFactory */ public void setConverterFactory(@Nullable PropertyValueConverterFactory converterFactory) { @@ -76,7 +74,7 @@ public PropertyValueConverterFactory getConverterFactory() { return converterFactory; } - private @NonNull PropertyValueConverterFactory requireConverterFactory() { + private PropertyValueConverterFactory requireConverterFactory() { PropertyValueConverterFactory factory = getConverterFactory(); @@ -113,20 +111,20 @@ public ValueConverterRegistry getValueConverterRegistry() { /** * Configure whether to use converter the cache. Enabled by default. * - * @param converterCacheEnabled set to {@literal true} to enable caching of - * {@link PropertyValueConverter converter} instances. + * @param converterCacheEnabled set to {@literal true} to enable caching of {@link PropertyValueConverter converter} + * instances. */ public void setConverterCacheEnabled(boolean converterCacheEnabled) { this.converterCacheEnabled = converterCacheEnabled; } /** - * Determines whether a {@link PropertyValueConverter} has been registered for - * the given {@link PersistentProperty property}. + * Determines whether a {@link PropertyValueConverter} has been registered for the given {@link PersistentProperty + * property}. * * @param property {@link PersistentProperty} to evaluate. - * @return {@literal true} if a {@link PropertyValueConverter} has been registered for - * the given {@link PersistentProperty property}. + * @return {@literal true} if a {@link PropertyValueConverter} has been registered for the given + * {@link PersistentProperty property}. * @see PersistentProperty */ @Override @@ -134,7 +132,6 @@ public boolean hasValueConverter(PersistentProperty property) { return requireConverterFactory().getConverter(property) != null; } - @NonNull @Override public , D extends ValueConversionContext

> PropertyValueConverter getValueConverter( P property) { @@ -155,8 +152,7 @@ public void init() { factoryList.add(resolveConverterFactory()); - resolveConverterRegistryAsConverterFactory() - .ifPresent(factoryList::add); + resolveConverterRegistryAsConverterFactory().ifPresent(factoryList::add); PropertyValueConverterFactory targetFactory = factoryList.size() > 1 ? PropertyValueConverterFactory.chained(factoryList) @@ -166,18 +162,16 @@ public void init() { : targetFactory; } - private @NonNull PropertyValueConverterFactory resolveConverterFactory() { + private PropertyValueConverterFactory resolveConverterFactory() { PropertyValueConverterFactory converterFactory = getConverterFactory(); - return converterFactory != null ? converterFactory - : PropertyValueConverterFactory.simple(); + return converterFactory != null ? converterFactory : PropertyValueConverterFactory.simple(); } private Optional resolveConverterRegistryAsConverterFactory() { - return Optional.ofNullable(getValueConverterRegistry()) - .filter(it -> !it.isEmpty()) + return Optional.ofNullable(getValueConverterRegistry()).filter(it -> !it.isEmpty()) .map(PropertyValueConverterFactory::configuredInstance); } diff --git a/src/main/java/org/springframework/data/convert/ValueConversionContext.java b/src/main/java/org/springframework/data/convert/ValueConversionContext.java index 2e99f25423..17e76c25d2 100644 --- a/src/main/java/org/springframework/data/convert/ValueConversionContext.java +++ b/src/main/java/org/springframework/data/convert/ValueConversionContext.java @@ -17,7 +17,6 @@ import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.util.TypeInformation; -import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; /** @@ -47,7 +46,7 @@ public interface ValueConversionContext

> { * @param value {@link Object value} to write; can be {@literal null}. * @return can be {@literal null}. * @throws IllegalStateException if value cannot be written as an instance of the - * {@link PersistentProperty#getTypeInformation() property type}. + * {@link PersistentProperty#getTypeInformation() property type}. * @see PersistentProperty#getTypeInformation() * @see #write(Object, TypeInformation) */ @@ -67,7 +66,7 @@ default Object write(@Nullable Object value) { * @see TypeInformation */ @Nullable - default T write(@Nullable Object value, @NonNull Class target) { + default T write(@Nullable Object value, Class target) { return write(value, TypeInformation.of(target)); } @@ -81,7 +80,7 @@ default T write(@Nullable Object value, @NonNull Class target) { * @see TypeInformation */ @Nullable - default T write(@Nullable Object value, @NonNull TypeInformation target) { + default T write(@Nullable Object value, TypeInformation target) { if (value == null || target.getType().isInstance(value)) { return target.getType().cast(value); @@ -97,7 +96,7 @@ default T write(@Nullable Object value, @NonNull TypeInformation target) * @param value {@link Object value} to be read; can be {@literal null}. * @return can be {@literal null}. * @throws IllegalStateException if value cannot be read as an instance of the - * {@link PersistentProperty#getTypeInformation() property type}. + * {@link PersistentProperty#getTypeInformation() property type}. * @see PersistentProperty#getTypeInformation() * @see #read(Object, TypeInformation) */ @@ -117,7 +116,7 @@ default Object read(@Nullable Object value) { * @see TypeInformation */ @Nullable - default T read(@Nullable Object value, @NonNull Class target) { + default T read(@Nullable Object value, Class target) { return read(value, TypeInformation.of(target)); } @@ -131,7 +130,7 @@ default T read(@Nullable Object value, @NonNull Class target) { * @see TypeInformation */ @Nullable - default T read(@Nullable Object value, @NonNull TypeInformation target) { + default T read(@Nullable Object value, TypeInformation target) { if (value == null || target.getType().isInstance(value)) { return target.getType().cast(value); diff --git a/src/main/java/org/springframework/data/repository/util/ClassUtils.java b/src/main/java/org/springframework/data/repository/util/ClassUtils.java index faa46aeddc..dab6ac7cf0 100644 --- a/src/main/java/org/springframework/data/repository/util/ClassUtils.java +++ b/src/main/java/org/springframework/data/repository/util/ClassUtils.java @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.Set; import java.util.function.Consumer; import org.springframework.data.repository.Repository; @@ -110,7 +109,7 @@ public static boolean isGenericRepositoryInterface(@Nullable String interfaceNam * @deprecated Use {@link #getNumberOfOccurrences(Method, Class)}. */ @Deprecated - public static int getNumberOfOccurences(@NonNull Method method, @NonNull Class type) { + public static int getNumberOfOccurences(Method method, Class type) { return getNumberOfOccurrences(method, type); }