DATACMNS-1275 - Introduced MappingContext.findPersistentPropertyPaths(Class<?>, Predicate<P>).
MappingContext now exposes a method to detect all property paths pointing to properties matching a given predicate. Extracted PersistentPropertyPath creation into a dedicated factory class so that it can be tested individually. DefaultPersistentPropertyPath now exposes a ….containsPropertyOfType(…) to detect whether we've already processed a particular type in the path. Also applied a bit of Java 8 and Lombok polish. InvalidPersistentPropertyPath now collects suggested alternatives to create a better exception message. PersistentEntities now allows to map over a MappingContext and PersistentEntity that a given type is corresponding to. Streamable now exposes an ….isEmpty(). Removed references to equivalent methods implemented in subtypes.
This commit is contained in:
@@ -23,6 +23,9 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.Spliterators.AbstractSpliterator;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Stream;
|
||||
@@ -107,4 +110,39 @@ public interface StreamUtils {
|
||||
public static <T> Stream<T> fromNullable(@Nullable T source) {
|
||||
return source == null ? Stream.empty() : Stream.of(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zips the given {@link Stream}s using the given {@link BiFunction}. The resulting {@link Stream} will have the
|
||||
* length of the shorter of the two, abbreviating the zipping when the shorter of the two {@link Stream}s is
|
||||
* exhausted.
|
||||
*
|
||||
* @param left must not be {@literal null}.
|
||||
* @param right must not be {@literal null}.
|
||||
* @param combiner must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.1
|
||||
*/
|
||||
public static <L, R, T> Stream<T> zip(Stream<L> left, Stream<R> right, BiFunction<L, R, T> combiner) {
|
||||
|
||||
Assert.notNull(left, "Left stream must not be null!");
|
||||
Assert.notNull(right, "Right must not be null!");
|
||||
Assert.notNull(combiner, "Combiner must not be null!");
|
||||
|
||||
Spliterator<L> lefts = left.spliterator();
|
||||
Spliterator<R> rights = right.spliterator();
|
||||
|
||||
long size = Long.min(lefts.estimateSize(), rights.estimateSize());
|
||||
int characteristics = lefts.characteristics() & rights.characteristics();
|
||||
boolean parallel = left.isParallel() || right.isParallel();
|
||||
|
||||
return StreamSupport.stream(new AbstractSpliterator<T>(size, characteristics) {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("null")
|
||||
public boolean tryAdvance(Consumer<? super T> action) {
|
||||
return lefts.tryAdvance(left -> rights.tryAdvance(right -> action.accept(combiner.apply(left, right))));
|
||||
}
|
||||
|
||||
}, parallel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,4 +121,13 @@ public interface Streamable<T> extends Iterable<T> {
|
||||
|
||||
return Streamable.of(() -> stream().filter(predicate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current {@link Streamable} is empty.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default boolean isEmpty() {
|
||||
return !iterator().hasNext();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user