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 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);
}
/**

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.
@@ -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)));
}
/**

View File

@@ -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;
}

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.
@@ -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)));
}
/**

View File

@@ -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;
}

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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 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.
@@ -26,6 +26,7 @@ import org.springframework.core.convert.ConversionService;
*
* @author Thomas Risberg
* @author Rod Johnson
* @author Christoph Strobl
*/
public class HashMapChangeSet implements ChangeSet {
@@ -36,7 +37,7 @@ public class HashMapChangeSet implements ChangeSet {
}
public HashMapChangeSet() {
this(new HashMap<String, Object>());
this(new HashMap<>());
}
public void set(String key, Object o) {

View File

@@ -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.
@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
* here, rather build your own base class and use the annotations directly.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.13
*/
public class AbstractAggregateRoot {
@@ -37,7 +38,7 @@ public class AbstractAggregateRoot {
* All domain events currently captured by the aggregate.
*/
@Getter(onMethod = @__(@DomainEvents)) //
private transient final List<Object> domainEvents = new ArrayList<Object>();
private transient final List<Object> domainEvents = new ArrayList<>();
/**
* Registers the given event object for publication on a call to a Spring Data repository's save method.

View File

@@ -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.
@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
* A chunk of data restricted by the configured {@link Pageable}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.8
*/
abstract class Chunk<T> implements Slice<T>, Serializable {
@@ -159,7 +160,7 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
Assert.notNull(converter, "Converter must not be null!");
return this.stream().map(it -> converter.convert(it)).collect(Collectors.toList());
return this.stream().map(converter::convert).collect(Collectors.toList());
}
/*

View File

@@ -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.
@@ -62,7 +62,7 @@ public class ExampleMatcher {
@Wither(AccessLevel.PRIVATE) MatchMode mode;
private ExampleMatcher() {
this(NullHandler.IGNORE, StringMatcher.DEFAULT, new PropertySpecifiers(), Collections.<String>emptySet(), false,
this(NullHandler.IGNORE, StringMatcher.DEFAULT, new PropertySpecifiers(), Collections.emptySet(), false,
MatchMode.ALL);
}
@@ -807,7 +807,7 @@ public class ExampleMatcher {
@EqualsAndHashCode
public static class PropertySpecifiers {
private final Map<String, PropertySpecifier> propertySpecifiers = new LinkedHashMap<String, PropertySpecifier>();
private final Map<String, PropertySpecifier> propertySpecifiers = new LinkedHashMap<>();
PropertySpecifiers() {}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 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.
@@ -29,6 +29,7 @@ import org.springframework.data.domain.jaxb.SpringDataJaxb.SortDto;
* {@link XmlAdapter} to convert {@link Pageable} instances int a {@link PageRequestDto} and vice versa.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
class PageableAdapter extends XmlAdapter<PageRequestDto, Pageable> {
@@ -42,7 +43,7 @@ class PageableAdapter extends XmlAdapter<PageRequestDto, Pageable> {
SortDto sortDto = SortAdapter.INSTANCE.marshal(request.getSort());
PageRequestDto dto = new PageRequestDto();
dto.orders = sortDto == null ? Collections.<OrderDto>emptyList() : sortDto.orders;
dto.orders = sortDto == null ? Collections.emptyList() : sortDto.orders;
dto.page = request.getPageNumber();
dto.size = request.getPageSize();

View File

@@ -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.
@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
* {@value #SUPPORTED_METRICS}.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public enum DistanceFormatter implements Converter<String, Distance>, Formatter<Distance> {
@@ -45,7 +46,7 @@ public enum DistanceFormatter implements Converter<String, Distance>, Formatter<
static {
Map<String, Metric> metrics = new LinkedHashMap<String, Metric>();
Map<String, Metric> metrics = new LinkedHashMap<>();
for (Metric metric : Metrics.values()) {
metrics.put(metric.getAbbreviation(), metric);

View File

@@ -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.
@@ -28,6 +28,7 @@ import java.util.Optional;
*
* @author Oliver Gierke
* @author Philipp Huegelmeyer
* @author Christoph Strobl
*/
@Value
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@@ -51,7 +52,7 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
* @return
*/
public static <N extends Number & Comparable<N>, T> Revision<N, T> of(RevisionMetadata<N> metadata, T entity) {
return new Revision<N, T>(metadata, entity);
return new Revision<>(metadata, entity);
}
/**
@@ -81,9 +82,7 @@ public final class Revision<N extends Number & Comparable<N>, T> implements Comp
Optional<N> thisRevisionNumber = getRevisionNumber();
Optional<N> thatRevisionNumber = that.getRevisionNumber();
return thisRevisionNumber.map(left -> {
return thatRevisionNumber.map(right -> left.compareTo(right)).orElse(1);
}).orElse(-1);
return thisRevisionNumber.map(left -> thatRevisionNumber.map(left::compareTo).orElse(1)).orElse(-1);
}
/*

View File

@@ -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.
@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
* Allows iterating over the underlying {@link Revisions} starting with older revisions.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public class Revisions<N extends Number & Comparable<N>, T> implements Iterable<Revision<N, T>> {
@@ -64,7 +65,7 @@ public class Revisions<N extends Number & Comparable<N>, T> implements Iterable<
}
public static <N extends Number & Comparable<N>, T> Revisions<N, T> of(List<? extends Revision<N, T>> revisions) {
return new Revisions<N, T>(revisions);
return new Revisions<>(revisions);
}
/**
@@ -83,7 +84,7 @@ public class Revisions<N extends Number & Comparable<N>, T> implements Iterable<
* @return
*/
public Revisions<N, T> reverse() {
return new Revisions<N, T>(revisions, !latestLast);
return new Revisions<>(revisions, !latestLast);
}
/*

View File

@@ -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() {

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.
@@ -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() {

View File

@@ -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());
}
/**

View File

@@ -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);
}
}

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.
@@ -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<>();

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.
@@ -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)));
}

View File

@@ -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;
}
/*

View File

@@ -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() {

View File

@@ -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));
}
/*

View File

@@ -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()));

View File

@@ -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);
}
}

View File

@@ -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 -> {

View File

@@ -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()))));

View File

@@ -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);
}
/**

View File

@@ -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));
}
}

View File

@@ -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);
}

View File

@@ -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.
@@ -25,6 +25,7 @@ import org.springframework.util.Assert;
* Helper value to abstract an accessor.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @soundtrack Benny Greb - Soulfood (Live)
* @since 1.13
*/
@@ -46,7 +47,7 @@ public final class Accessor {
this.descriptor = BeanUtils.findPropertyForMethod(method);
this.method = method;
Assert.notNull(descriptor, String.format("Invoked method %s is no accessor method!", method));
Assert.notNull(descriptor, () -> String.format("Invoked method %s is no accessor method!", method));
}
/**

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.
@@ -20,11 +20,9 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.data.util.ReflectionUtils;
import org.springframework.util.Assert;
/**
@@ -32,6 +30,7 @@ import org.springframework.util.Assert;
* properties.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.12
*/
class DefaultProjectionInformation implements ProjectionInformation {
@@ -102,7 +101,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
*/
private static List<PropertyDescriptor> collectDescriptors(Class<?> type) {
List<PropertyDescriptor> result = new ArrayList<PropertyDescriptor>();
List<PropertyDescriptor> result = new ArrayList<>();
result.addAll(Arrays.stream(BeanUtils.getPropertyDescriptors(type))//
.filter(it -> !hasDefaultGetter(it))//
.collect(Collectors.toList()));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 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.ClassUtils;
* types.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @see SpelAwareProxyProjectionFactory
* @since 1.10
*/
@@ -55,7 +56,7 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware,
*/
protected ProxyProjectionFactory() {
this.factories = new ArrayList<MethodInterceptorFactory>();
this.factories = new ArrayList<>();
this.factories.add(MapAccessingMethodInterceptorFactory.INSTANCE);
this.factories.add(PropertyAccessingMethodInvokerFactory.INSTANCE);
}

View File

@@ -41,7 +41,7 @@ import org.springframework.util.ReflectionUtils;
*/
public class SpelAwareProxyProjectionFactory extends ProxyProjectionFactory implements BeanFactoryAware {
private final Map<Class<?>, Boolean> typeCache = new HashMap<Class<?>, Boolean>();
private final Map<Class<?>, Boolean> typeCache = new HashMap<>();
private final SpelExpressionParser parser = new SpelExpressionParser();
private BeanFactory beanFactory;

View File

@@ -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.
@@ -41,6 +41,7 @@ import org.springframework.util.StringUtils;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
* @see 1.10
*/
class SpelEvaluatingMethodInterceptor implements MethodInterceptor {
@@ -98,7 +99,7 @@ class SpelEvaluatingMethodInterceptor implements MethodInterceptor {
private static Map<Integer, Expression> potentiallyCreateExpressionsForMethodsOnTargetInterface(
SpelExpressionParser parser, Class<?> targetInterface) {
Map<Integer, Expression> expressions = new HashMap<Integer, Expression>();
Map<Integer, Expression> expressions = new HashMap<>();
for (Method method : targetInterface.getMethods()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 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.
@@ -131,7 +131,7 @@ public class QSort extends Sort implements Serializable {
Assert.notEmpty(orderSpecifiers, "OrderSpecifiers must not be null or empty!");
List<OrderSpecifier<?>> newOrderSpecifiers = new ArrayList<OrderSpecifier<?>>(this.orderSpecifiers);
List<OrderSpecifier<?>> newOrderSpecifiers = new ArrayList<>(this.orderSpecifiers);
newOrderSpecifiers.addAll(orderSpecifiers);
return new QSort(newOrderSpecifiers);

View File

@@ -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.
@@ -37,6 +37,7 @@ import com.querydsl.core.types.dsl.CollectionPathBase;
* {@link PropertyPath} based implementation of {@link PathInformation}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.13
*/
@ToString
@@ -125,9 +126,9 @@ class PropertyPathInformation implements PathInformation {
private static Path<?> reifyPath(EntityPathResolver resolver, PropertyPath path, Optional<Path<?>> base) {
Optional<Path<?>> map = base.filter(it -> it instanceof CollectionPathBase)
.map(it -> CollectionPathBase.class.cast(it))//
.map(CollectionPathBase.class::cast)//
.map(CollectionPathBase::any)//
.map(it -> Path.class.cast(it))//
.map(Path.class::cast)//
.map(it -> reifyPath(resolver, path, Optional.of(it)));
return map.orElseGet(() -> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 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.
@@ -79,8 +79,8 @@ public class QuerydslBindings {
*/
public QuerydslBindings() {
this.pathSpecs = new LinkedHashMap<String, PathAndBinding<?, ?>>();
this.typeSpecs = new LinkedHashMap<Class<?>, PathAndBinding<?, ?>>();
this.pathSpecs = new LinkedHashMap<>();
this.typeSpecs = new LinkedHashMap<>();
this.whiteList = new HashSet<>();
this.blackList = new HashSet<>();
this.aliases = new HashSet<>();
@@ -94,7 +94,7 @@ public class QuerydslBindings {
* @return
*/
public final <T extends Path<S>, S> AliasingPathBinder<T, S> bind(T path) {
return new AliasingPathBinder<T, S>(path);
return new AliasingPathBinder<>(path);
}
/**
@@ -105,7 +105,7 @@ public class QuerydslBindings {
*/
@SafeVarargs
public final <T extends Path<S>, S> PathBinder<T, S> bind(T... paths) {
return new PathBinder<T, S>(paths);
return new PathBinder<>(paths);
}
/**
@@ -231,7 +231,7 @@ public class QuerydslBindings {
Assert.notNull(path, "PropertyPath must not be null!");
return Optional.ofNullable(pathSpecs.get(path.toDotPath())).flatMap(it -> it.getPath());
return Optional.ofNullable(pathSpecs.get(path.toDotPath())).flatMap(PathAndBinding::getPath);
}
/**
@@ -252,7 +252,7 @@ public class QuerydslBindings {
if (pathSpecs.containsKey(path)) {
return pathSpecs.get(path).getPath()//
.map(it -> QuerydslPathInformation.of(it))//
.map(QuerydslPathInformation::of)//
.orElse(null);
}
@@ -427,7 +427,7 @@ public class QuerydslBindings {
public AliasingPathBinder<P, T> as(String alias) {
Assert.hasText(alias, "Alias must not be null or empty!");
return new AliasingPathBinder<P, T>(alias, path);
return new AliasingPathBinder<>(alias, path);
}
/**
@@ -472,25 +472,13 @@ public class QuerydslBindings {
public <P extends Path<T>> void firstOptional(OptionalValueBinding<P, T> binding) {
Assert.notNull(binding, "Binding must not be null!");
all(new MultiValueBinding<P, T>() {
@Override
public Optional<Predicate> bind(P path, Collection<? extends T> value) {
return binding.bind(path, Optionals.next(value.iterator()));
}
});
all((MultiValueBinding<P, T>) (path, value) -> binding.bind(path, Optionals.next(value.iterator())));
}
public <P extends Path<T>> void first(SingleValueBinding<P, T> binding) {
Assert.notNull(binding, "Binding must not be null!");
all(new MultiValueBinding<P, T>() {
@Override
public Optional<Predicate> bind(P path, Collection<? extends T> value) {
return Optionals.next(value.iterator()).flatMap(t -> binding.bind(path, t));
}
});
all((MultiValueBinding<P, T>) (path, value) -> Optionals.next(value.iterator()).flatMap(t -> binding.bind(path, t)));
}
/**
@@ -520,15 +508,15 @@ public class QuerydslBindings {
@NonNull Optional<MultiValueBinding<P, T>> binding;
public static <T, P extends Path<? extends T>> PathAndBinding<P, T> withPath(P path) {
return new PathAndBinding<P, T>(Optional.of(path), Optional.empty());
return new PathAndBinding<>(Optional.of(path), Optional.empty());
}
public static <T, S extends Path<? extends T>> PathAndBinding<S, T> withoutPath() {
return new PathAndBinding<S, T>(Optional.empty(), Optional.empty());
return new PathAndBinding<>(Optional.empty(), Optional.empty());
}
public PathAndBinding<P, T> with(MultiValueBinding<P, T> binding) {
return new PathAndBinding<P, T>(path, Optional.of(binding));
return new PathAndBinding<>(path, Optional.of(binding));
}
}
}

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.
@@ -36,6 +36,7 @@ import com.querydsl.core.types.EntityPath;
* Factory to create {@link QuerydslBindings} using an {@link EntityPathResolver}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.11
*/
public class QuerydslBindingsFactory implements ApplicationContextAware {
@@ -58,7 +59,7 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
Assert.notNull(entityPathResolver, "EntityPathResolver must not be null!");
this.entityPathResolver = entityPathResolver;
this.entityPaths = new ConcurrentReferenceHashMap<TypeInformation<?>, EntityPath<?>>();
this.entityPaths = new ConcurrentReferenceHashMap<>();
this.beanFactory = Optional.empty();
this.repositories = Optional.empty();
}
@@ -140,12 +141,9 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
return customizer//
.filter(it -> !QuerydslBinderCustomizer.class.equals(it))//
.map(it -> createQuerydslBinderCustomizer(it)).orElseGet(() -> {
return repositories.flatMap(it -> it.getRepositoryFor(domainType))//
.map(it -> it instanceof QuerydslBinderCustomizer ? (QuerydslBinderCustomizer<EntityPath<?>>) it : null)//
.orElse(NoOpCustomizer.INSTANCE);
});
.map(this::createQuerydslBinderCustomizer).orElseGet(() -> repositories.flatMap(it -> it.getRepositoryFor(domainType))//
.map(it -> it instanceof QuerydslBinderCustomizer ? (QuerydslBinderCustomizer<EntityPath<?>>) it : null)//
.orElse(NoOpCustomizer.INSTANCE));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 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.
@@ -113,7 +113,7 @@ public class QuerydslPredicateBuilder {
Collection<Object> value = convertToPropertyPathSpecificType(entry.getValue(), propertyPath);
Optional<Predicate> predicate = invokeBinding(propertyPath, bindings, value);
predicate.ifPresent(it -> builder.and(it));
predicate.ifPresent(builder::and);
}
return builder.getValue();

View File

@@ -52,6 +52,7 @@ import org.springframework.util.StringUtils;
* @author Oliver Gierke
* @author Mark Paluch
* @author Peter Rietzler
* @author Christoph Strobl
*/
public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapable {
@@ -108,7 +109,7 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
* @param repositoryType must not be {@literal null}.
* @return
*/
private final String createPassivationId(Set<Annotation> qualifiers, Class<?> repositoryType) {
private String createPassivationId(Set<Annotation> qualifiers, Class<?> repositoryType) {
List<String> qualifierNames = new ArrayList<>(qualifiers.size());
@@ -117,11 +118,8 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
}
Collections.sort(qualifierNames);
return StringUtils.collectionToDelimitedString(qualifierNames, ":") + ":" + repositoryType.getName();
StringBuilder builder = new StringBuilder(StringUtils.collectionToDelimitedString(qualifierNames, ":"));
builder.append(":").append(repositoryType.getName());
return builder.toString();
}
/*
@@ -299,7 +297,7 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
public Set<Class<? extends Annotation>> getStereotypes() {
return Arrays.stream(repositoryType.getAnnotations())//
.map(it -> it.annotationType())//
.map(Annotation::annotationType)//
.filter(it -> it.isAnnotationPresent(Stereotype.class))//
.collect(Collectors.toSet());
}
@@ -359,7 +357,7 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
* @param repositoryType will never be {@literal null}.
* @return
*/
private final T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
private T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
Optional<Bean<?>> customImplementationBean = getCustomImplementationBean(repositoryType, beanManager, qualifiers);
Optional<Object> customImplementation = customImplementationBean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2014 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.
@@ -53,13 +53,14 @@ import org.springframework.data.repository.config.CustomRepositoryImplementation
* @author Dirk Mahler
* @author Oliver Gierke
* @author Mark Paluch
* @author Christoph Strobl
*/
public abstract class CdiRepositoryExtensionSupport implements Extension {
private static final Logger LOGGER = LoggerFactory.getLogger(CdiRepositoryExtensionSupport.class);
private final Map<Class<?>, Set<Annotation>> repositoryTypes = new HashMap<Class<?>, Set<Annotation>>();
private final Set<CdiRepositoryBean<?>> eagerRepositories = new HashSet<CdiRepositoryBean<?>>();
private final Map<Class<?>, Set<Annotation>> repositoryTypes = new HashMap<>();
private final Set<CdiRepositoryBean<?>> eagerRepositories = new HashSet<>();
private final CustomRepositoryImplementationDetector customImplementationDetector;
protected CdiRepositoryExtensionSupport() {

View File

@@ -40,6 +40,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Christoph Strobl
* @author Peter Rietzler
*/
@RequiredArgsConstructor
@@ -111,7 +112,7 @@ public class CustomRepositoryImplementationDetector {
throw new IllegalStateException(
String.format("Ambiguous custom implementations detected! Found %s but expected a single implementation!", //
definitions.stream()//
.map(it -> it.getBeanClassName())//
.map(BeanDefinition::getBeanClassName)//
.collect(Collectors.joining(", "))));
}
}

View File

@@ -34,6 +34,7 @@ import org.springframework.util.Assert;
* Builder to create {@link BeanDefinitionBuilder} instance to eventually create Spring Data repository instances.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @author Peter Rietzler
*/
class RepositoryBeanDefinitionBuilder {
@@ -95,7 +96,7 @@ class RepositoryBeanDefinitionBuilder {
NamedQueriesBeanDefinitionBuilder definitionBuilder = new NamedQueriesBeanDefinitionBuilder(
extension.getDefaultNamedQueryLocation());
configuration.getNamedQueriesLocation().ifPresent(it -> definitionBuilder.setLocations(it));
configuration.getNamedQueriesLocation().ifPresent(definitionBuilder::setLocations);
builder.addPropertyValue("namedQueries", definitionBuilder.build(configuration.getSource()));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 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.
@@ -43,6 +43,7 @@ import org.springframework.util.StringUtils;
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Christoph Strobl
*/
public abstract class RepositoryConfigurationExtensionSupport implements RepositoryConfigurationExtension {
@@ -79,7 +80,7 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
Assert.notNull(configSource, "ConfigSource must not be null!");
Assert.notNull(loader, "Loader must not be null!");
Set<RepositoryConfiguration<T>> result = new HashSet<RepositoryConfiguration<T>>();
Set<RepositoryConfiguration<T>> result = new HashSet<>();
for (BeanDefinition candidate : configSource.getCandidates(loader)) {

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.
@@ -25,6 +25,7 @@ import org.springframework.core.type.filter.TypeFilter;
import org.springframework.data.config.TypeFilterParser;
import org.springframework.data.config.TypeFilterParser.Type;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.data.util.ParsingUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -35,6 +36,7 @@ import org.w3c.dom.Element;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
* @author Peter Rietzler
*/
public class XmlRepositoryConfigurationSource extends RepositoryConfigurationSourceSupport {
@@ -98,7 +100,7 @@ public class XmlRepositoryConfigurationSource extends RepositoryConfigurationSou
* @see org.springframework.data.repository.config.RepositoryConfigurationSource#getQueryLookupStrategyKey()
*/
public Optional<Object> getQueryLookupStrategyKey() {
return getNullDefaultedAttribute(element, QUERY_LOOKUP_STRATEGY).map(it -> QueryLookupStrategy.Key.create(it));
return getNullDefaultedAttribute(element, QUERY_LOOKUP_STRATEGY).map(Key::create);
}
/*
@@ -173,7 +175,7 @@ public class XmlRepositoryConfigurationSource extends RepositoryConfigurationSou
@Override
public boolean shouldConsiderNestedRepositories() {
return getNullDefaultedAttribute(element, CONSIDER_NESTED_REPOSITORIES).map(it -> Boolean.parseBoolean(it))
return getNullDefaultedAttribute(element, CONSIDER_NESTED_REPOSITORIES).map(Boolean::parseBoolean)
.orElse(false);
}

View File

@@ -54,6 +54,7 @@ import org.springframework.util.ClassUtils;
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
* @author Christoph Strobl
*/
class DefaultRepositoryInformation implements RepositoryInformation {
@@ -62,7 +63,7 @@ class DefaultRepositoryInformation implements RepositoryInformation {
private static final String DOMAIN_TYPE_NAME = PARAMETERS[0].getName();
private static final String ID_TYPE_NAME = PARAMETERS[1].getName();
private final Map<Method, Method> methodCache = new ConcurrentHashMap<Method, Method>();
private final Map<Method, Method> methodCache = new ConcurrentHashMap<>();
private final RepositoryMetadata metadata;
private final Class<?> repositoryBaseClass;

View File

@@ -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.
@@ -44,6 +44,7 @@ import org.springframework.util.ReflectionUtils;
* will be invoked after all events have been published.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.13
* @soundtrack Henrik Freischlader Trio - Master Plan (Openness)
*/
@@ -110,7 +111,7 @@ public class EventPublishingRepositoryProxyPostProcessor implements RepositoryPr
@RequiredArgsConstructor
static class EventPublishingMethod {
private static Map<Class<?>, EventPublishingMethod> CACHE = new ConcurrentReferenceHashMap<Class<?>, EventPublishingMethod>();
private static Map<Class<?>, EventPublishingMethod> CACHE = new ConcurrentReferenceHashMap<>();
private static EventPublishingMethod NONE = new EventPublishingMethod(null, null);
private final Method publishingMethod;
@@ -133,14 +134,14 @@ public class EventPublishingRepositoryProxyPostProcessor implements RepositoryPr
return eventPublishingMethod.orNull();
}
AnnotationDetectionMethodCallback<DomainEvents> publishing = new AnnotationDetectionMethodCallback<DomainEvents>(
AnnotationDetectionMethodCallback<DomainEvents> publishing = new AnnotationDetectionMethodCallback<>(
DomainEvents.class);
ReflectionUtils.doWithMethods(type, publishing);
// TODO: Lazify this as the inspection might not be needed if the publishing callback didn't find an annotation in
// the first place
AnnotationDetectionMethodCallback<AfterDomainEventPublication> clearing = new AnnotationDetectionMethodCallback<AfterDomainEventPublication>(
AnnotationDetectionMethodCallback<AfterDomainEventPublication> clearing = new AnnotationDetectionMethodCallback<>(
AfterDomainEventPublication.class);
ReflectionUtils.doWithMethods(type, clearing);
@@ -240,7 +241,7 @@ public class EventPublishingRepositoryProxyPostProcessor implements RepositoryPr
return (Collection<Object>) source;
}
return Arrays.asList(source);
return Collections.singletonList(source);
}
}
}

View File

@@ -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.
@@ -26,6 +26,7 @@ import org.springframework.util.Assert;
*
* @author Mark Paluch
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.12
*/
public class ExampleMatcherAccessor {
@@ -143,7 +144,7 @@ public class ExampleMatcherAccessor {
}
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
return specifier.getIgnoreCase() != null ? specifier.getIgnoreCase().booleanValue() : matcher.isIgnoreCaseEnabled();
return specifier.getIgnoreCase() != null ? specifier.getIgnoreCase() : matcher.isIgnoreCaseEnabled();
}
/**

View File

@@ -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.
@@ -19,6 +19,7 @@ import java.io.Serializable;
import java.util.Optional;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.repository.core.EntityInformation;
/**
@@ -26,6 +27,7 @@ import org.springframework.data.repository.core.EntityInformation;
* a {@link org.springframework.data.mapping.IdentifierAccessor} to access the property value if requested.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
@SuppressWarnings("unchecked")
public class PersistentEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID> {
@@ -58,6 +60,6 @@ public class PersistentEntityInformation<T, ID extends Serializable> extends Abs
*/
@Override
public Class<ID> getIdType() {
return (Class<ID>) persistentEntity.getIdProperty().map(it -> it.getType()).orElse(null);
return (Class<ID>) persistentEntity.getIdProperty().map(PersistentProperty::getType).orElse(null);
}
}

View File

@@ -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.ReflectionUtils;
* retrieve the id.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public class ReflectionEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID> {
@@ -66,7 +67,7 @@ public class ReflectionEntityInformation<T, ID extends Serializable> extends Abs
}
});
Assert.notNull(this.field, String.format("No field annotated with %s found!", annotation.toString()));
Assert.notNull(this.field, () -> String.format("No field annotated with %s found!", annotation.toString()));
ReflectionUtils.makeAccessible(field);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2016 the original author or authors.
* Copyright 2008-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.
@@ -71,6 +71,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Christoph Strobl
*/
public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, BeanFactoryAware {
@@ -363,12 +364,9 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
Class<?> baseClass = information.getRepositoryBaseClass();
Optional<Constructor<?>> constructor = ReflectionUtils.findConstructor(baseClass, constructorArguments);
return constructor.map(it -> (R) BeanUtils.instantiateClass(it, constructorArguments)).orElseThrow(() -> {
return new IllegalStateException(String.format(
"No suitable constructor found on %s to match the given arguments: %s. Make sure you implement a constructor taking these",
baseClass, Arrays.stream(constructorArguments).map(Object::getClass).collect(Collectors.toList())));
});
return constructor.map(it -> (R) BeanUtils.instantiateClass(it, constructorArguments)).orElseThrow(() -> new IllegalStateException(String.format(
"No suitable constructor found on %s to match the given arguments: %s. Make sure you implement a constructor taking these",
baseClass, Arrays.stream(constructorArguments).map(Object::getClass).collect(Collectors.toList()))));
}
/**

View File

@@ -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.
@@ -26,6 +26,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
* proxy.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.13
* @soundtrack Hendrik Freischlader Trio - Openness (Openness)
*/
@@ -33,7 +34,7 @@ public enum SurroundingTransactionDetectorMethodInterceptor implements MethodInt
INSTANCE;
private final ThreadLocal<Boolean> SURROUNDING_TX_ACTIVE = new ThreadLocal<Boolean>();
private final ThreadLocal<Boolean> SURROUNDING_TX_ACTIVE = new ThreadLocal<>();
/**
* Returns whether a transaction was active before the method call entered the repository proxy.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-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.
@@ -52,6 +52,7 @@ import org.springframework.util.ObjectUtils;
* the proxy.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
class TransactionalRepositoryProxyPostProcessor implements RepositoryProxyPostProcessor {
@@ -300,7 +301,7 @@ class TransactionalRepositoryProxyPostProcessor implements RepositoryProxyPostPr
* As this base class is not marked Serializable, the cache will be recreated after serialization - provided that
* the concrete subclass is Serializable.
*/
final Map<Object, TransactionAttribute> attributeCache = new ConcurrentHashMap<Object, TransactionAttribute>();
final Map<Object, TransactionAttribute> attributeCache = new ConcurrentHashMap<>();
private RepositoryInformation repositoryInformation;
private boolean enableDefaultTransactions = true;

View File

@@ -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.
@@ -51,6 +51,7 @@ import org.springframework.util.ReflectionUtils.MethodFilter;
* {@link org.springframework.expression.EvaluationContext}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.9
*/
class EvaluationContextExtensionInformation {
@@ -142,7 +143,7 @@ class EvaluationContextExtensionInformation {
private static Map<String, Function> discoverDeclaredFunctions(Class<?> type) {
Map<String, Function> map = new HashMap<String, Function>();
Map<String, Function> map = new HashMap<>();
ReflectionUtils.doWithMethods(type, //
method -> map.put(method.getName(), new Function(method, null)), //
@@ -214,7 +215,7 @@ class EvaluationContextExtensionInformation {
Assert.notNull(type, "Type must not be null!");
this.accessors = new HashMap<String, Method>();
this.accessors = new HashMap<>();
this.methods = new HashSet<>();
this.fields = new ArrayList<>();
@@ -234,7 +235,7 @@ class EvaluationContextExtensionInformation {
}, PublicMethodAndFieldFilter.NON_STATIC);
ReflectionUtils.doWithFields(type, field -> RootObjectInformation.this.fields.add(field),
ReflectionUtils.doWithFields(type, RootObjectInformation.this.fields::add,
PublicMethodAndFieldFilter.NON_STATIC);
}
@@ -250,7 +251,7 @@ class EvaluationContextExtensionInformation {
.collect(Collectors.toMap(//
Method::getName, //
method -> new Function(method, it))))
.orElseGet(() -> Collections.emptyMap());
.orElseGet(Collections::emptyMap);
}
/**
@@ -263,7 +264,7 @@ class EvaluationContextExtensionInformation {
return target.map(it -> {
Map<String, Object> properties = new HashMap<String, Object>();
Map<String, Object> properties = new HashMap<>();
accessors.entrySet().stream()
.forEach(method -> properties.put(method.getKey(), new Function(method.getValue(), it)));
@@ -271,13 +272,13 @@ class EvaluationContextExtensionInformation {
return Collections.unmodifiableMap(properties);
}).orElseGet(() -> Collections.emptyMap());
}).orElseGet(Collections::emptyMap);
}
}
private static Map<String, Object> discoverDeclaredProperties(Class<?> type) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
ReflectionUtils.doWithFields(type, field -> map.put(field.getName(), field.get(null)),
PublicMethodAndFieldFilter.STATIC);

View File

@@ -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.
@@ -64,7 +64,7 @@ import org.springframework.util.StringUtils;
*/
public class ExtensionAwareEvaluationContextProvider implements EvaluationContextProvider, ApplicationContextAware {
private final Map<Class<?>, EvaluationContextExtensionInformation> extensionInformationCache = new HashMap<Class<?>, EvaluationContextExtensionInformation>();
private final Map<Class<?>, EvaluationContextExtensionInformation> extensionInformationCache = new HashMap<>();
private List<? extends EvaluationContextExtension> extensions;
private Optional<ListableBeanFactory> beanFactory = Optional.empty();
@@ -131,7 +131,7 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
*/
private <T extends Parameters<?, ?>> Map<String, Object> collectVariables(T parameters, Object[] arguments) {
Map<String, Object> variables = new HashMap<String, Object>();
Map<String, Object> variables = new HashMap<>();
parameters.stream()//
.filter(Parameter::isSpecialParameter)//
@@ -162,10 +162,8 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
this.extensions = Collections.emptyList();
beanFactory.ifPresent(it -> {
this.extensions = new ArrayList<>(
it.getBeansOfType(EvaluationContextExtension.class, true, false).values());
});
beanFactory.ifPresent(it -> this.extensions = new ArrayList<>(
it.getBeansOfType(EvaluationContextExtension.class, true, false).values()));
return extensions;
}
@@ -220,7 +218,7 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
this.adapters = toAdapters(extensions);
this.adapterMap = adapters.stream()//
.collect(Collectors.toMap(it -> it.getExtensionId(), it -> it));
.collect(Collectors.toMap(EvaluationContextExtensionAdapter::getExtensionId, it -> it));
Collections.reverse(this.adapters);
}
@@ -410,12 +408,12 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
ExtensionTypeInformation extensionTypeInformation = information.getExtensionTypeInformation();
RootObjectInformation rootObjectInformation = information.getRootObjectInformation(target);
this.functions = new HashMap<String, Function>();
this.functions = new HashMap<>();
this.functions.putAll(extensionTypeInformation.getFunctions());
this.functions.putAll(rootObjectInformation.getFunctions(target));
this.functions.putAll(extension.getFunctions());
this.properties = new HashMap<String, Object>();
this.properties = new HashMap<>();
this.properties.putAll(extensionTypeInformation.getProperties());
this.properties.putAll(rootObjectInformation.getProperties(target));
this.properties.putAll(extension.getProperties());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2015 the original author or authors.
* Copyright 2008-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.util.Assert;
* Abstracts method parameters that have to be bound to query parameters or applied to the query independently.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter> implements Streamable<T> {
@@ -283,7 +284,7 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
*
* @param method
*/
private final void assertEitherAllParamAnnotatedOrNone() {
private void assertEitherAllParamAnnotatedOrNone() {
boolean nameFound = false;
int index = 0;

View File

@@ -40,6 +40,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
* @author Maciek Opała
*/
public class QueryMethod {
@@ -90,7 +91,7 @@ public class QueryMethod {
}
}
Assert.notNull(this.parameters,
Assert.notNull(this.parameters, () ->
String.format("Parameters extracted from method '%s' must not be null!", method.getName()));
if (isPageQuery()) {
@@ -265,7 +266,7 @@ public class QueryMethod {
if (QueryExecutionConverters.supports(method.getReturnType())) {
// unwrap only one level to handle cases like Future<List<Entity>> correctly.
return ClassTypeInformation.fromReturnTypeOf(method).getComponentType().map(it -> it.getType())
return ClassTypeInformation.fromReturnTypeOf(method).getComponentType().map(TypeInformation::getType)
.orElseThrow(() -> new IllegalStateException(
String.format("Couldn't find component type for return value of method %s!", method)));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 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.
@@ -42,6 +42,7 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
* @author John Blum
* @author Mark Paluch
* @author Christoph Strobl
* @since 1.12
*/
public class ResultProcessor {
@@ -88,7 +89,7 @@ public class ResultProcessor {
*/
public ResultProcessor withDynamicProjection(Optional<ParameterAccessor> accessor) {
return accessor.flatMap(it -> it.getDynamicProjection())//
return accessor.flatMap(ParameterAccessor::getDynamicProjection)//
.map(it -> new ResultProcessor(method, factory, it))//
.orElse(this);
}
@@ -267,7 +268,7 @@ public class ResultProcessor {
private static Map<String, Object> toMap(Collection<?> values, List<String> names) {
int i = 0;
Map<String, Object> result = new HashMap<String, Object>(values.size());
Map<String, Object> result = new HashMap<>(values.size());
for (Object element : values) {
result.put(names.get(i++), element);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 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.
@@ -39,6 +39,7 @@ import org.springframework.util.ClassUtils;
* A representation of the type returned by a {@link QueryMethod}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.12
*/
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@@ -60,9 +61,9 @@ public abstract class ReturnedType {
Assert.notNull(domainType, "Domain type must not be null!");
Assert.notNull(factory, "ProjectionFactory must not be null!");
return (ReturnedType) (returnedType.isInterface()
return returnedType.isInterface()
? new ReturnedInterface(factory.getProjectionInformation(returnedType), domainType)
: new ReturnedClass(returnedType, domainType));
: new ReturnedClass(returnedType, domainType);
}
/**
@@ -209,7 +210,7 @@ public abstract class ReturnedType {
*/
private static final class ReturnedClass extends ReturnedType {
private static final Set<Class<?>> VOID_TYPES = new HashSet<Class<?>>(Arrays.asList(Void.class, void.class));
private static final Set<Class<?>> VOID_TYPES = new HashSet<>(Arrays.asList(Void.class, void.class));
private final Class<?> type;
private final List<String> inputProperties;
@@ -285,13 +286,9 @@ public abstract class ReturnedType {
PreferredConstructorDiscoverer<?, ?> discoverer = new PreferredConstructorDiscoverer(type);
return discoverer.getConstructor().map(it -> {
return it.getParameters().stream()//
.flatMap(parameter -> Optionals.toStream(parameter.getName()))//
.collect(Collectors.toList());
}).orElseGet(() -> Collections.emptyList());
return discoverer.getConstructor().map(it -> it.getParameters().stream()//
.flatMap(parameter -> Optionals.toStream(parameter.getName()))//
.collect(Collectors.toList())).orElseGet(Collections::emptyList);
}
private boolean isDto() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2015 the original author or authors.
* Copyright 2008-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.
@@ -36,6 +36,7 @@ import org.springframework.util.StringUtils;
* method ends are valid: {@code LastnameUsernameDesc}, {@code LastnameAscUsernameDesc}.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
class OrderBySource {
@@ -67,7 +68,7 @@ class OrderBySource {
*/
public OrderBySource(String clause, Optional<Class<?>> domainClass) {
this.orders = new ArrayList<Sort.Order>();
this.orders = new ArrayList<>();
if (!StringUtils.hasText(clause)) {
return;

View File

@@ -238,7 +238,7 @@ public class PartTree implements Streamable<OrPart> {
String[] split = split(source, "And");
this.children = Arrays.stream(split)//
.filter(part -> StringUtils.hasText(part))//
.filter(StringUtils::hasText)//
.map(part -> new Part(part, domainClass, alwaysIgnoreCase))//
.collect(Collectors.toList());
}
@@ -339,7 +339,7 @@ public class PartTree implements Streamable<OrPart> {
return maxResults;
}
private final boolean matches(Optional<String> subject, Pattern pattern) {
private boolean matches(Optional<String> subject, Pattern pattern) {
return subject.map(it -> pattern.matcher(it).find()).orElse(false);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 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;
* Simply helper to reference a dedicated attribute of an {@link Annotation}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.10
*/
@RequiredArgsConstructor
@@ -67,7 +68,7 @@ class AnnotationAttribute {
Assert.notNull(parameter, "MethodParameter must not be null!");
Annotation annotation = parameter.getParameterAnnotation(annotationType);
return Optional.ofNullable(annotation).map(it -> getValueFrom(it));
return Optional.ofNullable(annotation).map(this::getValueFrom);
}
/**
@@ -93,7 +94,7 @@ class AnnotationAttribute {
public Object getValueFrom(Annotation annotation) {
Assert.notNull(annotation, "Annotation must not be null!");
return (String) attributeName.map(it -> AnnotationUtils.getValue(annotation, it))
return attributeName.map(it -> AnnotationUtils.getValue(annotation, it))
.orElseGet(() -> AnnotationUtils.getValue(annotation));
}
}

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.
@@ -31,6 +31,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
* to avoid reflection overhead introduced by the base class if we know we work with a {@link CrudRepository}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.10
*/
class CrudRepositoryInvoker extends ReflectionRepositoryInvoker {
@@ -89,7 +90,7 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker {
@Override
@SuppressWarnings("unchecked")
public <T> T invokeFindOne(Serializable id) {
return customFindOneMethod ? super.<T>invokeFindOne(id) : (T) repository.findOne(convertId(id));
return customFindOneMethod ? super.invokeFindOne(id) : (T) repository.findOne(convertId(id));
}
/*

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.
@@ -36,6 +36,7 @@ import org.springframework.util.Assert;
* invocations over reflection ones.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.10
*/
public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory {
@@ -67,7 +68,7 @@ public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory
this.repositories = repositories;
this.conversionService = conversionService;
this.invokers = new HashMap<Class<?>, RepositoryInvoker>();
this.invokers = new HashMap<>();
}
/*
@@ -76,7 +77,7 @@ public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory
*/
@Override
public RepositoryInvoker getInvokerFor(Class<?> domainType) {
return invokers.computeIfAbsent(domainType, type -> prepareInvokers(type));
return invokers.computeIfAbsent(domainType, this::prepareInvokers);
}
/**
@@ -90,7 +91,7 @@ public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory
Optional<RepositoryInformation> information = repositories.getRepositoryInformationFor(domainType);
Optional<Object> repository = repositories.getRepositoryFor(domainType);
return mapIfAllPresent(information, repository, (left, right) -> createInvoker(left, right))//
return mapIfAllPresent(information, repository, this::createInvoker)//
.orElseThrow(
() -> new IllegalArgumentException(String.format("No repository found for domain type: %s", domainType)));
}

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.
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
* Value object to represent {@link MethodParameters} to allow to easily find the ones with a given annotation.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.10
*/
class MethodParameters {
@@ -146,12 +147,9 @@ class MethodParameters {
super(method, parameterIndex);
this.attribute = attribute;
this.name = Lazy.of(() -> {
return this.attribute.//
flatMap(it -> it.getValueFrom(this).map(Object::toString)).//
orElseGet(() -> super.getParameterName());
});
this.name = Lazy.of(() -> this.attribute.//
flatMap(it -> it.getValueFrom(this).map(Object::toString)).//
orElseGet(super::getParameterName));
}
/*

View File

@@ -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.
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
*
* @author Mark Paluch
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.13
*/
@UtilityClass
@@ -55,16 +56,16 @@ public class PageableExecutionUtils {
if (pageable == Pageable.NONE || pageable.getOffset() == 0) {
if (pageable == Pageable.NONE || pageable.getPageSize() > content.size()) {
return new PageImpl<T>(content, pageable, content.size());
return new PageImpl<>(content, pageable, content.size());
}
return new PageImpl<T>(content, pageable, totalSupplier.getAsLong());
return new PageImpl<>(content, pageable, totalSupplier.getAsLong());
}
if (content.size() != 0 && pageable.getPageSize() > content.size()) {
return new PageImpl<T>(content, pageable, pageable.getOffset() + content.size());
return new PageImpl<>(content, pageable, pageable.getOffset() + content.size());
}
return new PageImpl<T>(content, pageable, totalSupplier.getAsLong());
return new PageImpl<>(content, pageable, totalSupplier.getAsLong());
}
}

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.
@@ -43,6 +43,7 @@ import org.springframework.util.ClassUtils;
* @author Oliver Gierke
* @author Thomas Darimont
* @author Thomas Eizinger
* @author Christoph Strobl
*/
public class Repositories implements Iterable<Class<?>> {
@@ -76,8 +77,8 @@ public class Repositories implements Iterable<Class<?>> {
Assert.notNull(factory, "Factory must not be null!");
this.beanFactory = Optional.of(factory);
this.repositoryFactoryInfos = new HashMap<Class<?>, RepositoryFactoryInformation<Object, Serializable>>();
this.repositoryBeanNames = new HashMap<Class<?>, String>();
this.repositoryFactoryInfos = new HashMap<>();
this.repositoryBeanNames = new HashMap<>();
populateRepositoryFactoryInformation(factory);
}
@@ -102,7 +103,7 @@ public class Repositories implements Iterable<Class<?>> {
Set<Class<?>> alternativeDomainTypes = information.getAlternativeDomainTypes();
String beanName = BeanFactoryUtils.transformedBeanName(name);
Set<Class<?>> typesToRegister = new HashSet<Class<?>>(alternativeDomainTypes.size() + 1);
Set<Class<?>> typesToRegister = new HashSet<>(alternativeDomainTypes.size() + 1);
typesToRegister.add(domainType);
typesToRegister.addAll(alternativeDomainTypes);
@@ -136,7 +137,7 @@ public class Repositories implements Iterable<Class<?>> {
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
Optional<String> repositoryBeanName = Optional.ofNullable(repositoryBeanNames.get(domainClass));
return beanFactory.flatMap(it -> repositoryBeanName.map(name -> it.getBean(name)));
return beanFactory.flatMap(it -> repositoryBeanName.map(it::getBean));
}
/**
@@ -271,7 +272,7 @@ public class Repositories implements Iterable<Class<?>> {
@Override
public List<QueryMethod> getQueryMethods() {
return Collections.<QueryMethod>emptyList();
return Collections.emptyList();
}
}
}

View File

@@ -35,6 +35,7 @@ import org.springframework.data.repository.util.QueryExecutionConverters.Wrapper
* Converter implementations to map from and to Javaslang collections.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.13
*/
class JavaslangCollections {
@@ -131,7 +132,7 @@ class JavaslangCollections {
static {
Set<ConvertiblePair> pairs = new HashSet<ConvertiblePair>();
Set<ConvertiblePair> pairs = new HashSet<>();
pairs.add(new ConvertiblePair(Collection.class, javaslang.collection.Traversable.class));
pairs.add(new ConvertiblePair(Map.class, javaslang.collection.Traversable.class));

View File

@@ -66,6 +66,7 @@ import com.google.common.base.Optional;
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Christoph Strobl
* @author Maciek Opała
* @since 1.8
* @see ReactiveWrappers

View File

@@ -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.
@@ -26,18 +26,19 @@ import java.util.concurrent.ConcurrentHashMap;
* on each and every request.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
@RequiredArgsConstructor
public class CachingIsNewStrategyFactory implements IsNewStrategyFactory {
private final @NonNull IsNewStrategyFactory delegate;
private final Map<Class<?>, IsNewStrategy> cache = new ConcurrentHashMap<Class<?>, IsNewStrategy>();
private final Map<Class<?>, IsNewStrategy> cache = new ConcurrentHashMap<>();
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.model.IsNewStrategyFactory#getIsNewStrategy(java.lang.Class)
*/
public IsNewStrategy getIsNewStrategy(Class<?> type) {
return cache.computeIfAbsent(type, it -> delegate.getIsNewStrategy(it));
return cache.computeIfAbsent(type, delegate::getIsNewStrategy);
}
}

View File

@@ -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.
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
*
* @author Michael Hunger
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.6
*/
class MultiTransactionStatus implements TransactionStatus {
@@ -175,7 +176,7 @@ class MultiTransactionStatus implements TransactionStatus {
private static class SavePoints {
private final Map<TransactionStatus, Object> savepoints = new HashMap<TransactionStatus, Object>();
private final Map<TransactionStatus, Object> savepoints = new HashMap<>();
private void addSavePoint(TransactionStatus status, Object savepoint) {

View File

@@ -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.
@@ -34,6 +34,7 @@ import org.springframework.util.ClassUtils;
* Scanner to find types with annotations on the classpath.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public class AnnotatedTypeScanner implements ResourceLoaderAware, EnvironmentAware {
@@ -104,7 +105,7 @@ public class AnnotatedTypeScanner implements ResourceLoaderAware, EnvironmentAwa
provider.addIncludeFilter(new AnnotationTypeFilter(annotationType, true, considerInterfaces));
}
Set<Class<?>> types = new HashSet<Class<?>>();
Set<Class<?>> types = new HashSet<>();
for (String basePackage : basePackages) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2014 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.
@@ -39,6 +39,7 @@ import org.springframework.util.ClassUtils;
* {@link TypeInformation} for a plain {@link Class}.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
@@ -54,7 +55,7 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
static {
for (ClassTypeInformation<?> info : Arrays.asList(COLLECTION, LIST, SET, MAP, OBJECT)) {
CACHE.put(info.getType(), new WeakReference<ClassTypeInformation<?>>(info));
CACHE.put(info.getType(), new WeakReference<>(info));
}
}
@@ -79,7 +80,7 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
}
ClassTypeInformation<S> result = new ClassTypeInformation<>(type);
CACHE.put(type, new WeakReference<ClassTypeInformation<?>>(result));
CACHE.put(type, new WeakReference<>(result));
return result;
}
@@ -126,7 +127,7 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
}
Map<TypeVariable, Type> source = GenericTypeResolver.getTypeVariableMap(type);
Map<TypeVariable<?>, Type> map = new HashMap<TypeVariable<?>, Type>(source.size());
Map<TypeVariable<?>, Type> map = new HashMap<>(source.size());
for (Entry<TypeVariable, Type> entry : source.entrySet()) {

View File

@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
* Utility methods to work with {@link Optional}s.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
@UtilityClass
public class Optionals {
@@ -62,7 +63,7 @@ public class Optionals {
Assert.notNull(optionals, "Optional must not be null!");
return Arrays.asList(optionals).stream().flatMap(it -> it.map(Stream::of).orElseGet(() -> Stream.empty()));
return Arrays.asList(optionals).stream().flatMap(it -> it.map(Stream::of).orElseGet(Stream::empty));
}
/**
@@ -78,9 +79,9 @@ public class Optionals {
Assert.notNull(function, "Function must not be null!");
return Streamable.of(source).stream()//
.map(it -> function.apply(it))//
.filter(it -> it.isPresent())//
.findFirst().orElseGet(() -> Optional.empty());
.map(function::apply)//
.filter(Optional::isPresent)//
.findFirst().orElseGet(Optional::empty);
}
/**
@@ -96,7 +97,7 @@ public class Optionals {
Assert.notNull(function, "Function must not be null!");
return Streamable.of(source).stream()//
.map(it -> function.apply(it))//
.map(function::apply)//
.filter(it -> !it.equals(defaultValue))//
.findFirst().orElse(defaultValue);
}
@@ -126,8 +127,8 @@ public class Optionals {
Assert.notNull(suppliers, "Suppliers must not be null!");
return Streamable.of(suppliers).stream()//
.map(it -> it.get())//
.filter(it -> it.isPresent())//
.map(Supplier::get)//
.filter(Optional::isPresent)//
.findFirst().orElse(Optional.empty());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 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.
@@ -30,6 +30,7 @@ import java.util.stream.Collectors;
*
* @author Tobias Trelle
* @author Oliver Gierke
* @author Christoph Strobl
* @param <S> Type of the first thing.
* @param <T> Type of the second thing.
* @since 1.12
@@ -50,7 +51,7 @@ public final class Pair<S, T> {
* @return
*/
public static <S, T> Pair<S, T> of(S first, T second) {
return new Pair<S, T>(first, second);
return new Pair<>(first, second);
}
/**

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.
@@ -34,6 +34,7 @@ import org.springframework.util.StringUtils;
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Christoph Strobl
*/
class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T> {
@@ -72,7 +73,7 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
Class<?> rawType = getType();
Set<Type> supertypes = new HashSet<>();
Optional.ofNullable(rawType.getGenericSuperclass()).ifPresent(it -> supertypes.add(it));
Optional.ofNullable(rawType.getGenericSuperclass()).ifPresent(supertypes::add);
supertypes.addAll(Arrays.asList(rawType.getGenericInterfaces()));
Optional<TypeInformation<?>> result = supertypes.stream()//
@@ -95,7 +96,7 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
@Override
public List<TypeInformation<?>> getTypeArguments() {
List<TypeInformation<?>> result = new ArrayList<TypeInformation<?>>();
List<TypeInformation<?>> result = new ArrayList<>();
for (Type argument : type.getActualTypeArguments()) {
result.add(createInfo(argument));

View File

@@ -52,7 +52,7 @@ public abstract class ParentTypeAwareTypeInformation<S> extends TypeDiscoverer<S
*/
private static Map<TypeVariable<?>, Type> mergeMaps(TypeDiscoverer<?> parent, Map<TypeVariable<?>, Type> map) {
Map<TypeVariable<?>, Type> typeVariableMap = new HashMap<TypeVariable<?>, Type>();
Map<TypeVariable<?>, Type> typeVariableMap = new HashMap<>();
typeVariableMap.putAll(map);
typeVariableMap.putAll(parent.getTypeVariableMap());

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.
@@ -42,6 +42,7 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
* @since 1.5
*/
public abstract class ReflectionUtils {
@@ -277,7 +278,7 @@ public abstract class ReflectionUtils {
public static Optional<Method> getMethod(Class<?> type, String name, ResolvableType... parameterTypes) {
List<Class<?>> collect = Arrays.stream(parameterTypes).map(it -> it.getRawClass()).collect(Collectors.toList());
List<Class<?>> collect = Arrays.stream(parameterTypes).map(ResolvableType::getRawClass).collect(Collectors.toList());
Optional<Method> method = Optional.ofNullable(
org.springframework.util.ReflectionUtils.findMethod(type, name, collect.toArray(new Class<?>[collect.size()])));
@@ -286,7 +287,7 @@ public abstract class ReflectionUtils {
.allMatch(index -> ResolvableType.forMethodParameter(it, index).equals(parameterTypes[index])));
}
private static final boolean argumentsMatch(Class<?>[] parameterTypes, Object[] arguments) {
private static boolean argumentsMatch(Class<?>[] parameterTypes, Object[] arguments) {
if (parameterTypes.length != arguments.length) {
return false;

View File

@@ -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.
@@ -26,6 +26,7 @@ import org.springframework.util.Assert;
* Simple interface to ease streamability of {@link Iterable}s.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public interface Streamable<T> extends Iterable<T> {
@@ -43,8 +44,8 @@ public interface Streamable<T> extends Iterable<T> {
*
* @return will never be {@literal null}.
*/
public static <T> Streamable<T> empty() {
return () -> Collections.emptyIterator();
static <T> Streamable<T> empty() {
return Collections::emptyIterator;
}
/**
@@ -54,7 +55,7 @@ public interface Streamable<T> extends Iterable<T> {
* @return
*/
@SafeVarargs
public static <T> Streamable<T> of(T... t) {
static <T> Streamable<T> of(T... t) {
return () -> Arrays.asList(t).iterator();
}
@@ -64,10 +65,10 @@ public interface Streamable<T> extends Iterable<T> {
* @param iterable must not be {@literal null}.
* @return
*/
public static <T> Streamable<T> of(Iterable<T> iterable) {
static <T> Streamable<T> of(Iterable<T> iterable) {
Assert.notNull(iterable, "Iterable must not be null!");
return () -> iterable.iterator();
return iterable::iterator;
}
}

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.
@@ -51,6 +51,7 @@ import org.springframework.util.ReflectionUtils;
* Basic {@link TypeDiscoverer} that contains basic functionality to discover property types.
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
class TypeDiscoverer<S> implements TypeInformation<S> {
@@ -60,7 +61,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
ClassLoader classLoader = TypeDiscoverer.class.getClassLoader();
Set<Class<?>> mapTypes = new HashSet<Class<?>>();
Set<Class<?>> mapTypes = new HashSet<>();
mapTypes.add(Map.class);
try {
@@ -92,8 +93,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
this.type = type;
this.resolvedType = Lazy.of(() -> resolveType(type));
this.componentType = Lazy.of(() -> doGetComponentType());
this.valueType = Lazy.of(() -> doGetMapValueType());
this.componentType = Lazy.of(this::doGetComponentType);
this.valueType = Lazy.of(this::doGetMapValueType);
this.typeVariableMap = typeVariableMap;
this.hashCode = 17 + (31 * type.hashCode()) + (31 * typeVariableMap.hashCode());
}
@@ -108,7 +109,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
}
private TypeInformation<?> createInfo(Optional<Type> fieldType) {
return fieldType.map(it -> createInfo(it)).orElseThrow(() -> new IllegalArgumentException());
return fieldType.map(this::createInfo).orElseThrow(IllegalArgumentException::new);
}
/**
@@ -129,7 +130,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
}
Class<S> resolveType = resolveType(fieldType);
Map<TypeVariable, Type> variableMap = new HashMap<TypeVariable, Type>();
Map<TypeVariable, Type> variableMap = new HashMap<>();
variableMap.putAll(GenericTypeResolver.getTypeVariableMap(resolveType));
if (fieldType instanceof ParameterizedType) {
@@ -183,7 +184,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
protected Class<S> resolveType(Type type) {
Map<TypeVariable, Type> map = new HashMap<TypeVariable, Type>();
Map<TypeVariable, Type> map = new HashMap<>();
map.putAll(getTypeVariableMap());
return (Class<S>) GenericTypeResolver.resolveType(type, map);
@@ -198,7 +199,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
Assert.notNull(constructor, "Constructor must not be null!");
Type[] types = constructor.getGenericParameterTypes();
List<TypeInformation<?>> result = new ArrayList<TypeInformation<?>>(types.length);
List<TypeInformation<?>> result = new ArrayList<>(types.length);
for (Type parameterType : types) {
result.add(createInfo(parameterType));
@@ -216,13 +217,13 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
int separatorIndex = fieldname.indexOf('.');
if (separatorIndex == -1) {
return fieldTypes.computeIfAbsent(fieldname, it -> getPropertyInformation(it));
return fieldTypes.computeIfAbsent(fieldname, this::getPropertyInformation);
}
String head = fieldname.substring(0, separatorIndex);
Optional<TypeInformation<?>> info = getProperty(head);
return info.map(it -> it.getProperty(fieldname.substring(separatorIndex + 1))).orElseGet(() -> Optional.empty());
return info.map(it -> it.getProperty(fieldname.substring(separatorIndex + 1))).orElseGet(Optional::empty);
}
/**
@@ -261,7 +262,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
return Optional.of(descriptor);
}
List<Class<?>> superTypes = new ArrayList<Class<?>>();
List<Class<?>> superTypes = new ArrayList<>();
superTypes.addAll(Arrays.asList(type.getInterfaces()));
superTypes.add(type.getSuperclass());
@@ -415,7 +416,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
Assert.notNull(method, "Method most not be null!");
return Streamable.of(method.getGenericParameterTypes()).stream()//
.map(it -> createInfo(it))//
.map(this::createInfo)//
.collect(Collectors.toList());
}

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.
@@ -40,6 +40,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
* @author Oliver Gierke
* @author Nick Williams
* @author Mark Paluch
* @author Christoph Strobl
*/
public class PageableHandlerMethodArgumentResolver implements PageableArgumentResolver {
@@ -252,19 +253,19 @@ public class PageableHandlerMethodArgumentResolver implements PageableArgumentRe
}
int p = page.orElseGet(
() -> defaultOrFallback.map(it -> it.getPageNumber()).orElseThrow(() -> new IllegalStateException()));
() -> defaultOrFallback.map(Pageable::getPageNumber).orElseThrow(IllegalStateException::new));
int ps = pageSize
.orElseGet(() -> defaultOrFallback.map(it -> it.getPageSize()).orElseThrow(() -> new IllegalStateException()));
.orElseGet(() -> defaultOrFallback.map(Pageable::getPageSize).orElseThrow(IllegalStateException::new));
// Limit lower bound
ps = ps < 1 ? defaultOrFallback.map(it -> it.getPageSize()).orElseThrow(() -> new IllegalStateException()) : ps;
ps = ps < 1 ? defaultOrFallback.map(Pageable::getPageSize).orElseThrow(IllegalStateException::new) : ps;
// Limit upper bound
ps = ps > maxPageSize ? maxPageSize : ps;
Sort sort = sortResolver.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
return PageRequest.of(p, ps,
sort.isSorted() ? sort : defaultOrFallback.map(it -> it.getSort()).orElseGet(() -> Sort.unsorted()));
sort.isSorted() ? sort : defaultOrFallback.map(Pageable::getSort).orElseGet(Sort::unsorted));
}
/**

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.
@@ -40,6 +40,7 @@ import org.springframework.web.util.UriComponentsBuilder;
* @since 1.6
* @author Oliver Gierke
* @author Nick Williams
* @author Christoph Strobl
*/
public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArgumentResolver {
@@ -115,7 +116,7 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg
* @param parameter must not be {@literal null}.
* @return
*/
private static final MethodParameter findMatchingPageableParameter(MethodParameter parameter) {
private static MethodParameter findMatchingPageableParameter(MethodParameter parameter) {
MethodParameters parameters = new MethodParameters(parameter.getMethod());
List<MethodParameter> pageableParameters = parameters.getParametersOfType(Pageable.class);

View File

@@ -42,6 +42,7 @@ import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
* {@link ProjectedPayload}.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @soundtrack Richard Spaven - Ice Is Nice (Spaven's 5ive)
* @since 1.13
*/
@@ -49,7 +50,7 @@ public class ProjectingJackson2HttpMessageConverter extends MappingJackson2HttpM
implements BeanClassLoaderAware, BeanFactoryAware {
private final SpelAwareProxyProjectionFactory projectionFactory;
private final Map<Class<?>, Boolean> supportedTypesCache = new ConcurrentReferenceHashMap<Class<?>, Boolean>();
private final Map<Class<?>, Boolean> supportedTypesCache = new ConcurrentReferenceHashMap<>();
/**
* Creates a new {@link ProjectingJackson2HttpMessageConverter} using a default {@link ObjectMapper}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 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.
@@ -42,6 +42,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
* @author Thomas Darimont
* @author Nick Williams
* @author Mark Paluch
* @author Christoph Strobl
*/
public class SortHandlerMethodArgumentResolver implements SortArgumentResolver {
@@ -208,7 +209,7 @@ public class SortHandlerMethodArgumentResolver implements SortArgumentResolver {
*/
Sort parseParameterIntoSort(String[] source, String delimiter) {
List<Order> allOrders = new ArrayList<Sort.Order>();
List<Order> allOrders = new ArrayList<>();
for (String part : source) {
@@ -224,7 +225,7 @@ public class SortHandlerMethodArgumentResolver implements SortArgumentResolver {
int lastIndex = direction.map(it -> elements.length - 1).orElseGet(() -> elements.length);
for (int i = 0; i < lastIndex; i++) {
toOrder(elements[i], direction).ifPresent(it -> allOrders.add(it));
toOrder(elements[i], direction).ifPresent(allOrders::add);
}
}
@@ -266,7 +267,7 @@ public class SortHandlerMethodArgumentResolver implements SortArgumentResolver {
builder.add(order.getProperty());
}
return builder == null ? Collections.<String>emptyList() : builder.dumpExpressionIfPresentInto(expressions);
return builder == null ? Collections.emptyList() : builder.dumpExpressionIfPresentInto(expressions);
}
/**
@@ -296,7 +297,7 @@ public class SortHandlerMethodArgumentResolver implements SortArgumentResolver {
builder.add(order.getProperty());
}
return builder == null ? Collections.<String>emptyList() : builder.dumpExpressionIfPresentInto(expressions);
return builder == null ? Collections.emptyList() : builder.dumpExpressionIfPresentInto(expressions);
}
/**

View File

@@ -35,13 +35,14 @@ import org.xmlbeam.XBProjector;
* A read-only {@link HttpMessageConverter} to create XMLBeam-based projection instances for interfaces.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @see <a href="http://www.xmlbeam.org">http://www.xmlbeam.org</a>
* @soundtrack Dr. Kobayashi Maru & The Mothership Connection - Anthem (EPisode One)
*/
public class XmlBeamHttpMessageConverter extends AbstractHttpMessageConverter<Object> {
private final ProjectionFactory projectionFactory;
private final Map<Class<?>, Boolean> supportedTypesCache = new ConcurrentReferenceHashMap<Class<?>, Boolean>();
private final Map<Class<?>, Boolean> supportedTypesCache = new ConcurrentReferenceHashMap<>();
/**
* Creates a new {@link XmlBeamHttpMessageConverter}.

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.
@@ -93,7 +93,7 @@ public class QuerydslPredicateArgumentResolver implements HandlerMethodArgumentR
public Predicate resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
for (Entry<String, String[]> entry : webRequest.getParameterMap().entrySet()) {
parameters.put(entry.getKey(), Arrays.asList(entry.getValue()));
@@ -104,7 +104,7 @@ public class QuerydslPredicateArgumentResolver implements HandlerMethodArgumentR
TypeInformation<?> domainType = extractTypeInfo(parameter).getActualType();
Optional<? extends Class<? extends QuerydslBinderCustomizer>> map = annotation
.<Class<? extends QuerydslBinderCustomizer>>map(it -> it.bindings());
.<Class<? extends QuerydslBinderCustomizer>>map(QuerydslPredicate::bindings);
QuerydslBindings bindings = bindingsFactory.createBindingsFor(domainType,
(Optional<Class<? extends QuerydslBinderCustomizer<?>>>) map);