DATACMNS-867 - Additional Java 8 language feature cleanup.
Make use of lambdas and method references though out the codebase. Remove no longer required generic type parameters. Additionally remove unused imports and replace single element list initialization with dedicated singletonList. Use Assertion overloads taking Supplier for dynamic assertion error messages.
This commit is contained in:
committed by
Oliver Gierke
parent
aa4c51e1ea
commit
be347eaaab
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -23,6 +23,7 @@ import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Value
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@@ -57,7 +58,7 @@ public class Alias {
|
||||
}
|
||||
|
||||
public <T> Optional<T> mapTyped(Class<T> type) {
|
||||
return value.filter(it -> type.isInstance(it)).map(it -> type.cast(it));
|
||||
return value.filter(type::isInstance).map(type::cast);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2017 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.
|
||||
@@ -42,12 +42,13 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Jon Brisbin
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
|
||||
private final Constructor<T> constructor;
|
||||
private final List<Parameter<Object, P>> parameters;
|
||||
private final Map<PersistentProperty<?>, Boolean> isPropertyParameterCache = new HashMap<PersistentProperty<?>, Boolean>();
|
||||
private final Map<PersistentProperty<?>, Boolean> isPropertyParameterCache = new HashMap<>();
|
||||
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
private final Lock read = lock.readLock();
|
||||
@@ -218,7 +219,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
this.entity = entity;
|
||||
|
||||
this.enclosingClassCache = Lazy.of(() -> {
|
||||
Class<T> owningType = entity.orElseThrow(() -> new IllegalStateException()).getType();
|
||||
Class<T> owningType = entity.orElseThrow(IllegalStateException::new).getType();
|
||||
return owningType.isMemberClass() && type.getType().equals(owningType.getEnclosingClass());
|
||||
});
|
||||
|
||||
@@ -230,7 +231,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
return Arrays.stream(annotations)//
|
||||
.filter(it -> it.annotationType() == Value.class)//
|
||||
.findFirst().map(it -> ((Value) it).value())//
|
||||
.filter(it -> StringUtils.hasText(it));
|
||||
.filter(StringUtils::hasText);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,13 +287,11 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
*/
|
||||
boolean maps(PersistentProperty<?> property) {
|
||||
|
||||
if (!name.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return entity//
|
||||
.flatMap(it -> it.getPersistentProperty(name.get()))//
|
||||
.map(it -> property.equals(it)).orElse(false);
|
||||
//
|
||||
//
|
||||
return name.map(s -> entity
|
||||
.flatMap(it -> it.getPersistentProperty(s))
|
||||
.map(property::equals).orElse(false)).orElse(false);
|
||||
}
|
||||
|
||||
private boolean isEnclosingClassParameter() {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
* @param owningType must not be {@literal null}.
|
||||
*/
|
||||
PropertyPath(String name, Class<?> owningType) {
|
||||
this(name, ClassTypeInformation.from(owningType), Collections.<PropertyPath> emptyList());
|
||||
this(name, ClassTypeInformation.from(owningType), Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 by the original author(s).
|
||||
* Copyright 2011-2017 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,6 +76,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Tomasz Wysocki
|
||||
* @author Mark Paluch
|
||||
* @author Mikael Klamra
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
|
||||
implements MappingContext<E, P>, ApplicationEventPublisherAware, InitializingBean {
|
||||
@@ -86,7 +87,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
private Set<? extends Class<?>> initialEntitySet = new HashSet<Class<?>>();
|
||||
private Set<? extends Class<?>> initialEntitySet = new HashSet<>();
|
||||
private boolean strict = false;
|
||||
private SimpleTypeHolder simpleTypeHolder = new SimpleTypeHolder();
|
||||
|
||||
@@ -147,7 +148,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
read.lock();
|
||||
|
||||
return persistentEntities.values().stream()//
|
||||
.flatMap(it -> Optionals.toStream(it))//
|
||||
.flatMap(Optionals::toStream)//
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
} finally {
|
||||
@@ -391,7 +392,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type);
|
||||
|
||||
final Map<String, PropertyDescriptor> descriptors = new HashMap<String, PropertyDescriptor>();
|
||||
final Map<String, PropertyDescriptor> descriptors = new HashMap<>();
|
||||
for (PropertyDescriptor descriptor : pds) {
|
||||
descriptors.put(descriptor.getName(), descriptor);
|
||||
}
|
||||
@@ -415,7 +416,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
// Inform listeners
|
||||
if (null != applicationEventPublisher) {
|
||||
applicationEventPublisher.publishEvent(new MappingContextEvent<E, P>(this, entity));
|
||||
applicationEventPublisher.publishEvent(new MappingContextEvent<>(this, entity));
|
||||
}
|
||||
|
||||
return Optional.of(entity);
|
||||
@@ -437,7 +438,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
try {
|
||||
|
||||
read.lock();
|
||||
return Collections.unmodifiableSet(new HashSet<TypeInformation<?>>(persistentEntities.keySet()));
|
||||
return Collections.unmodifiableSet(new HashSet<>(persistentEntities.keySet()));
|
||||
|
||||
} finally {
|
||||
read.unlock();
|
||||
@@ -478,7 +479,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
* context.
|
||||
*/
|
||||
public void initialize() {
|
||||
initialEntitySet.forEach(it -> addPersistentEntity(it));
|
||||
initialEntitySet.forEach(this::addPersistentEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -551,13 +552,13 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
}
|
||||
|
||||
entity.addPersistentProperty(property);
|
||||
property.getAssociation().ifPresent(it -> entity.addAssociation(it));
|
||||
property.getAssociation().ifPresent(entity::addAssociation);
|
||||
|
||||
if (entity.getType().equals(property.getRawType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
property.getPersistentEntityType().forEach(it -> addPersistentEntity(it));
|
||||
property.getPersistentEntityType().forEach(AbstractMappingContext.this::addPersistentEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2017 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.
|
||||
@@ -30,6 +30,7 @@ import org.springframework.util.StringUtils;
|
||||
* Abstraction of a path of {@link PersistentProperty}s.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements PersistentPropertyPath<T> {
|
||||
|
||||
@@ -77,7 +78,7 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
|
||||
Assert.notNull(property, "Property must not be null!");
|
||||
|
||||
if (isEmpty()) {
|
||||
return new DefaultPersistentPropertyPath<>(Arrays.asList(property));
|
||||
return new DefaultPersistentPropertyPath<>(Collections.singletonList(property));
|
||||
}
|
||||
|
||||
Class<?> leafPropertyType = getLeafProperty().getActualType();
|
||||
@@ -121,8 +122,8 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
|
||||
public String toPath(String delimiter, Converter<? super T, String> converter) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Converter<? super T, String> converterToUse = (Converter<? super T, String>) (converter == null
|
||||
? PropertyNameConverter.INSTANCE : converter);
|
||||
Converter<? super T, String> converterToUse = converter == null
|
||||
? PropertyNameConverter.INSTANCE : converter;
|
||||
String delimiterToUse = delimiter == null ? "." : delimiter;
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -19,6 +19,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -37,6 +38,7 @@ import org.springframework.util.Assert;
|
||||
* value of 0 in case of a version property.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class MappingContextIsNewStrategyFactory extends IsNewStrategyFactorySupport {
|
||||
|
||||
@@ -50,7 +52,7 @@ public class MappingContextIsNewStrategyFactory extends IsNewStrategyFactorySupp
|
||||
*/
|
||||
@Deprecated
|
||||
public MappingContextIsNewStrategyFactory(MappingContext<? extends PersistentEntity<?, ?>, ?> context) {
|
||||
this(new PersistentEntities(Arrays.asList(context)));
|
||||
this(new PersistentEntities(Collections.singletonList(context)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +75,7 @@ public class MappingContextIsNewStrategyFactory extends IsNewStrategyFactorySupp
|
||||
protected IsNewStrategy doGetIsNewStrategy(Class<?> type) {
|
||||
|
||||
return context.getPersistentEntity(type)//
|
||||
.flatMap(it -> foo(it))//
|
||||
.flatMap(MappingContextIsNewStrategyFactory::foo)//
|
||||
.orElseThrow(() -> new MappingException(String.format("Cannot determine IsNewStrategy for type %s!", type)));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
this.association = isAssociation() ? Optional.of(createAssociation()) : Optional.empty();
|
||||
this.owner = owner;
|
||||
this.simpleTypeHolder = simpleTypeHolder;
|
||||
this.hashCode = Lazy.of(() -> property.hashCode());
|
||||
this.hashCode = Lazy.of(property::hashCode);
|
||||
}
|
||||
|
||||
protected abstract Association<P> createAssociation();
|
||||
@@ -125,7 +125,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
}
|
||||
|
||||
TypeInformation<?> candidate = getTypeInformationIfEntityCandidate();
|
||||
return candidate != null ? Collections.singleton(candidate) : Collections.<TypeInformation<?>>emptySet();
|
||||
return candidate != null ? Collections.singleton(candidate) : Collections.emptySet();
|
||||
}
|
||||
|
||||
private TypeInformation<?> getTypeInformationIfEntityCandidate() {
|
||||
@@ -267,7 +267,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getMapValueType() {
|
||||
return isMap() ? information.getMapValueType().map(it -> it.getType()).orElse(null) : null;
|
||||
return isMap() ? information.getMapValueType().map(TypeInformation::getType).orElse(null) : null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
* @param property
|
||||
* @throws MappingException in case we find an ambiguous mapping on the accessor methods
|
||||
*/
|
||||
private final void populateAnnotationCache(Property property) {
|
||||
private void populateAnnotationCache(Property property) {
|
||||
|
||||
Optionals.toStream(property.getGetter(), property.getSetter()).forEach(it -> {
|
||||
|
||||
@@ -221,7 +221,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
return cacheAndReturn(annotationType,
|
||||
getAccessors()//
|
||||
.map(it -> it.map(inner -> AnnotatedElementUtils.findMergedAnnotation(inner, annotationType)))//
|
||||
.flatMap(it -> Optionals.toStream(it))//
|
||||
.flatMap(Optionals::toStream)//
|
||||
.findFirst());
|
||||
}
|
||||
|
||||
@@ -281,12 +281,15 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
populateAnnotationCache(getProperty());
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder().append(annotationCache.values().stream()//
|
||||
.flatMap(it -> Optionals.toStream(it))//
|
||||
String builder = annotationCache.values().stream()//
|
||||
.flatMap(Optionals::toStream)//
|
||||
.map(Object::toString)//
|
||||
.collect(Collectors.joining(" ")));
|
||||
.collect(Collectors.joining(" "));
|
||||
|
||||
return builder.toString() + super.toString();
|
||||
return builder//
|
||||
//
|
||||
//
|
||||
+ super.toString();
|
||||
}
|
||||
|
||||
private Stream<Optional<? extends AnnotatedElement>> getAccessors() {
|
||||
|
||||
@@ -109,7 +109,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
this.comparator = comparator;
|
||||
this.constructor = new PreferredConstructorDiscoverer<>(this).getConstructor();
|
||||
this.associations = comparator.<Set<Association<P>>> map(it -> new TreeSet<>(new AssociationComparator<>(it)))
|
||||
.orElseGet(() -> new HashSet<>());
|
||||
.orElseGet(HashSet::new);
|
||||
|
||||
this.propertyCache = new HashMap<>();
|
||||
this.annotationCache = new HashMap<>();
|
||||
@@ -118,7 +118,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
this.typeAlias = Lazy.of(() -> Alias
|
||||
.ofOptional(Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(getType(), TypeAlias.class))//
|
||||
.map(TypeAlias::value)//
|
||||
.filter(it -> StringUtils.hasText(it))));
|
||||
.filter(StringUtils::hasText)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -338,7 +338,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
Assert.notNull(handler, "PropertyHandler must not be null!");
|
||||
|
||||
getPersistentProperties().forEach(it -> handler.doWithPersistentProperty(it));
|
||||
getPersistentProperties().forEach(handler::doWithPersistentProperty);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -350,7 +350,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
Assert.notNull(handler, "Handler must not be null!");
|
||||
|
||||
getPersistentProperties().forEach(it -> handler.doWithPersistentProperty(it));
|
||||
getPersistentProperties().forEach(handler::doWithPersistentProperty);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -416,7 +416,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
* @see org.springframework.data.mapping.MutablePersistentEntity#verify()
|
||||
*/
|
||||
public void verify() {
|
||||
comparator.ifPresent(it -> Collections.sort(properties, it));
|
||||
comparator.ifPresent(it -> properties.sort(it));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.asm.ClassWriter;
|
||||
@@ -66,7 +67,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
public class ClassGeneratingPropertyAccessorFactory implements PersistentPropertyAccessorFactory {
|
||||
|
||||
private volatile Map<TypeInformation<?>, Class<PersistentPropertyAccessor>> propertyAccessorClasses = new HashMap<TypeInformation<?>, Class<PersistentPropertyAccessor>>(
|
||||
private volatile Map<TypeInformation<?>, Class<PersistentPropertyAccessor>> propertyAccessorClasses = new HashMap<>(
|
||||
32);
|
||||
private volatile Map<Class<PersistentPropertyAccessor>, Constructor<?>> constructorMap = new HashMap<>(32);
|
||||
|
||||
@@ -303,25 +304,15 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
private static List<PersistentProperty<?>> getPersistentProperties(PersistentEntity<?, ?> entity) {
|
||||
|
||||
final List<PersistentProperty<?>> persistentProperties = new ArrayList<PersistentProperty<?>>();
|
||||
final List<PersistentProperty<?>> persistentProperties = new ArrayList<>();
|
||||
|
||||
entity.doWithAssociations(new SimpleAssociationHandler() {
|
||||
|
||||
@Override
|
||||
public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
|
||||
if (association.getInverse() != null) {
|
||||
persistentProperties.add(association.getInverse());
|
||||
}
|
||||
entity.doWithAssociations((SimpleAssociationHandler) association -> {
|
||||
if (association.getInverse() != null) {
|
||||
persistentProperties.add(association.getInverse());
|
||||
}
|
||||
});
|
||||
|
||||
entity.doWithProperties(new SimplePropertyHandler() {
|
||||
|
||||
@Override
|
||||
public void doWithPersistentProperty(PersistentProperty<?> property) {
|
||||
persistentProperties.add(property);
|
||||
}
|
||||
});
|
||||
entity.doWithProperties((SimplePropertyHandler) property -> persistentProperties.add(property));
|
||||
|
||||
return persistentProperties;
|
||||
}
|
||||
@@ -360,15 +351,10 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
for (PersistentProperty<?> property : persistentProperties) {
|
||||
|
||||
property.getSetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> {
|
||||
cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, setterName(property),
|
||||
referenceName(JAVA_LANG_INVOKE_METHOD_HANDLE), null, null).visitEnd();
|
||||
});
|
||||
property.getGetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> {
|
||||
|
||||
cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, getterName(property),
|
||||
referenceName(JAVA_LANG_INVOKE_METHOD_HANDLE), null, null).visitEnd();
|
||||
});
|
||||
property.getSetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, setterName(property),
|
||||
referenceName(JAVA_LANG_INVOKE_METHOD_HANDLE), null, null).visitEnd());
|
||||
property.getGetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, getterName(property),
|
||||
referenceName(JAVA_LANG_INVOKE_METHOD_HANDLE), null, null).visitEnd());
|
||||
|
||||
property.getField().filter(it -> generateSetterMethodHandle(entity, it)).ifPresent(it -> {
|
||||
|
||||
@@ -497,18 +483,12 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
|
||||
if (property.usePropertyAccess()) {
|
||||
|
||||
property.getGetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> {
|
||||
visitPropertyGetterInitializer(property, mv, entityClasses, internalClassName);
|
||||
});
|
||||
property.getGetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> visitPropertyGetterInitializer(property, mv, entityClasses, internalClassName));
|
||||
|
||||
property.getSetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> {
|
||||
visitPropertySetterInitializer(property, mv, entityClasses, internalClassName);
|
||||
});
|
||||
property.getSetter().filter(it -> generateMethodHandle(entity, it)).ifPresent(it -> visitPropertySetterInitializer(property, mv, entityClasses, internalClassName));
|
||||
}
|
||||
|
||||
property.getField().filter(it -> generateSetterMethodHandle(entity, it)).ifPresent(it -> {
|
||||
visitFieldGetterSetterInitializer(property, mv, entityClasses, internalClassName);
|
||||
});
|
||||
property.getField().filter(it -> generateSetterMethodHandle(entity, it)).ifPresent(it -> visitFieldGetterSetterInitializer(property, mv, entityClasses, internalClassName));
|
||||
}
|
||||
|
||||
mv.visitLabel(l1);
|
||||
@@ -1249,7 +1229,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
|
||||
private static Map<String, PropertyStackAddress> createPropertyStackMap(
|
||||
List<PersistentProperty<?>> persistentProperties) {
|
||||
|
||||
Map<String, PropertyStackAddress> stackmap = new HashMap<String, PropertyStackAddress>();
|
||||
Map<String, PropertyStackAddress> stackmap = new HashMap<>();
|
||||
|
||||
for (PersistentProperty<?> property : persistentProperties) {
|
||||
stackmap.put(property.getName(), new PropertyStackAddress(new Label(), property.getName().hashCode()));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2017 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.
|
||||
@@ -57,6 +57,6 @@ public class IdPropertyIdentifierAccessor implements IdentifierAccessor {
|
||||
* @see org.springframework.data.keyvalue.core.IdentifierAccessor#getIdentifier()
|
||||
*/
|
||||
public Optional<Object> getIdentifier() {
|
||||
return idProperty.flatMap(it -> accessor.getProperty(it));
|
||||
return idProperty.flatMap(accessor::getProperty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2017 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.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.data.mapping.PreferredConstructor;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Jon Brisbin
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class MappingInstantiationException extends RuntimeException {
|
||||
|
||||
@@ -57,13 +58,13 @@ public class MappingInstantiationException extends RuntimeException {
|
||||
|
||||
super(buildExceptionMessage(entity, arguments.stream(), message), cause);
|
||||
|
||||
this.entityType = entity.map(it -> it.getType()).orElse(null);
|
||||
this.constructor = entity.flatMap(it -> it.getPersistenceConstructor()).map(c -> c.getConstructor()).orElse(null);
|
||||
this.entityType = entity.map(PersistentEntity::getType).orElse(null);
|
||||
this.constructor = entity.flatMap(PersistentEntity::getPersistenceConstructor).map(PreferredConstructor::getConstructor).orElse(null);
|
||||
this.constructorArguments = arguments;
|
||||
}
|
||||
|
||||
private static final String buildExceptionMessage(Optional<PersistentEntity<?, ?>> entity, Stream<Object> arguments,
|
||||
String defaultMessage) {
|
||||
private static String buildExceptionMessage(Optional<PersistentEntity<?, ?>> entity, Stream<Object> arguments,
|
||||
String defaultMessage) {
|
||||
|
||||
return entity.map(it -> {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -30,6 +30,7 @@ import org.springframework.util.Assert;
|
||||
* expression evaluation.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class PersistentEntityParameterValueProvider<P extends PersistentProperty<P>>
|
||||
implements ParameterValueProvider<P> {
|
||||
@@ -72,7 +73,7 @@ public class PersistentEntityParameterValueProvider<P extends PersistentProperty
|
||||
}
|
||||
|
||||
return provider.getPropertyValue(parameter.getName()//
|
||||
.flatMap(it -> entity.getPersistentProperty(it))//
|
||||
.flatMap(entity::getPersistentProperty)//
|
||||
.orElseThrow(() -> new MappingException(
|
||||
String.format("No property %s found on entity %s to bind constructor parameter to!", parameter.getName(),
|
||||
entity.getType()))));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 by the original author(s).
|
||||
* Copyright 2011-2017 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,6 +33,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
* Helper class to find a {@link PreferredConstructor}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class PreferredConstructorDiscoverer<T, P extends PersistentProperty<P>> {
|
||||
|
||||
@@ -104,7 +105,7 @@ public class PreferredConstructorDiscoverer<T, P extends PersistentProperty<P>>
|
||||
List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor);
|
||||
|
||||
if (parameterTypes.isEmpty()) {
|
||||
return new PreferredConstructor<T, P>((Constructor<T>) constructor);
|
||||
return new PreferredConstructor<>((Constructor<T>) constructor);
|
||||
}
|
||||
|
||||
String[] parameterNames = discoverer.getParameterNames(constructor);
|
||||
@@ -121,7 +122,7 @@ public class PreferredConstructorDiscoverer<T, P extends PersistentProperty<P>>
|
||||
parameters[i] = new Parameter(name, type, annotations, entity);
|
||||
}
|
||||
|
||||
return new PreferredConstructor<T, P>((Constructor<T>) constructor, parameters);
|
||||
return new PreferredConstructor<>((Constructor<T>) constructor, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.mapping.model;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -28,6 +29,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class Property {
|
||||
@@ -42,10 +44,10 @@ public class Property {
|
||||
|
||||
this.field = field;
|
||||
this.descriptor = descriptor;
|
||||
this.hashCode = Lazy.of(() -> computeHashCode());
|
||||
this.hashCode = Lazy.of(this::computeHashCode);
|
||||
this.rawType = Lazy
|
||||
.of(() -> field.<Class<?>>map(Field::getType).orElseGet(() -> descriptor.map(it -> it.getPropertyType())//
|
||||
.orElseThrow(() -> new IllegalStateException())));
|
||||
.of(() -> field.<Class<?>>map(Field::getType).orElseGet(() -> descriptor.map(PropertyDescriptor::getPropertyType)//
|
||||
.orElseThrow(IllegalStateException::new)));
|
||||
}
|
||||
|
||||
public static Property of(Field field) {
|
||||
@@ -70,12 +72,12 @@ public class Property {
|
||||
}
|
||||
|
||||
public Optional<Method> getGetter() {
|
||||
return descriptor.map(it -> it.getReadMethod())//
|
||||
return descriptor.map(PropertyDescriptor::getReadMethod)//
|
||||
.filter(it -> getType().isAssignableFrom(it.getReturnType()));
|
||||
}
|
||||
|
||||
public Optional<Method> getSetter() {
|
||||
return descriptor.map(it -> it.getWriteMethod())//
|
||||
return descriptor.map(PropertyDescriptor::getWriteMethod)//
|
||||
.filter(it -> it.getParameterTypes()[0].isAssignableFrom(getType()));
|
||||
}
|
||||
|
||||
@@ -87,8 +89,8 @@ public class Property {
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return field.map(Field::getName).orElseGet(() -> descriptor.map(it -> it.getName())//
|
||||
.orElseThrow(() -> new IllegalStateException()));
|
||||
return field.map(Field::getName).orElseGet(() -> descriptor.map(FeatureDescriptor::getName)//
|
||||
.orElseThrow(IllegalStateException::new));
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
@@ -97,8 +99,8 @@ public class Property {
|
||||
|
||||
private int computeHashCode() {
|
||||
|
||||
return this.field.map(it -> it.hashCode())
|
||||
.orElseGet(() -> this.descriptor.map(it -> it.hashCode()).orElseThrow(() -> new IllegalStateException()));
|
||||
return this.field.map(Field::hashCode)
|
||||
.orElseGet(() -> this.descriptor.map(PropertyDescriptor::hashCode).orElseThrow(IllegalStateException::new));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -137,6 +139,6 @@ public class Property {
|
||||
@Override
|
||||
public String toString() {
|
||||
return field.map(Object::toString)
|
||||
.orElseGet(() -> descriptor.map(Object::toString).orElseThrow(() -> new IllegalStateException()));
|
||||
.orElseGet(() -> descriptor.map(Object::toString).orElseThrow(IllegalStateException::new));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 by the original author(s).
|
||||
* Copyright 2011-2017 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,10 +28,11 @@ import org.springframework.util.Assert;
|
||||
* Simple container to hold a set of types to be considered simple types.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class SimpleTypeHolder {
|
||||
|
||||
private static final Set<Class<?>> DEFAULTS = new HashSet<Class<?>>();
|
||||
private static final Set<Class<?>> DEFAULTS = new HashSet<>();
|
||||
|
||||
static {
|
||||
DEFAULTS.add(boolean.class);
|
||||
@@ -74,7 +75,7 @@ public class SimpleTypeHolder {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public SimpleTypeHolder() {
|
||||
this(Collections.EMPTY_SET, true);
|
||||
this(Collections.emptySet(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,7 @@ public class SimpleTypeHolder {
|
||||
public SimpleTypeHolder(Set<? extends Class<?>> customSimpleTypes, boolean registerDefaults) {
|
||||
|
||||
Assert.notNull(customSimpleTypes, "CustomSimpleTypes must not be null!");
|
||||
this.simpleTypes = new CopyOnWriteArraySet<Class<?>>(customSimpleTypes);
|
||||
this.simpleTypes = new CopyOnWriteArraySet<>(customSimpleTypes);
|
||||
|
||||
if (registerDefaults) {
|
||||
this.simpleTypes.addAll(DEFAULTS);
|
||||
@@ -105,7 +106,7 @@ public class SimpleTypeHolder {
|
||||
Assert.notNull(customSimpleTypes, "CustomSimpleTypes must not be null!");
|
||||
Assert.notNull(source, "SourceTypeHolder must not be null!");
|
||||
|
||||
this.simpleTypes = new CopyOnWriteArraySet<Class<?>>(customSimpleTypes);
|
||||
this.simpleTypes = new CopyOnWriteArraySet<>(customSimpleTypes);
|
||||
this.simpleTypes.addAll(source.simpleTypes);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user