From 405af698aa80e22b7f1d1596dfbb796a3c882011 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Thu, 4 Jun 2015 23:35:23 +1000 Subject: Fix up generic types by adding bounds where possible instead of rigid constraints --- src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java') diff --git a/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java b/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java index 4337c14..4f4eb62 100644 --- a/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java +++ b/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java @@ -53,7 +53,7 @@ public class ShrinkTree { } @SuppressWarnings("unchecked") - public static Stream[]> promoteChildren(ShrinkTree[] trees) { + public static Stream[]> promoteChildren(ShrinkTree[] trees) { return IntStream.range(0, trees.length) .mapToObj(index -> trees[index].getChildren().map(child -> IntStream.range(0, trees.length) @@ -63,7 +63,7 @@ public class ShrinkTree { .map(x -> (ShrinkTree[]) x); } - public static Stream[]> removeChildren(ShrinkTree[] trees) { + public static Stream[]> removeChildren(ShrinkTree[] trees) { return IntStream.range(0, trees.length) .mapToObj(index -> IntStream.range(0, trees.length) .filter(i -> i != index) @@ -71,7 +71,7 @@ public class ShrinkTree { .toArray(ShrinkTree[]::new)); } - public static Stream[]> removeAndPromoteChildren(ShrinkTree[] trees) { + public static Stream[]> removeAndPromoteChildren(ShrinkTree[] trees) { return Stream.concat(removeChildren(trees), promoteChildren(trees)); } @@ -84,17 +84,17 @@ public class ShrinkTree { .map(shrinks -> combine(shrinks, processChildren))); } - public ShrinkTree map(Function f) { + public ShrinkTree map(Function f) { return new ShrinkTree<>( f.apply(this.value), () -> this.getChildren().map(tree -> tree.map(f))); } - public ShrinkTree flatMap(Function> f) { + public ShrinkTree flatMap(Function> f) { return ShrinkTree.join(this.map(f)); } - public ShrinkTree filter(Predicate predicate) { + public ShrinkTree filter(Predicate predicate) { if (predicate.test(this.getValue())) { return new ShrinkTree<>( this.getValue(), @@ -111,14 +111,15 @@ public class ShrinkTree { } private static Stream> strategyStream(final T value, final ShrinkStrategy strategy) { - return strategy.shrink(value).map(v -> new ShrinkTree<>(v, () -> strategyStream(v, strategy))); + return strategy.shrink(value) + .map(v -> new ShrinkTree(v, () -> strategyStream(v, strategy))); } public void print(Writer output) throws IOException { print(output, Object::toString); } - public void print(Writer output, Function toString) throws IOException { + public void print(Writer output, Function toString) throws IOException { output.write(toString.apply(this.getValue())); output.write('['); Iterator> iterator = children.get().iterator(); -- cgit v1.2.3