DATACMNS-1433 - Added additional Streamable.and(…) flavors for convenience.
Removed superfluous Streamable creation from DefaultImplementationlookupConfiguration.
This commit is contained in:
@@ -82,7 +82,7 @@ class DefaultImplementationLookupConfiguration implements ImplementationLookupCo
|
||||
*/
|
||||
@Override
|
||||
public Streamable<TypeFilter> getExcludeFilters() {
|
||||
return config.getExcludeFilters().and(Streamable.of(new AnnotationTypeFilter(NoRepositoryBean.class)));
|
||||
return config.getExcludeFilters().and(new AnnotationTypeFilter(NoRepositoryBean.class));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
@@ -146,6 +148,47 @@ public interface Streamable<T> extends Iterable<T>, Supplier<Stream<T>> {
|
||||
return Streamable.of(() -> Stream.concat(this.stream(), stream.get()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Streamable} from the current one and the given values concatenated.
|
||||
*
|
||||
* @param others must not be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default Streamable<T> and(T... others) {
|
||||
|
||||
Assert.notNull(others, "Other values must not be null!");
|
||||
|
||||
return Streamable.of(() -> Stream.concat(this.stream(), Arrays.stream(others)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Streamable} from the current one and the given {@link Iterable} concatenated.
|
||||
*
|
||||
* @param iterable must not be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
default Streamable<T> and(Iterable<? extends T> iterable) {
|
||||
|
||||
Assert.notNull(iterable, "Iterable must not be null!");
|
||||
|
||||
return Streamable.of(() -> Stream.concat(this.stream(), StreamSupport.stream(iterable.spliterator(), false)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to allow adding a {@link Streamable} directly as otherwise the invocation is ambiguous between
|
||||
* {@link #and(Iterable)} and {@link #and(Supplier)}.
|
||||
*
|
||||
* @param streamable must not be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
default Streamable<T> and(Streamable<? extends T> streamable) {
|
||||
return and((Supplier<? extends Stream<? extends T>>) streamable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new, unmodifiable {@link List}.
|
||||
*
|
||||
|
||||
@@ -38,4 +38,19 @@ public class StreamableUnitTests {
|
||||
assertThat(streamable.toList()).containsExactly(1, 2, 1);
|
||||
assertThat(streamable.toSet()).containsExactlyInAnyOrder(1, 2);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1433
|
||||
public void concatenatesIterable() {
|
||||
assertThat(Streamable.of(1, 2).and(Arrays.asList(3, 4))).containsExactly(1, 2, 3, 4);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1433
|
||||
public void concatenatesVarargs() {
|
||||
assertThat(Streamable.of(1, 2).and(3, 4)).containsExactly(1, 2, 3, 4);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1433
|
||||
public void concatenatesStreamable() {
|
||||
assertThat(Streamable.of(1, 2).and(Streamable.of(3, 4))).containsExactly(1, 2, 3, 4);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user