Skip to content

Commit

Permalink
Remove superfluous @NonNull annotations.
Browse files Browse the repository at this point in the history
Closes #2976
  • Loading branch information
mp911de committed Nov 13, 2023
1 parent 7803230 commit 97be53b
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 147 deletions.
185 changes: 89 additions & 96 deletions src/main/java/org/springframework/data/convert/CustomConversions.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -48,8 +47,8 @@ public interface PropertyValueConverter<DV, SV, C extends ValueConversionContext
* operation.
*
* @param value value to read.
* @param context {@link ValueConversionContext} containing store-specific metadata
* used in the value conversion; never {@literal null}.
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
* never {@literal null}.
* @return the converted value. Can be {@literal null}.
*/
@Nullable
Expand All @@ -59,8 +58,8 @@ public interface PropertyValueConverter<DV, SV, C extends ValueConversionContext
* Convert the given {@code null} value from the store into its domain value representation. Typically, a
* {@literal read} operation. Returns {@code null} by default.
*
* @param context {@link ValueConversionContext} containing store-specific metadata
* used in the value conversion; never {@literal null}.
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
* never {@literal null}.
* @return the converted value. Can be {@literal null}.
*/
@Nullable
Expand All @@ -73,8 +72,8 @@ default DV readNull(C context) {
* operation.
*
* @param value value to write; can be {@literal null}.
* @param context {@link ValueConversionContext} containing store-specific metadata
* used in the value conversion; never {@literal null}.
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
* never {@literal null}.
* @return the converted value. Can be {@literal null}.
*/
@Nullable
Expand All @@ -84,8 +83,8 @@ default DV readNull(C context) {
* Convert the given {@code null} value from the domain model into it's native store representation. Typically, a
* {@literal write} operation. Returns {@code null} by default.
*
* @param context {@link ValueConversionContext} containing store-specific metadata
* used in the value conversion; never {@literal null}.
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
* never {@literal null}.
* @return the converted value. Can be {@literal null}.
*/
@Nullable
Expand Down Expand Up @@ -127,32 +126,32 @@ class FunctionPropertyValueConverter<DV, SV, P extends PersistentProperty<P>>
private final BiFunction<DV, ValueConversionContext<P>, SV> writer;
private final BiFunction<SV, ValueConversionContext<P>, DV> reader;

public FunctionPropertyValueConverter(@NonNull BiFunction<DV, ValueConversionContext<P>, SV> writer,
@NonNull BiFunction<SV, ValueConversionContext<P>, DV> reader) {
public FunctionPropertyValueConverter(BiFunction<DV, ValueConversionContext<P>, SV> writer,
BiFunction<SV, ValueConversionContext<P>, DV> reader) {

this.writer = writer;
this.reader = reader;
}

@Nullable
@Override
public SV write(@Nullable DV value, @NonNull ValueConversionContext<P> context) {
public SV write(@Nullable DV value, ValueConversionContext<P> context) {
return writer.apply(value, context);
}

@Override
public SV writeNull(@NonNull ValueConversionContext<P> context) {
public SV writeNull(ValueConversionContext<P> context) {
return writer.apply(null, context);
}

@Nullable
@Override
public DV read(@Nullable SV value, @NonNull ValueConversionContext<P> context) {
public DV read(@Nullable SV value, ValueConversionContext<P> context) {
return reader.apply(value, context);
}

@Override
public DV readNull(@NonNull ValueConversionContext<P> context) {
public DV readNull(ValueConversionContext<P> context) {
return reader.apply(null, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ static class Cache {
Map<PersistentProperty<?>, Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>>> perPropertyCache = new ConcurrentHashMap<>();
Map<Class<?>, Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>>> typeCache = new ConcurrentHashMap<>();

@Nullable
Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>> get(PersistentProperty<?> property) {
return perPropertyCache.get(property);
}

@Nullable
Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>> get(Class<?> type) {
return typeCache.get(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -106,7 +105,7 @@ public PropertyValueConverterRegistrar<P> registerConverter(Class<?> type, Strin
* @throws IllegalArgumentException if the {@link ValueConverterRegistry} is {@literal null}.
* @see ValueConverterRegistry
*/
public void registerConvertersIn(@NonNull ValueConverterRegistry<P> target) {
public void registerConvertersIn(ValueConverterRegistry<P> target) {

Assert.notNull(target, "Target registry must not be null");

Expand All @@ -119,7 +118,7 @@ public void registerConvertersIn(@NonNull ValueConverterRegistry<P> target) {
*
* @return new instance of {@link SimplePropertyValueConverterRegistry}.
*/
@NonNull

public ValueConverterRegistry<P> buildRegistry() {
return new SimplePropertyValueConverterRegistry<>(registry);
}
Expand All @@ -135,7 +134,7 @@ public static class WritingConverterRegistrationBuilder<T, S, P extends Persiste
private final PropertyValueConverterRegistrar<P> config;

WritingConverterRegistrationBuilder(Class<T> type, String property,
@NonNull PropertyValueConverterRegistrar<P> config) {
PropertyValueConverterRegistrar<P> config) {

this.config = config;
this.registration = converter -> config.registerConverter(type, property, converter);
Expand Down Expand Up @@ -173,8 +172,8 @@ public static class ReadingConverterRegistrationBuilder<T, S, R, P extends Persi
private final WritingConverterRegistrationBuilder<T, S, P> origin;
private final BiFunction<S, ValueConversionContext<P>, R> writer;

ReadingConverterRegistrationBuilder(@NonNull WritingConverterRegistrationBuilder<T, S, P> origin,
@NonNull BiFunction<S, ValueConversionContext<P>, R> writer) {
ReadingConverterRegistrationBuilder(WritingConverterRegistrationBuilder<T, S, P> origin,
BiFunction<S, ValueConversionContext<P>, R> writer) {

this.origin = origin;
this.writer = writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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) {
Expand All @@ -76,7 +74,7 @@ public PropertyValueConverterFactory getConverterFactory() {
return converterFactory;
}

private @NonNull PropertyValueConverterFactory requireConverterFactory() {
private PropertyValueConverterFactory requireConverterFactory() {

PropertyValueConverterFactory factory = getConverterFactory();

Expand Down Expand Up @@ -113,28 +111,27 @@ 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
public boolean hasValueConverter(PersistentProperty<?> property) {
return requireConverterFactory().getConverter(property) != null;
}

@NonNull
@Override
public <DV, SV, P extends PersistentProperty<P>, D extends ValueConversionContext<P>> PropertyValueConverter<DV, SV, D> getValueConverter(
P property) {
Expand All @@ -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)
Expand All @@ -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<PropertyValueConverterFactory> resolveConverterRegistryAsConverterFactory() {

return Optional.ofNullable(getValueConverterRegistry())
.filter(it -> !it.isEmpty())
return Optional.ofNullable(getValueConverterRegistry()).filter(it -> !it.isEmpty())
.map(PropertyValueConverterFactory::configuredInstance);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -47,7 +46,7 @@ public interface ValueConversionContext<P extends PersistentProperty<P>> {
* @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)
*/
Expand All @@ -67,7 +66,7 @@ default Object write(@Nullable Object value) {
* @see TypeInformation
*/
@Nullable
default <T> T write(@Nullable Object value, @NonNull Class<T> target) {
default <T> T write(@Nullable Object value, Class<T> target) {
return write(value, TypeInformation.of(target));
}

Expand All @@ -81,7 +80,7 @@ default <T> T write(@Nullable Object value, @NonNull Class<T> target) {
* @see TypeInformation
*/
@Nullable
default <T> T write(@Nullable Object value, @NonNull TypeInformation<T> target) {
default <T> T write(@Nullable Object value, TypeInformation<T> target) {

if (value == null || target.getType().isInstance(value)) {
return target.getType().cast(value);
Expand All @@ -97,7 +96,7 @@ default <T> T write(@Nullable Object value, @NonNull TypeInformation<T> 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)
*/
Expand All @@ -117,7 +116,7 @@ default Object read(@Nullable Object value) {
* @see TypeInformation
*/
@Nullable
default <T> T read(@Nullable Object value, @NonNull Class<T> target) {
default <T> T read(@Nullable Object value, Class<T> target) {
return read(value, TypeInformation.of(target));
}

Expand All @@ -131,7 +130,7 @@ default <T> T read(@Nullable Object value, @NonNull Class<T> target) {
* @see TypeInformation
*/
@Nullable
default <T> T read(@Nullable Object value, @NonNull TypeInformation<T> target) {
default <T> T read(@Nullable Object value, TypeInformation<T> target) {

if (value == null || target.getType().isInstance(value)) {
return target.getType().cast(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 97be53b

Please sign in to comment.