DATACMNS-1755 - Use method references in favor of lambdas.
Simplify several lambda expressions in the codebase by using method references. Original pull request: #448.
This commit is contained in:
committed by
Mark Paluch
parent
cb8443e299
commit
b42cdb6568
@@ -195,8 +195,8 @@ public class AuditingHandler implements InitializingBean {
|
||||
Assert.notNull(auditor,
|
||||
() -> String.format("Auditor must not be null! Returned by: %s!", AopUtils.getTargetClass(it)));
|
||||
|
||||
auditor.filter(__ -> isNew).ifPresent(foo -> wrapper.setCreatedBy(foo));
|
||||
auditor.filter(__ -> !isNew || modifyOnCreation).ifPresent(foo -> wrapper.setLastModifiedBy(foo));
|
||||
auditor.filter(__ -> isNew).ifPresent(wrapper::setCreatedBy);
|
||||
auditor.filter(__ -> !isNew || modifyOnCreation).ifPresent(wrapper::setLastModifiedBy);
|
||||
|
||||
return auditor;
|
||||
});
|
||||
@@ -216,8 +216,8 @@ public class AuditingHandler implements InitializingBean {
|
||||
|
||||
Assert.notNull(now, () -> String.format("Now must not be null! Returned by: %s!", dateTimeProvider.getClass()));
|
||||
|
||||
now.filter(__ -> isNew).ifPresent(it -> wrapper.setCreatedDate(it));
|
||||
now.filter(__ -> !isNew || modifyOnCreation).ifPresent(it -> wrapper.setLastModifiedDate(it));
|
||||
now.filter(__ -> isNew).ifPresent(wrapper::setCreatedDate);
|
||||
now.filter(__ -> !isNew || modifyOnCreation).ifPresent(wrapper::setLastModifiedDate);
|
||||
|
||||
return now;
|
||||
}
|
||||
|
||||
@@ -198,9 +198,9 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
|
||||
|
||||
Collection<PersistentEntity<?, ?>> entities = contexts.stream() //
|
||||
.flatMap(it -> it.getPersistentEntities().stream()) //
|
||||
.map(it -> it.getIdProperty()) //
|
||||
.map(PersistentEntity::getIdProperty) //
|
||||
.filter(it -> it != null && type.equals(it.getTypeInformation().getActualType())) //
|
||||
.map(it -> it.getOwner()) //
|
||||
.map(PersistentProperty::getOwner) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (entities.size() > 1) {
|
||||
|
||||
@@ -47,7 +47,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends PersistentProperty<P>> {
|
||||
|
||||
private static final Predicate<PersistentProperty<? extends PersistentProperty<?>>> IS_ENTITY = it -> it.isEntity();
|
||||
private static final Predicate<PersistentProperty<? extends PersistentProperty<?>>> IS_ENTITY = PersistentProperty::isEntity;
|
||||
|
||||
private final Map<TypeAndPath, PersistentPropertyPath<P>> propertyPaths = new ConcurrentReferenceHashMap<>();
|
||||
private final MappingContext<E, P> context;
|
||||
|
||||
@@ -310,7 +310,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
}
|
||||
|
||||
String builder = annotationCache.values().stream() //
|
||||
.flatMap(it -> Optionals.toStream(it)) //
|
||||
.flatMap(Optionals::toStream) //
|
||||
.map(Object::toString) //
|
||||
.collect(Collectors.joining(" "));
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public class MappingInstantiationException extends RuntimeException {
|
||||
}
|
||||
|
||||
return String.format(TEXT_TEMPLATE, it.getType().getName(),
|
||||
constructor.map(c -> toString(c)).orElse("NO_CONSTRUCTOR"), //
|
||||
constructor.map(MappingInstantiationException::toString).orElse("NO_CONSTRUCTOR"), //
|
||||
String.join(",", toStringArgs));
|
||||
|
||||
}).orElse(defaultMessage);
|
||||
|
||||
@@ -176,8 +176,8 @@ public class DefaultCrudMethods implements CrudMethods {
|
||||
private static Optional<Method> getMostSpecificMethod(Method method, Class<?> type) {
|
||||
|
||||
return Optionals.toStream(Optional.ofNullable(ClassUtils.getMostSpecificMethod(method, type)))//
|
||||
.map(it -> BridgeMethodResolver.findBridgedMethod(it))//
|
||||
.peek(it -> ReflectionUtils.makeAccessible(it))//
|
||||
.map(BridgeMethodResolver::findBridgedMethod)//
|
||||
.peek(ReflectionUtils::makeAccessible)//
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.repository.query;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.data.repository.query.SpelQueryContext.SpelExtractor;
|
||||
@@ -62,7 +63,7 @@ public class SpelEvaluator {
|
||||
EvaluationContext evaluationContext = evaluationContextProvider.getEvaluationContext(parameters, values);
|
||||
|
||||
return extractor.getParameters().collect(Collectors.toMap(//
|
||||
it -> it.getKey(), //
|
||||
Entry::getKey, //
|
||||
it -> getSpElValue(evaluationContext, it.getValue()) //
|
||||
));
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ class EvaluationContextExtensionInformation {
|
||||
* @return the methods
|
||||
*/
|
||||
public MultiValueMap<String, Function> getFunctions(Optional<Object> target) {
|
||||
return target.map(this::getFunctions).orElseGet(() -> new LinkedMultiValueMap<>());
|
||||
return target.map(this::getFunctions).orElseGet(LinkedMultiValueMap::new);
|
||||
}
|
||||
|
||||
private MultiValueMap<String, Function> getFunctions(Object target) {
|
||||
|
||||
@@ -94,7 +94,7 @@ public class PagedResourcesAssembler<T> implements RepresentationModelAssembler<
|
||||
@Override
|
||||
@SuppressWarnings("null")
|
||||
public PagedModel<EntityModel<T>> toModel(Page<T> entity) {
|
||||
return toModel(entity, it -> EntityModel.of(it));
|
||||
return toModel(entity, EntityModel::of);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ public class PagedResourcesAssembler<T> implements RepresentationModelAssembler<
|
||||
* @return
|
||||
*/
|
||||
public PagedModel<EntityModel<T>> toModel(Page<T> page, Link selfLink) {
|
||||
return toModel(page, it -> EntityModel.of(it), selfLink);
|
||||
return toModel(page, EntityModel::of, selfLink);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +230,7 @@ public class PagedResourcesAssembler<T> implements RepresentationModelAssembler<
|
||||
resources.add(createLink(base, page.previousPageable(), IanaLinkRelations.PREV));
|
||||
}
|
||||
|
||||
Link selfLink = link.map(it -> it.withSelfRel())//
|
||||
Link selfLink = link.map(Link::withSelfRel)//
|
||||
.orElseGet(() -> createLink(base, page.getPageable(), IanaLinkRelations.SELF));
|
||||
|
||||
resources.add(selfLink);
|
||||
|
||||
@@ -169,7 +169,7 @@ public class SpringDataWebConfiguration implements WebMvcConfigurer, BeanClassLo
|
||||
if (ClassUtils.isPresent("org.xmlbeam.XBProjector", context.getClassLoader())) {
|
||||
|
||||
converters.add(0, context.getBeanProvider(XmlBeamHttpMessageConverter.class) //
|
||||
.getIfAvailable(() -> new XmlBeamHttpMessageConverter()));
|
||||
.getIfAvailable(XmlBeamHttpMessageConverter::new));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user