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