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