From 6546881559e4bbcfe2b220199a9f3cd4196d1960 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Tue, 9 Jun 2015 23:58:41 +1000 Subject: A few changes, as suggested by static analysis --- .../java/au/id/zancanaro/javacheck/ShrinkTree.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 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 4f4eb62..6e21f27 100644 --- a/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java +++ b/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java @@ -52,7 +52,7 @@ public class ShrinkTree { return heads; } - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "SuspiciousUninitializedArray"}) public static Stream[]> promoteChildren(ShrinkTree[] trees) { return IntStream.range(0, trees.length) .mapToObj(index -> trees[index].getChildren().map(child -> @@ -65,10 +65,11 @@ public class ShrinkTree { public static Stream[]> removeChildren(ShrinkTree[] trees) { return IntStream.range(0, trees.length) - .mapToObj(index -> IntStream.range(0, trees.length) - .filter(i -> i != index) - .mapToObj(i -> trees[i]) - .toArray(ShrinkTree[]::new)); + .mapToObj(index -> + IntStream.range(0, trees.length) + .filter(i -> i != index) + .mapToObj(i -> trees[i]) + .toArray(ShrinkTree[]::new)); } public static Stream[]> removeAndPromoteChildren(ShrinkTree[] trees) { @@ -90,14 +91,15 @@ public class ShrinkTree { () -> 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) { - if (predicate.test(this.getValue())) { + T value = this.getValue(); + if (predicate.test(value)) { return new ShrinkTree<>( - this.getValue(), + value, () -> this.getChildren() .filter(tree -> predicate.test(tree.getValue())) .map(tree -> tree.filter(predicate))); @@ -112,7 +114,7 @@ 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))); + .map(v -> new ShrinkTree<>(v, () -> strategyStream(v, strategy))); } public void print(Writer output) throws IOException { -- cgit v1.2.3