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:
Christoph Strobl
2017-02-15 12:06:09 +01:00
committed by Oliver Gierke
parent aa4c51e1ea
commit be347eaaab
176 changed files with 673 additions and 797 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-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.
@@ -48,13 +48,14 @@ import org.springframework.util.ClassUtils;
* @author Thomas Darimont
* @author Oliver Gierke
* @author Phillip Webb
* @author Christoph Strobl
* @since 1.11
*/
public class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private final ObjectInstantiatorClassGenerator generator;
private volatile Map<TypeInformation<?>, EntityInstantiator> entityInstantiators = new HashMap<TypeInformation<?>, EntityInstantiator>(
private volatile Map<TypeInformation<?>, EntityInstantiator> entityInstantiators = new HashMap<>(
32);
/**
@@ -97,7 +98,7 @@ public class ClassGeneratingEntityInstantiator implements EntityInstantiator {
instantiator = createEntityInstantiator(entity);
map = new HashMap<TypeInformation<?>, EntityInstantiator>(map);
map = new HashMap<>(map);
map.put(entity.getTypeInformation(), instantiator);
this.entityInstantiators = map;
@@ -217,7 +218,7 @@ public class ClassGeneratingEntityInstantiator implements EntityInstantiator {
}
return it.getParameters().stream()//
.map(parameter -> provider.getParameterValue(parameter))//
.map(provider::getParameterValue)//
.toArray();
}).orElse(EMPTY_ARRAY);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 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.
@@ -32,13 +32,11 @@ import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
/**
* Default implementation of {@link MongoTypeMapper} allowing configuration of the key to lookup and store type
* information in {@link DBObject}. The key defaults to {@link #DEFAULT_TYPE_KEY}. Actual type-to-{@link String}
* conversion and back is done in {@link #getTypeString(TypeInformation)} or {@link #getTypeInformation(String)}
* respectively.
* Default implementation of {@link TypeMapper}.
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class DefaultTypeMapper<S> implements TypeMapper<S> {
@@ -53,7 +51,7 @@ public class DefaultTypeMapper<S> implements TypeMapper<S> {
* @param accessor must not be {@literal null}.
*/
public DefaultTypeMapper(TypeAliasAccessor<S> accessor) {
this(accessor, Arrays.asList(new SimpleTypeInformationMapper()));
this(accessor, Collections.singletonList(new SimpleTypeInformationMapper()));
}
/**
@@ -151,7 +149,7 @@ public class DefaultTypeMapper<S> implements TypeMapper<S> {
return readType(source)//
.map(it -> readType(source))//
.orElseGet(() -> getFallbackTypeFor(source))//
.map(it -> it.getType());
.map(TypeInformation::getType);
}
/**

View File

@@ -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.
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class EntityInstantiators {
@@ -37,7 +38,7 @@ public class EntityInstantiators {
* Creates a new {@link EntityInstantiators} using the default fallback instantiator and no custom ones.
*/
public EntityInstantiators() {
this(Collections.<Class<?>, EntityInstantiator> emptyMap());
this(Collections.emptyMap());
}
/**
@@ -46,7 +47,7 @@ public class EntityInstantiators {
* @param fallback must not be {@literal null}.
*/
public EntityInstantiators(EntityInstantiator fallback) {
this(fallback, Collections.<Class<?>, EntityInstantiator> emptyMap());
this(fallback, Collections.emptyMap());
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -33,6 +33,7 @@ import org.springframework.util.ClassUtils;
* classpath.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
@SuppressWarnings("deprecation")
public abstract class JodaTimeConverters {
@@ -50,7 +51,7 @@ public abstract class JodaTimeConverters {
return Collections.emptySet();
}
List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(LocalDateToDateConverter.INSTANCE);
converters.add(LocalDateTimeToDateConverter.INSTANCE);
converters.add(DateTimeToDateConverter.INSTANCE);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-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.ClassUtils;
*
* @author Oliver Gierke
* @author Barak Schoster
* @author Christoph Strobl
*/
public abstract class Jsr310Converters {
@@ -58,7 +59,7 @@ public abstract class Jsr310Converters {
return Collections.emptySet();
}
List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(DateToLocalDateTimeConverter.INSTANCE);
converters.add(LocalDateTimeToDateConverter.INSTANCE);
converters.add(DateToLocalDateConverter.INSTANCE);

View File

@@ -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.
@@ -33,6 +33,7 @@ import org.springframework.util.Assert;
* inspecting the {@link PersistentEntity} instances for type alias information.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public class MappingContextTypeInformationMapper implements TypeInformationMapper {
@@ -63,9 +64,7 @@ public class MappingContextTypeInformationMapper implements TypeInformationMappe
*/
public Alias createAliasFor(TypeInformation<?> type) {
return typeMap.computeIfAbsent(type.getRawTypeInformation(), key -> {
return verify(key, mappingContext.getPersistentEntity(key).map(it -> it.getTypeAlias()).orElse(Alias.NONE));
});
return typeMap.computeIfAbsent(type.getRawTypeInformation(), key -> verify(key, mappingContext.getPersistentEntity(key).map(PersistentEntity::getTypeAlias).orElse(Alias.NONE)));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 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.
@@ -35,6 +35,7 @@ import org.springframework.data.mapping.model.ParameterValueProvider;
* instance of the entity via reflection.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public enum ReflectionEntityInstantiator implements EntityInstantiator {
@@ -50,7 +51,7 @@ public enum ReflectionEntityInstantiator implements EntityInstantiator {
.map(it -> constructor.getParameters().stream()//
.map(parameter -> it.getParameterValue(parameter).orElse(Optional.empty()))//
.collect(Collectors.toList()))//
.orElseGet(() -> Collections.emptyList());
.orElseGet(Collections::emptyList);
List<Object> foo = new ArrayList<>(params.size());

View File

@@ -40,6 +40,7 @@ import org.threeten.bp.ZoneId;
* the classpath.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @see <a href="http://www.threeten.org/threetenbp">http://www.threeten.org/threetenbp</a>
* @since 1.10
*/
@@ -59,7 +60,7 @@ public abstract class ThreeTenBackPortConverters {
return Collections.emptySet();
}
List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(DateToLocalDateTimeConverter.INSTANCE);
converters.add(LocalDateTimeToDateConverter.INSTANCE);
converters.add(DateToLocalDateConverter.INSTANCE);