DATACMNS-1726 - Delombok source files.
This commit is contained in:
@@ -15,13 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.convert;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -37,6 +30,8 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
@@ -49,6 +44,7 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Value object to capture custom conversion. That is essentially a {@link List} of converters and some additional logic
|
||||
@@ -62,9 +58,9 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
@Slf4j
|
||||
public class CustomConversions {
|
||||
|
||||
private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(CustomConversions.class);
|
||||
private static final String READ_CONVERTER_NOT_SIMPLE = "Registering converter from %s to %s as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.";
|
||||
private static final String WRITE_CONVERTER_NOT_SIMPLE = "Registering converter from %s to %s as writing converter although it doesn't convert to a store-supported type! You might want to check your annotation setup at the converter implementation.";
|
||||
private static final String NOT_A_CONVERTER = "Converter %s is neither a Spring Converter, GenericConverter or ConverterFactory!";
|
||||
@@ -511,12 +507,15 @@ public class CustomConversions {
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
static class TargetTypes {
|
||||
|
||||
private final @NonNull Class<?> sourceType;
|
||||
private final Class<?> sourceType;
|
||||
private final Map<Class<?>, Class<?>> conversionTargets = new ConcurrentHashMap<>();
|
||||
|
||||
TargetTypes(Class<?> sourceType) {
|
||||
this.sourceType = sourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or compute a target type given its {@code targetType}. Returns a cached {@link Optional} if the value
|
||||
* (present/absent target) was computed once. Otherwise, uses a {@link Function mappingFunction} to determine a
|
||||
@@ -624,15 +623,23 @@ public class CustomConversions {
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
private static class ConverterRegistration {
|
||||
|
||||
private final Object converter;
|
||||
private final @NonNull ConvertiblePair convertiblePair;
|
||||
private final @NonNull StoreConversions storeConversions;
|
||||
private final ConvertiblePair convertiblePair;
|
||||
private final StoreConversions storeConversions;
|
||||
private final boolean reading;
|
||||
private final boolean writing;
|
||||
|
||||
private ConverterRegistration(Object converter, ConvertiblePair convertiblePair, StoreConversions storeConversions,
|
||||
boolean reading, boolean writing) {
|
||||
this.converter = converter;
|
||||
this.convertiblePair = convertiblePair;
|
||||
this.storeConversions = storeConversions;
|
||||
this.reading = reading;
|
||||
this.writing = writing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the converter shall be used for writing.
|
||||
*
|
||||
@@ -692,15 +699,18 @@ public class CustomConversions {
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Value
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public static class StoreConversions {
|
||||
|
||||
public static final StoreConversions NONE = StoreConversions.of(SimpleTypeHolder.DEFAULT, Collections.emptyList());
|
||||
|
||||
SimpleTypeHolder storeTypeHolder;
|
||||
Collection<?> storeConverters;
|
||||
private final SimpleTypeHolder storeTypeHolder;
|
||||
private final Collection<?> storeConverters;
|
||||
|
||||
private StoreConversions(SimpleTypeHolder storeTypeHolder, Collection<?> storeConverters) {
|
||||
|
||||
this.storeTypeHolder = storeTypeHolder;
|
||||
this.storeConverters = storeConverters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link StoreConversions} for the given store-specific {@link SimpleTypeHolder} and the given
|
||||
@@ -800,6 +810,57 @@ public class CustomConversions {
|
||||
private boolean isStoreSimpleType(Class<?> type) {
|
||||
return storeTypeHolder.isSimpleType(type);
|
||||
}
|
||||
|
||||
SimpleTypeHolder getStoreTypeHolder() {
|
||||
return this.storeTypeHolder;
|
||||
}
|
||||
|
||||
Collection<?> getStoreConverters() {
|
||||
return this.storeConverters;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof StoreConversions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StoreConversions that = (StoreConversions) o;
|
||||
if (!ObjectUtils.nullSafeEquals(storeTypeHolder, that.storeTypeHolder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(storeConverters, that.storeConverters);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(storeTypeHolder);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(storeConverters);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StoreConversions{" + "storeTypeHolder=" + storeTypeHolder + ", storeConverters=" + storeConverters + '}';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,20 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.convert;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.With;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
@@ -38,6 +30,7 @@ import org.springframework.data.convert.ConverterBuilder.ReadingConverterBuilder
|
||||
import org.springframework.data.convert.ConverterBuilder.WritingConverterBuilder;
|
||||
import org.springframework.data.util.Optionals;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Builder to easily set up (bi-directional) {@link Converter} instances for Spring Data type mapping using Lambdas. Use
|
||||
@@ -50,14 +43,20 @@ import org.springframework.lang.Nullable;
|
||||
* @see ConverterBuilder#reading(Class, Class, Function)
|
||||
* @soundtrack John Mayer - Still Feel Like Your Man (The Search for Everything)
|
||||
*/
|
||||
@With(AccessLevel.PACKAGE)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
class DefaultConverterBuilder<S, T>
|
||||
implements ConverterAware, ReadingConverterBuilder<T, S>, WritingConverterBuilder<S, T> {
|
||||
|
||||
private final @NonNull ConvertiblePair convertiblePair;
|
||||
private final @NonNull Optional<Function<? super S, ? extends T>> writing;
|
||||
private final @NonNull Optional<Function<? super T, ? extends S>> reading;
|
||||
private final ConvertiblePair convertiblePair;
|
||||
private final Optional<Function<? super S, ? extends T>> writing;
|
||||
private final Optional<Function<? super T, ? extends S>> reading;
|
||||
|
||||
DefaultConverterBuilder(ConvertiblePair convertiblePair, Optional<Function<? super S, ? extends T>> writing,
|
||||
Optional<Function<? super T, ? extends S>> reading) {
|
||||
this.convertiblePair = convertiblePair;
|
||||
this.writing = writing;
|
||||
this.reading = reading;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -121,13 +120,26 @@ class DefaultConverterBuilder<S, T>
|
||||
return new ConvertiblePair(convertiblePair.getTargetType(), convertiblePair.getSourceType());
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
DefaultConverterBuilder<S, T> withWriting(Optional<Function<? super S, ? extends T>> writing) {
|
||||
return this.writing == writing ? this
|
||||
: new DefaultConverterBuilder<S, T>(this.convertiblePair, writing, this.reading);
|
||||
}
|
||||
|
||||
DefaultConverterBuilder<S, T> withReading(Optional<Function<? super T, ? extends S>> reading) {
|
||||
return this.reading == reading ? this
|
||||
: new DefaultConverterBuilder<S, T>(this.convertiblePair, this.writing, reading);
|
||||
}
|
||||
|
||||
private static class ConfigurableGenericConverter<S, T> implements GenericConverter {
|
||||
|
||||
private final ConvertiblePair convertiblePair;
|
||||
private final Function<? super S, ? extends T> function;
|
||||
|
||||
public ConfigurableGenericConverter(ConvertiblePair convertiblePair, Function<? super S, ? extends T> function) {
|
||||
this.convertiblePair = convertiblePair;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
|
||||
@@ -143,12 +155,47 @@ class DefaultConverterBuilder<S, T>
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
|
||||
*/
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return Collections.singleton(convertiblePair);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof ConfigurableGenericConverter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ConfigurableGenericConverter<?, ?> that = (ConfigurableGenericConverter<?, ?>) o;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(convertiblePair, that.convertiblePair)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(function, that.function);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(convertiblePair);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(function);
|
||||
return result;
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
private static class Writing<S, T> extends ConfigurableGenericConverter<S, T> {
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.convert;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.model.ParameterValueProvider;
|
||||
@@ -26,11 +24,14 @@ import org.springframework.data.mapping.model.ParameterValueProvider;
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class EntityInstantiatorAdapter implements EntityInstantiator {
|
||||
|
||||
private final org.springframework.data.mapping.model.EntityInstantiator delegate;
|
||||
|
||||
EntityInstantiatorAdapter(org.springframework.data.mapping.model.EntityInstantiator delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.model.EntityInstantiator#createInstance(org.springframework.data.mapping.PersistentEntity, org.springframework.data.mapping.model.ParameterValueProvider)
|
||||
|
||||
Reference in New Issue
Block a user