DATACMNS-1726 - Delombok source files.
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -29,19 +27,20 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* Simple helper to allow lenient lookup of beans of a given type from a {@link ListableBeanFactory}. This is not user
|
||||
* facing API but a mere helper for Spring Data configuration code.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 2.1
|
||||
* @soundtrack Dave Matthews Band - Bartender (DMB Live 25)
|
||||
*/
|
||||
@UtilityClass
|
||||
public class BeanLookup {
|
||||
public abstract class BeanLookup {
|
||||
|
||||
private BeanLookup() {}
|
||||
|
||||
/**
|
||||
* Returns a {@link Lazy} for the unique bean of the given type from the given {@link BeanFactory} (which needs to be
|
||||
* a {@link ListableBeanFactory}). The lookup will produce a {@link NoUniqueBeanDefinitionException} in case multiple
|
||||
* beans of the given type are available in the given {@link BeanFactory}.
|
||||
*
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @param beanFactory the {@link BeanFactory} to lookup the bean from.
|
||||
* @return a {@link Lazy} for the unique bean of the given type or the instance provided by the fallback in case no
|
||||
@@ -57,7 +56,7 @@ public class BeanLookup {
|
||||
|
||||
/**
|
||||
* Looks up the unique bean of the given type from the given {@link ListableBeanFactory}.
|
||||
*
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @param beanFactory must not be {@literal null}.
|
||||
* @return
|
||||
|
||||
@@ -15,17 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Simple value type to delay the creation of an object using a {@link Supplier} returning the produced object for
|
||||
@@ -36,17 +32,25 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@EqualsAndHashCode
|
||||
public class Lazy<T> implements Supplier<T> {
|
||||
|
||||
private static final Lazy<?> EMPTY = new Lazy<>(() -> null, null, true);
|
||||
|
||||
private final Supplier<? extends T> supplier;
|
||||
|
||||
private @Nullable T value = null;
|
||||
private boolean resolved = false;
|
||||
|
||||
public Lazy(Supplier<? extends T> supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
private Lazy(Supplier<? extends T> supplier, T value, boolean resolved) {
|
||||
this.supplier = supplier;
|
||||
this.value = value;
|
||||
this.resolved = resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Lazy} to produce an object lazily.
|
||||
*
|
||||
@@ -216,4 +220,44 @@ public class Lazy<T> implements Supplier<T> {
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Lazy)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Lazy<?> lazy = (Lazy<?>) o;
|
||||
|
||||
if (resolved != lazy.resolved) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(supplier, lazy.supplier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(value, lazy.value);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(supplier);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(value);
|
||||
result = 31 * result + (resolved ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
@@ -27,11 +25,18 @@ import java.util.stream.Stream;
|
||||
* @author Oliver Gierke
|
||||
* @since 2.0
|
||||
*/
|
||||
@Value(staticConstructor = "of")
|
||||
class LazyStreamable<T> implements Streamable<T> {
|
||||
final class LazyStreamable<T> implements Streamable<T> {
|
||||
|
||||
private final Supplier<? extends Stream<T>> stream;
|
||||
|
||||
private LazyStreamable(Supplier<? extends Stream<T>> stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public static <T> LazyStreamable<T> of(Supplier<? extends Stream<T>> stream) {
|
||||
return new LazyStreamable<T>(stream);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
@@ -49,4 +54,17 @@ class LazyStreamable<T> implements Streamable<T> {
|
||||
public Stream<T> stream() {
|
||||
return stream.get();
|
||||
}
|
||||
|
||||
public Supplier<? extends Stream<T>> getStream() {
|
||||
return this.stream;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LazyStreamable(stream=" + this.getStream() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.Value;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
@@ -31,14 +24,14 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -49,7 +42,6 @@ import org.springframework.util.StringUtils;
|
||||
* @since 2.2
|
||||
* @soundtrack The Intersphere - Don't Think Twice (The Grand Delusion)
|
||||
*/
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class MethodInvocationRecorder {
|
||||
|
||||
public static PropertyNameDetectionStrategy DEFAULT = DefaultPropertyNameDetectionStrategy.INSTANCE;
|
||||
@@ -64,6 +56,10 @@ public class MethodInvocationRecorder {
|
||||
this(Optional.empty());
|
||||
}
|
||||
|
||||
private MethodInvocationRecorder(Optional<RecordingMethodInterceptor> interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Recorded} for the given type.
|
||||
*
|
||||
@@ -169,13 +165,17 @@ public class MethodInvocationRecorder {
|
||||
}
|
||||
}
|
||||
|
||||
@Value
|
||||
private static class InvocationInformation {
|
||||
private static final class InvocationInformation {
|
||||
|
||||
static final InvocationInformation NOT_INVOKED = new InvocationInformation(new Unrecorded(), null);
|
||||
private static final InvocationInformation NOT_INVOKED = new InvocationInformation(new Unrecorded(), null);
|
||||
|
||||
@NonNull Recorded<?> recorded;
|
||||
@Nullable Method invokedMethod;
|
||||
private final Recorded<?> recorded;
|
||||
@Nullable private final Method invokedMethod;
|
||||
|
||||
public InvocationInformation(Recorded<?> recorded, Method invokedMethod) {
|
||||
this.recorded = recorded;
|
||||
this.invokedMethod = invokedMethod;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Object getCurrentInstance() {
|
||||
@@ -205,6 +205,60 @@ public class MethodInvocationRecorder {
|
||||
.orElseThrow(() -> new IllegalArgumentException(
|
||||
String.format("No property name found for method %s!", invokedMethod)));
|
||||
}
|
||||
|
||||
public Recorded<?> getRecorded() {
|
||||
return this.recorded;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Method getInvokedMethod() {
|
||||
return this.invokedMethod;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof InvocationInformation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
InvocationInformation that = (InvocationInformation) o;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(recorded, that.recorded)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(invokedMethod, that.invokedMethod);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(recorded);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(invokedMethod);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MethodInvocationRecorder.InvocationInformation(recorded=" + this.getRecorded() + ", invokedMethod="
|
||||
+ this.getInvokedMethod() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public interface PropertyNameDetectionStrategy {
|
||||
@@ -213,7 +267,7 @@ public class MethodInvocationRecorder {
|
||||
String getPropertyName(Method method);
|
||||
}
|
||||
|
||||
private static enum DefaultPropertyNameDetectionStrategy implements PropertyNameDetectionStrategy {
|
||||
private enum DefaultPropertyNameDetectionStrategy implements PropertyNameDetectionStrategy {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -221,7 +275,7 @@ public class MethodInvocationRecorder {
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.core.Recorder.PropertyNameDetectionStrategy#getPropertyName(java.lang.reflect.Method)
|
||||
*/
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public String getPropertyName(Method method) {
|
||||
return getPropertyName(method.getReturnType(), method.getName());
|
||||
@@ -240,13 +294,16 @@ public class MethodInvocationRecorder {
|
||||
}
|
||||
}
|
||||
|
||||
@ToString
|
||||
@RequiredArgsConstructor
|
||||
public static class Recorded<T> {
|
||||
|
||||
private final @Nullable T currentInstance;
|
||||
private final @Nullable MethodInvocationRecorder recorder;
|
||||
|
||||
public Recorded(T currentInstance, MethodInvocationRecorder recorder) {
|
||||
this.currentInstance = currentInstance;
|
||||
this.recorder = recorder;
|
||||
}
|
||||
|
||||
public Optional<String> getPropertyPath() {
|
||||
return getPropertyPath(MethodInvocationRecorder.DEFAULT);
|
||||
}
|
||||
@@ -304,6 +361,16 @@ public class MethodInvocationRecorder {
|
||||
return new Recorded<S>(converter.apply(currentInstance).values().iterator().next(), recorder);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MethodInvocationRecorder.Recorded(currentInstance=" + this.currentInstance + ", recorder=" + this.recorder
|
||||
+ ")";
|
||||
}
|
||||
|
||||
public interface ToCollectionConverter<T, S> extends Function<T, Collection<S>> {}
|
||||
|
||||
public interface ToMapConverter<T, S> extends Function<T, Map<?, S>> {}
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
@@ -37,11 +33,19 @@ import org.springframework.util.MultiValueMap;
|
||||
* @author Jens Schauder
|
||||
* @since 2.0
|
||||
*/
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE, staticName = "of")
|
||||
class MultiValueMapCollector<T, K, V> implements Collector<T, MultiValueMap<K, V>, MultiValueMap<K, V>> {
|
||||
|
||||
private final @NonNull Function<T, K> keyFunction;
|
||||
private final @NonNull Function<T, V> valueFunction;
|
||||
private final Function<T, K> keyFunction;
|
||||
private final Function<T, V> valueFunction;
|
||||
|
||||
private MultiValueMapCollector(Function<T, K> keyFunction, Function<T, V> valueFunction) {
|
||||
this.keyFunction = keyFunction;
|
||||
this.valueFunction = valueFunction;
|
||||
}
|
||||
|
||||
static <T, K, V> MultiValueMapCollector<T, K, V> of(Function<T, K> keyFunction, Function<T, V> valueFunction) {
|
||||
return new MultiValueMapCollector<T, K, V>(keyFunction, valueFunction);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
@@ -81,8 +79,7 @@ import org.springframework.util.MultiValueMap;
|
||||
* @see Nullable
|
||||
* @see Nonnull
|
||||
*/
|
||||
@UtilityClass
|
||||
public class NullableUtils {
|
||||
public abstract class NullableUtils {
|
||||
|
||||
private static final String NON_NULL_CLASS_NAME = "javax.annotation.Nonnull";
|
||||
private static final String TYPE_QUALIFIER_CLASS_NAME = "javax.annotation.meta.TypeQualifierDefault";
|
||||
@@ -96,6 +93,8 @@ public class NullableUtils {
|
||||
private static final Set<String> WHEN_NULLABLE = new HashSet<>(Arrays.asList("UNKNOWN", "MAYBE", "NEVER"));
|
||||
private static final Set<String> WHEN_NON_NULLABLE = new HashSet<>(Collections.singletonList("ALWAYS"));
|
||||
|
||||
private NullableUtils() {}
|
||||
|
||||
/**
|
||||
* Determine whether {@link ElementType} in the scope of {@link Method} requires non-{@literal null} values.
|
||||
* Non-nullability rules are discovered from class and package annotations. Non-null is applied when
|
||||
@@ -106,7 +105,7 @@ public class NullableUtils {
|
||||
* @return {@literal true} if {@link ElementType} allows {@literal null} values by default.
|
||||
* @see #isNonNull(Annotation, ElementType)
|
||||
*/
|
||||
public boolean isNonNull(Method method, ElementType elementType) {
|
||||
public static boolean isNonNull(Method method, ElementType elementType) {
|
||||
return isNonNull(method.getDeclaringClass(), elementType) || isNonNull((AnnotatedElement) method, elementType);
|
||||
}
|
||||
|
||||
@@ -120,7 +119,7 @@ public class NullableUtils {
|
||||
* @return {@literal true} if {@link ElementType} allows {@literal null} values by default.
|
||||
* @see #isNonNull(Annotation, ElementType)
|
||||
*/
|
||||
public boolean isNonNull(Class<?> type, ElementType elementType) {
|
||||
public static boolean isNonNull(Class<?> type, ElementType elementType) {
|
||||
return isNonNull(type.getPackage(), elementType) || isNonNull((AnnotatedElement) type, elementType);
|
||||
}
|
||||
|
||||
@@ -133,7 +132,7 @@ public class NullableUtils {
|
||||
* @param elementType the element type.
|
||||
* @return {@literal true} if {@link ElementType} allows {@literal null} values by default.
|
||||
*/
|
||||
public boolean isNonNull(AnnotatedElement element, ElementType elementType) {
|
||||
public static boolean isNonNull(AnnotatedElement element, ElementType elementType) {
|
||||
|
||||
for (Annotation annotation : element.getAnnotations()) {
|
||||
|
||||
|
||||
@@ -15,17 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* A tuple of things.
|
||||
*
|
||||
@@ -36,13 +33,19 @@ import java.util.stream.Stream;
|
||||
* @param <T> Type of the second thing.
|
||||
* @since 1.12
|
||||
*/
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class Pair<S, T> {
|
||||
|
||||
private final @NonNull S first;
|
||||
private final @NonNull T second;
|
||||
private final S first;
|
||||
private final T second;
|
||||
|
||||
private Pair(S first, T second) {
|
||||
|
||||
Assert.notNull(first, "First must not be null!");
|
||||
Assert.notNull(second, "Second must not be null!");
|
||||
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Pair} for the given elements.
|
||||
@@ -81,4 +84,48 @@ public final class Pair<S, T> {
|
||||
public static <S, T> Collector<Pair<S, T>, ?, Map<S, T>> toMap() {
|
||||
return Collectors.toMap(Pair::getFirst, Pair::getSecond);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Pair)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pair<?, ?> pair = (Pair<?, ?>) o;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(first, pair.first)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(second, pair.second);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(first);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(second);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s->%s", this.first, this.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -31,6 +28,7 @@ import java.util.stream.Collectors;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.TypeUtils;
|
||||
|
||||
/**
|
||||
@@ -43,8 +41,6 @@ import org.springframework.util.TypeUtils;
|
||||
* @since 2.1.7
|
||||
* @soundtrack Signs, High Times - Tedeschi Trucks Band (Signs)
|
||||
*/
|
||||
@EqualsAndHashCode(of = "types")
|
||||
@RequiredArgsConstructor
|
||||
public class ParameterTypes {
|
||||
|
||||
private static final TypeDescriptor OBJECT_DESCRIPTOR = TypeDescriptor.valueOf(Object.class);
|
||||
@@ -64,6 +60,11 @@ public class ParameterTypes {
|
||||
this.alternatives = Lazy.of(() -> getAlternatives());
|
||||
}
|
||||
|
||||
public ParameterTypes(List<TypeDescriptor> types, Lazy<Collection<ParameterTypes>> alternatives) {
|
||||
this.types = types;
|
||||
this.alternatives = alternatives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ParameterTypes} for the given list of {@link TypeDescriptor}s.
|
||||
*
|
||||
@@ -276,13 +277,37 @@ public class ParameterTypes {
|
||||
return types.get(types.size() - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof ParameterTypes)) {
|
||||
return false;
|
||||
}
|
||||
ParameterTypes that = (ParameterTypes) o;
|
||||
return ObjectUtils.nullSafeEquals(types, that.types);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ObjectUtils.nullSafeHashCode(types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension of {@link ParameterTypes} that remembers the seed tail and only adds typed varargs if the current tail is
|
||||
* assignable to the seed one.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
static class ParentParameterTypes extends ParameterTypes {
|
||||
|
||||
private final TypeDescriptor tail;
|
||||
@@ -317,5 +342,39 @@ public class ParameterTypes {
|
||||
? Optional.empty() //
|
||||
: super.withLastVarArgs();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof ParentParameterTypes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ParentParameterTypes that = (ParentParameterTypes) o;
|
||||
return ObjectUtils.nullSafeEquals(tail, that.tail);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(tail);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -31,8 +29,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.5
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ParsingUtils {
|
||||
public abstract class ParsingUtils {
|
||||
|
||||
private static final String UPPER = "\\p{Lu}|\\P{InBASIC_LATIN}";
|
||||
private static final String LOWER = "\\p{Ll}";
|
||||
@@ -41,6 +38,8 @@ public class ParsingUtils {
|
||||
|
||||
private static final Pattern CAMEL_CASE = Pattern.compile(CAMEL_CASE_REGEX);
|
||||
|
||||
private ParsingUtils() {}
|
||||
|
||||
/**
|
||||
* Splits up the given camel-case {@link String}.
|
||||
*
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -28,12 +26,11 @@ import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
|
||||
/**
|
||||
* Proxy type detection utilities, extensible via {@link ProxyDetector} registered via Spring factories.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Victor Wooten - Cruising Altitude (Trypnotix)
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ProxyUtils {
|
||||
public abstract class ProxyUtils {
|
||||
|
||||
private static Map<Class<?>, Class<?>> USER_TYPES = new ConcurrentReferenceHashMap<>();
|
||||
|
||||
@@ -44,9 +41,11 @@ public class ProxyUtils {
|
||||
DETECTORS.add(ClassUtils::getUserClass);
|
||||
}
|
||||
|
||||
private ProxyUtils() {}
|
||||
|
||||
/**
|
||||
* Returns the user class for the given type.
|
||||
*
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -68,7 +67,7 @@ public class ProxyUtils {
|
||||
|
||||
/**
|
||||
* Returns the user class for the given source object.
|
||||
*
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -84,11 +83,11 @@ public class ProxyUtils {
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface ProxyDetector {
|
||||
public static interface ProxyDetector {
|
||||
|
||||
/**
|
||||
* Returns the user class for the given type.
|
||||
*
|
||||
*
|
||||
* @param type will never be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -49,8 +45,11 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
* @author Mark Paluch
|
||||
* @since 1.5
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ReflectionUtils {
|
||||
public final class ReflectionUtils {
|
||||
|
||||
private ReflectionUtils() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the class with the given fully qualified name or returns the given default instance if the
|
||||
@@ -92,10 +91,13 @@ public class ReflectionUtils {
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public static class AnnotationFieldFilter implements DescribedFieldFilter {
|
||||
|
||||
private final @NonNull Class<? extends Annotation> annotationType;
|
||||
private final Class<? extends Annotation> annotationType;
|
||||
|
||||
public AnnotationFieldFilter(Class<? extends Annotation> annotationType) {
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -28,7 +24,16 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -37,6 +42,7 @@ import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -573,12 +579,15 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
* @author Oliver Gierke
|
||||
* @since 1.11
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor
|
||||
private static class SyntheticParamterizedType implements ParameterizedType {
|
||||
|
||||
private final @NonNull ClassTypeInformation<?> typeInformation;
|
||||
private final @NonNull List<TypeInformation<?>> typeParameters;
|
||||
private final ClassTypeInformation<?> typeInformation;
|
||||
private final List<TypeInformation<?>> typeParameters;
|
||||
|
||||
public SyntheticParamterizedType(ClassTypeInformation<?> typeInformation, List<TypeInformation<?>> typeParameters) {
|
||||
this.typeInformation = typeInformation;
|
||||
this.typeParameters = typeParameters;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -614,5 +623,40 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof SyntheticParamterizedType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SyntheticParamterizedType that = (SyntheticParamterizedType) o;
|
||||
|
||||
if (!ObjectUtils.nullSafeEquals(typeInformation, that.typeInformation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(typeParameters, that.typeParameters);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ObjectUtils.nullSafeHashCode(typeInformation);
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(typeParameters);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user