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 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.
|
||||
@@ -41,6 +41,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Ranie Jade Ramiso
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.5
|
||||
*/
|
||||
final class AnnotationAuditingMetadata {
|
||||
@@ -51,7 +52,7 @@ final class AnnotationAuditingMetadata {
|
||||
private static final AnnotationFieldFilter LAST_MODIFIED_DATE_FILTER = new AnnotationFieldFilter(
|
||||
LastModifiedDate.class);
|
||||
|
||||
private static final Map<Class<?>, AnnotationAuditingMetadata> METADATA_CACHE = new ConcurrentHashMap<Class<?>, AnnotationAuditingMetadata>();
|
||||
private static final Map<Class<?>, AnnotationAuditingMetadata> METADATA_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
public static final boolean IS_JDK_8 = org.springframework.util.ClassUtils.isPresent("java.time.Clock",
|
||||
AnnotationAuditingMetadata.class.getClassLoader());
|
||||
@@ -124,7 +125,7 @@ final class AnnotationAuditingMetadata {
|
||||
* @param type the type to inspect, must not be {@literal null}.
|
||||
*/
|
||||
public static AnnotationAuditingMetadata getMetadata(Class<?> type) {
|
||||
return METADATA_CACHE.computeIfAbsent(type, it -> new AnnotationAuditingMetadata(it));
|
||||
return METADATA_CACHE.computeIfAbsent(type, AnnotationAuditingMetadata::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.auditing;
|
||||
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.util.Assert;
|
||||
* Auditing handler to mark entity objects created and modified.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.5
|
||||
*/
|
||||
public class AuditingHandler implements InitializingBean {
|
||||
@@ -59,7 +61,7 @@ public class AuditingHandler implements InitializingBean {
|
||||
@Deprecated
|
||||
public AuditingHandler(
|
||||
MappingContext<? extends PersistentEntity<?, ?>, ? extends PersistentProperty<?>> mappingContext) {
|
||||
this(new PersistentEntities(Arrays.asList(mappingContext)));
|
||||
this(new PersistentEntities(Collections.singletonList(mappingContext)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -162,9 +162,9 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
|
||||
|
||||
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
|
||||
|
||||
JodaTimeConverters.getConvertersToRegister().forEach(it -> conversionService.addConverter(it));
|
||||
Jsr310Converters.getConvertersToRegister().forEach(it -> conversionService.addConverter(it));
|
||||
ThreeTenBackPortConverters.getConvertersToRegister().forEach(it -> conversionService.addConverter(it));
|
||||
JodaTimeConverters.getConvertersToRegister().forEach(conversionService::addConverter);
|
||||
Jsr310Converters.getConvertersToRegister().forEach(conversionService::addConverter);
|
||||
ThreeTenBackPortConverters.getConvertersToRegister().forEach(conversionService::addConverter);
|
||||
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
@@ -214,9 +214,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> Optional<T> getAsTemporalAccessor(Optional<?> source, Class<T> target) {
|
||||
|
||||
return source.map(it -> {
|
||||
return target.isInstance(it) ? (T) it : conversionService.convert(it, target);
|
||||
});
|
||||
return source.map(it -> target.isInstance(it) ? (T) it : conversionService.convert(it, target));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,10 +300,8 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
|
||||
*/
|
||||
private Optional<? extends Object> setField(Optional<Field> field, Optional<? extends Object> value) {
|
||||
|
||||
field.ifPresent(it -> {
|
||||
ReflectionUtils.setField(it, target,
|
||||
Optional.class.isAssignableFrom(it.getType()) ? value : value.orElse(null));
|
||||
});
|
||||
field.ifPresent(it -> ReflectionUtils.setField(it, target,
|
||||
Optional.class.isAssignableFrom(it.getType()) ? value : value.orElse(null)));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.auditing;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.util.Assert;
|
||||
* {@link #markModified(Optional)} based on the {@link IsNewStrategy} determined from the factory.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.5
|
||||
*/
|
||||
public class IsNewAwareAuditingHandler extends AuditingHandler {
|
||||
@@ -49,7 +51,7 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
|
||||
@Deprecated
|
||||
public IsNewAwareAuditingHandler(
|
||||
MappingContext<? extends PersistentEntity<?, ?>, ? extends PersistentProperty<?>> mappingContext) {
|
||||
this(new PersistentEntities(Arrays.asList(mappingContext)));
|
||||
this(new PersistentEntities(Collections.singletonList(mappingContext)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 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.
|
||||
@@ -39,6 +39,7 @@ import org.springframework.util.Assert;
|
||||
* values.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.8
|
||||
*/
|
||||
public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrapperFactory {
|
||||
@@ -56,7 +57,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
Assert.notNull(entities, "PersistentEntities must not be null!");
|
||||
|
||||
this.entities = entities;
|
||||
this.metadataCache = new HashMap<Class<?>, MappingAuditingMetadata>();
|
||||
this.metadataCache = new HashMap<>();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -159,9 +160,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
@Override
|
||||
public Optional<? extends Object> setCreatedBy(Optional<? extends Object> value) {
|
||||
|
||||
metadata.createdByProperty.ifPresent(it -> {
|
||||
this.accessor.setProperty(it, value);
|
||||
});
|
||||
metadata.createdByProperty.ifPresent(it -> this.accessor.setProperty(it, value));
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -173,9 +172,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
@Override
|
||||
public Optional<TemporalAccessor> setCreatedDate(Optional<TemporalAccessor> value) {
|
||||
|
||||
metadata.createdDateProperty.ifPresent(it -> {
|
||||
this.accessor.setProperty(it, getDateValueToSet(value, it.getType(), it));
|
||||
});
|
||||
metadata.createdDateProperty.ifPresent(it -> this.accessor.setProperty(it, getDateValueToSet(value, it.getType(), it)));
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -187,9 +184,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
@Override
|
||||
public Optional<? extends Object> setLastModifiedBy(Optional<? extends Object> value) {
|
||||
|
||||
metadata.lastModifiedByProperty.ifPresent(it -> {
|
||||
this.accessor.setProperty(it, value);
|
||||
});
|
||||
metadata.lastModifiedByProperty.ifPresent(it -> this.accessor.setProperty(it, value));
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -200,7 +195,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
*/
|
||||
@Override
|
||||
public Optional<TemporalAccessor> getLastModifiedDate() {
|
||||
return getAsTemporalAccessor(metadata.lastModifiedDateProperty.map(it -> accessor.getProperty(it)),
|
||||
return getAsTemporalAccessor(metadata.lastModifiedDateProperty.map(accessor::getProperty),
|
||||
TemporalAccessor.class);
|
||||
}
|
||||
|
||||
@@ -211,9 +206,7 @@ public class MappingAuditableBeanWrapperFactory extends DefaultAuditableBeanWrap
|
||||
@Override
|
||||
public Optional<TemporalAccessor> setLastModifiedDate(Optional<TemporalAccessor> value) {
|
||||
|
||||
metadata.lastModifiedDateProperty.ifPresent(it -> {
|
||||
this.accessor.setProperty(it, getDateValueToSet(value, it.getType(), it));
|
||||
});
|
||||
metadata.lastModifiedDateProperty.ifPresent(it -> this.accessor.setProperty(it, getDateValueToSet(value, it.getType(), it)));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user