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/Generator.java | 6 +++--- src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/au/id/zancanaro/javacheck/Generator.java b/src/main/java/au/id/zancanaro/javacheck/Generator.java index 5a8fec3..24c23ca 100644 --- a/src/main/java/au/id/zancanaro/javacheck/Generator.java +++ b/src/main/java/au/id/zancanaro/javacheck/Generator.java @@ -111,7 +111,7 @@ public interface Generator { * @param The result of the transformation * @return A new generator resulting from mapping f over this */ - default Generator map(Function f) { + default Generator map(Function f) { return (random, size) -> this.generate(random, size).map(f); } @@ -127,7 +127,7 @@ public interface Generator { * @return A new generator resulting from calling the provided action on the * result of this */ - default Generator flatMap(Function> action) { + default Generator flatMap(Function> action) { return (random, size) -> ShrinkTree.join( this.generate(random, size) .map(action @@ -148,7 +148,7 @@ public interface Generator { * @return A new generator resulting from filtering this generator to only * terms which match the given predicate */ - default Generator suchThat(Predicate predicate) { + default Generator suchThat(Predicate predicate) { return (random, size) -> { ShrinkTree result = this.generate(random, size); if (predicate.test(result.getValue())) { 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