Browse Source

DATACMNS-1433 - Added additional Streamable.and(…) flavors for convenience.

Removed superfluous Streamable creation from DefaultImplementationlookupConfiguration.
pull/325/head
Oliver Drotbohm 7 years ago
parent
commit
a3a5c8e484
No known key found for this signature in database
GPG Key ID: 6E42B5787543F690
  1. 2
      src/main/java/org/springframework/data/repository/config/DefaultImplementationLookupConfiguration.java
  2. 43
      src/main/java/org/springframework/data/util/Streamable.java
  3. 15
      src/test/java/org/springframework/data/util/StreamableUnitTests.java

2
src/main/java/org/springframework/data/repository/config/DefaultImplementationLookupConfiguration.java

@ -82,7 +82,7 @@ class DefaultImplementationLookupConfiguration implements ImplementationLookupCo @@ -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));
}
/*

43
src/main/java/org/springframework/data/util/Streamable.java

@ -17,6 +17,8 @@ package org.springframework.data.util; @@ -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>> { @@ -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}.
*

15
src/test/java/org/springframework/data/util/StreamableUnitTests.java

@ -38,4 +38,19 @@ public class StreamableUnitTests { @@ -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);
}
}

Loading…
Cancel
Save