diff --git a/src/main/java/org/cqfn/astranaut/core/algorithms/Depth.java b/src/main/java/org/cqfn/astranaut/core/algorithms/DepthCalculator.java similarity index 97% rename from src/main/java/org/cqfn/astranaut/core/algorithms/Depth.java rename to src/main/java/org/cqfn/astranaut/core/algorithms/DepthCalculator.java index f52c8c5..a8950c1 100644 --- a/src/main/java/org/cqfn/astranaut/core/algorithms/Depth.java +++ b/src/main/java/org/cqfn/astranaut/core/algorithms/DepthCalculator.java @@ -32,7 +32,7 @@ * * @since 1.1.0 */ -public final class Depth { +public final class DepthCalculator { /** * A table with the calculated values. * Since nodes are immutable, depth calculated once for a node will never change. @@ -42,7 +42,7 @@ public final class Depth { /** * Constructor. */ - public Depth() { + public DepthCalculator() { this.calculated = new HashMap<>(); } diff --git a/src/main/java/org/cqfn/astranaut/core/algorithms/DeepTraversal.java b/src/main/java/org/cqfn/astranaut/core/algorithms/DepthFirstWalker.java similarity index 90% rename from src/main/java/org/cqfn/astranaut/core/algorithms/DeepTraversal.java rename to src/main/java/org/cqfn/astranaut/core/algorithms/DepthFirstWalker.java index 6244ba6..0fcbd56 100644 --- a/src/main/java/org/cqfn/astranaut/core/algorithms/DeepTraversal.java +++ b/src/main/java/org/cqfn/astranaut/core/algorithms/DepthFirstWalker.java @@ -29,11 +29,11 @@ import org.cqfn.astranaut.core.base.Node; /** - * Performs a deep traversal of the syntax tree. + * Performs a depth-first traversal of the syntax tree. * * @since 1.1.5 */ -public class DeepTraversal { +public class DepthFirstWalker { /** * The root node of the tree being traversed. */ @@ -43,7 +43,7 @@ public class DeepTraversal { * Constructor. * @param root The root node of the tree being traversed */ - public DeepTraversal(final Node root) { + public DepthFirstWalker(final Node root) { this.root = root; } @@ -58,7 +58,7 @@ public DeepTraversal(final Node root) { * @return Found node (optional) */ public Optional findFirst(final Visitor visitor) { - return Optional.ofNullable(DeepTraversal.findFirst(this.root, visitor)); + return Optional.ofNullable(DepthFirstWalker.findFirst(this.root, visitor)); } /** @@ -70,7 +70,7 @@ public Optional findFirst(final Visitor visitor) { */ public List findAll(final Visitor visitor) { final List list = new ArrayList<>(0); - DeepTraversal.findAll(this.root, visitor, list); + DepthFirstWalker.findAll(this.root, visitor, list); return list; } @@ -88,7 +88,7 @@ private static Node findFirst(final Node node, final Visitor visitor) { } else { final int count = node.getChildCount(); for (int index = 0; index < count && result == null; index = index + 1) { - result = DeepTraversal.findFirst(node.getChild(index), visitor); + result = DepthFirstWalker.findFirst(node.getChild(index), visitor); } } return result; @@ -107,7 +107,7 @@ private static void findAll(final Node node, final Visitor visitor, final List> get() { + public Set> find() { final Map> result = new HashMap<>(); this.search(this.root, result); return result.values() diff --git a/src/main/java/org/cqfn/astranaut/core/algorithms/ReplaceNode.java b/src/main/java/org/cqfn/astranaut/core/algorithms/NodeReplacer.java similarity index 99% rename from src/main/java/org/cqfn/astranaut/core/algorithms/ReplaceNode.java rename to src/main/java/org/cqfn/astranaut/core/algorithms/NodeReplacer.java index 5e31749..78799d7 100644 --- a/src/main/java/org/cqfn/astranaut/core/algorithms/ReplaceNode.java +++ b/src/main/java/org/cqfn/astranaut/core/algorithms/NodeReplacer.java @@ -35,7 +35,7 @@ * * @since 1.0 */ -public class ReplaceNode { +public class NodeReplacer { /** * Replaces a subtree of the initial tree with the newly created subtree. * @param tree The initial tree diff --git a/src/main/java/org/cqfn/astranaut/core/algorithms/Subtree.java b/src/main/java/org/cqfn/astranaut/core/algorithms/SubtreeBuilder.java similarity index 98% rename from src/main/java/org/cqfn/astranaut/core/algorithms/Subtree.java rename to src/main/java/org/cqfn/astranaut/core/algorithms/SubtreeBuilder.java index d0a8eb7..810d8bf 100644 --- a/src/main/java/org/cqfn/astranaut/core/algorithms/Subtree.java +++ b/src/main/java/org/cqfn/astranaut/core/algorithms/SubtreeBuilder.java @@ -38,7 +38,7 @@ * * @since 1.1.4 */ -public class Subtree { +public class SubtreeBuilder { /** * Algorithm that composes a subtree only from the nodes that are specified in the set. */ @@ -66,7 +66,7 @@ public class Subtree { * @param root The root node of the original tree * @param algorithm Algorithm that selects nodes based on some criteria */ - public Subtree(final Node root, final Algorithm algorithm) { + public SubtreeBuilder(final Node root, final Algorithm algorithm) { this.root = root; this.algorithm = algorithm; } diff --git a/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java b/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java index 657572a..b4058d0 100644 --- a/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java +++ b/src/main/java/org/cqfn/astranaut/core/algorithms/patching/Matcher.java @@ -27,7 +27,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.cqfn.astranaut.core.algorithms.DeepTraversal; +import org.cqfn.astranaut.core.algorithms.DepthFirstWalker; import org.cqfn.astranaut.core.base.Action; import org.cqfn.astranaut.core.base.ActionList; import org.cqfn.astranaut.core.base.Delete; @@ -78,7 +78,7 @@ public ActionList getActionList() { * @return Nodes that match the root node of the pattern */ Set match(final Pattern pattern) { - final DeepTraversal deep = new DeepTraversal(this.root); + final DepthFirstWalker deep = new DepthFirstWalker(this.root); final PatternNode head = pattern.getRoot(); final List preset = deep.findAll( node -> node.getTypeName().equals(head.getTypeName()) diff --git a/src/test/java/org/cqfn/astranaut/core/algorithms/DepthTest.java b/src/test/java/org/cqfn/astranaut/core/algorithms/DepthCalculatorTest.java similarity index 92% rename from src/test/java/org/cqfn/astranaut/core/algorithms/DepthTest.java rename to src/test/java/org/cqfn/astranaut/core/algorithms/DepthCalculatorTest.java index 2d6a92c..b300eda 100644 --- a/src/test/java/org/cqfn/astranaut/core/algorithms/DepthTest.java +++ b/src/test/java/org/cqfn/astranaut/core/algorithms/DepthCalculatorTest.java @@ -29,15 +29,15 @@ import org.junit.jupiter.api.Test; /** - * Testing {@link Depth} class. + * Testing {@link DepthCalculator} class. * * @since 1.1.0 */ -class DepthTest { +class DepthCalculatorTest { @Test void test() { final DiffTree tree = LittleTrees.createTreeWithDeleteAction(); - final Depth depth = new Depth(); + final DepthCalculator depth = new DepthCalculator(); int value = depth.calculate(tree.getRoot()); Assertions.assertEquals(5, value); value = depth.calculate(tree.getRoot().getChild(0)); diff --git a/src/test/java/org/cqfn/astranaut/core/algorithms/DeepTraversalTest.java b/src/test/java/org/cqfn/astranaut/core/algorithms/DepthFirstWalkerTest.java similarity index 87% rename from src/test/java/org/cqfn/astranaut/core/algorithms/DeepTraversalTest.java rename to src/test/java/org/cqfn/astranaut/core/algorithms/DepthFirstWalkerTest.java index 0efbd7b..cfa1e44 100644 --- a/src/test/java/org/cqfn/astranaut/core/algorithms/DeepTraversalTest.java +++ b/src/test/java/org/cqfn/astranaut/core/algorithms/DepthFirstWalkerTest.java @@ -31,15 +31,15 @@ import org.junit.jupiter.api.Test; /** - * Testing {@link DeepTraversal} class. + * Testing {@link DepthFirstWalker} class. * * @since 1.1.5 */ -class DeepTraversalTest { +class DepthFirstWalkerTest { @Test void testFindFirst() { final Node root = DraftNode.create("A(B,C,D(E<\"eee\">,F<\"fff\">)))"); - final DeepTraversal traversal = new DeepTraversal(root); + final DepthFirstWalker traversal = new DepthFirstWalker(root); final Optional node = traversal.findFirst(node1 -> !node1.getData().isEmpty()); Assertions.assertTrue(node.isPresent()); Assertions.assertEquals("E", node.get().getTypeName()); @@ -48,7 +48,7 @@ void testFindFirst() { @Test void testNotFoundFirst() { final Node root = DraftNode.create("A(B,C,D)"); - final DeepTraversal traversal = new DeepTraversal(root); + final DepthFirstWalker traversal = new DepthFirstWalker(root); final Optional node = traversal.findFirst(node1 -> !node1.getData().isEmpty()); Assertions.assertFalse(node.isPresent()); } @@ -56,7 +56,7 @@ void testNotFoundFirst() { @Test void testFindAll() { final Node root = DraftNode.create("A(B,C<\"ccc\">,D(E<\"eee\">)))"); - final DeepTraversal traversal = new DeepTraversal(root); + final DepthFirstWalker traversal = new DepthFirstWalker(root); final List list = traversal.findAll(node1 -> !node1.getData().isEmpty()); Assertions.assertNotNull(list); Assertions.assertEquals(2, list.size()); @@ -65,7 +65,7 @@ void testFindAll() { @Test void testFindNothing() { final Node root = DraftNode.create("A(X,Y,Z)"); - final DeepTraversal traversal = new DeepTraversal(root); + final DepthFirstWalker traversal = new DepthFirstWalker(root); final List list = traversal.findAll(node1 -> !node1.getData().isEmpty()); Assertions.assertNotNull(list); Assertions.assertTrue(list.isEmpty()); diff --git a/src/test/java/org/cqfn/astranaut/core/algorithms/IdenticalTest.java b/src/test/java/org/cqfn/astranaut/core/algorithms/IdenticalNodeFinderTest.java similarity index 80% rename from src/test/java/org/cqfn/astranaut/core/algorithms/IdenticalTest.java rename to src/test/java/org/cqfn/astranaut/core/algorithms/IdenticalNodeFinderTest.java index 7aa5e0d..02f184e 100644 --- a/src/test/java/org/cqfn/astranaut/core/algorithms/IdenticalTest.java +++ b/src/test/java/org/cqfn/astranaut/core/algorithms/IdenticalNodeFinderTest.java @@ -30,18 +30,18 @@ import org.junit.jupiter.api.Test; /** - * Tests for {@link Identical} class. + * Tests for {@link IdenticalNodeFinder} class. * * @since 1.1.5 */ -class IdenticalTest { +class IdenticalNodeFinderTest { @Test void testIdenticalSets() { final Node original = DraftNode.create( "T<\"a\">(T<\"b\">,T<\"c\">(F<\"a\">,T<\"b\">,T<\"a\">,F<\"a\">))" ); - final Identical identical = new Identical(original); - final Set> identicals = identical.get(); + final IdenticalNodeFinder identical = new IdenticalNodeFinder(original); + final Set> identicals = identical.find(); Assertions.assertEquals(3, identicals.size()); } @@ -50,8 +50,8 @@ void testNoIdenticals() { final Node original = DraftNode.create( "T<\"a\">(T<\"b\">,T<\"c\">(F<\"a\">,F<\"b\">,F<\"c\">,K<\"a\">))" ); - final Identical identical = new Identical(original); - final Set> identicals = identical.get(); + final IdenticalNodeFinder identical = new IdenticalNodeFinder(original); + final Set> identicals = identical.find(); Assertions.assertEquals(0, identicals.size()); } @@ -60,8 +60,8 @@ void testIdenticalsAndEmptyData() { final Node original = DraftNode.create( "T<\"a\">(T<\"b\">,T<\"c\">(F<\"a\">,T<\"b\">,T<\"a\">,F,F,T))" ); - final Identical identical = new Identical(original); - final Set> identicals = identical.get(); + final IdenticalNodeFinder identical = new IdenticalNodeFinder(original); + final Set> identicals = identical.find(); Assertions.assertEquals(2, identicals.size()); } } diff --git a/src/test/java/org/cqfn/astranaut/core/algorithms/NodeReplacerTest.java b/src/test/java/org/cqfn/astranaut/core/algorithms/NodeReplacerTest.java index 7476621..f96769a 100644 --- a/src/test/java/org/cqfn/astranaut/core/algorithms/NodeReplacerTest.java +++ b/src/test/java/org/cqfn/astranaut/core/algorithms/NodeReplacerTest.java @@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test; /** - * Test for {@link ReplaceNode} class. + * Test for {@link NodeReplacer} class. * * @since 1.0 */ @@ -73,7 +73,7 @@ void testReplacementOfRoot() { ) ); final Node target = this.createTargetTree(); - final Pair result = new ReplaceNode().replace(root, root, target); + final Pair result = new NodeReplacer().replace(root, root, target); Assertions.assertEquals(target, result.getKey()); Assertions.assertEquals(-1, result.getValue()); } @@ -116,7 +116,7 @@ void testReplacementOfRootChild() { source ); final Node target = this.createTargetTree(); - final Pair result = new ReplaceNode().replace(root, source, target); + final Pair result = new NodeReplacer().replace(root, source, target); Assertions.assertEquals(target, result.getKey().getChild(2)); Assertions.assertEquals(2, result.getValue()); } @@ -157,7 +157,7 @@ void testReplacementOfRootGrandChild() { ) ); final Node target = this.createTargetTree(); - final Pair result = new ReplaceNode().replace(root, source, target); + final Pair result = new NodeReplacer().replace(root, source, target); Assertions.assertEquals(target, result.getKey().getChild(2).getChild(0)); Assertions.assertEquals(left, result.getKey().getChild(0)); Assertions.assertEquals(mid, result.getKey().getChild(1)); @@ -178,7 +178,7 @@ void testReplacementWithoutMatch() { ); final Node source = this.createNode("444", ""); final Node target = this.createTargetTree(); - final Pair result = new ReplaceNode().replace(root, source, target); + final Pair result = new NodeReplacer().replace(root, source, target); Assertions.assertEquals(DummyNode.INSTANCE, result.getKey()); Assertions.assertEquals(-1, result.getValue()); } diff --git a/src/test/java/org/cqfn/astranaut/core/algorithms/PatternBuilderTest.java b/src/test/java/org/cqfn/astranaut/core/algorithms/PatternBuilderTest.java index 2f00ffc..c677933 100644 --- a/src/test/java/org/cqfn/astranaut/core/algorithms/PatternBuilderTest.java +++ b/src/test/java/org/cqfn/astranaut/core/algorithms/PatternBuilderTest.java @@ -70,7 +70,7 @@ void creatingPatternWithHole() { builder.makeHole(first, 1); final Pattern pattern = builder.getPattern(); Assertions.assertNotNull(pattern); - final DeepTraversal traversal = new DeepTraversal(pattern.getRoot()); + final DepthFirstWalker traversal = new DepthFirstWalker(pattern.getRoot()); final Optional hole = traversal.findFirst(node -> node instanceof Hole); Assertions.assertTrue(hole.isPresent()); Assertions.assertEquals("#1", hole.get().getData()); diff --git a/src/test/java/org/cqfn/astranaut/core/algorithms/SubtreeTest.java b/src/test/java/org/cqfn/astranaut/core/algorithms/SubtreeBuilderTest.java similarity index 87% rename from src/test/java/org/cqfn/astranaut/core/algorithms/SubtreeTest.java rename to src/test/java/org/cqfn/astranaut/core/algorithms/SubtreeBuilderTest.java index 0b7cb9e..924d253 100644 --- a/src/test/java/org/cqfn/astranaut/core/algorithms/SubtreeTest.java +++ b/src/test/java/org/cqfn/astranaut/core/algorithms/SubtreeBuilderTest.java @@ -34,18 +34,18 @@ import org.junit.jupiter.api.Test; /** - * Test for {@link Subtree}. + * Test for {@link SubtreeBuilder}. * * @since 1.1.4 */ -class SubtreeTest { +class SubtreeBuilderTest { @Test void testSubtreeCreation() { final Node original = DraftNode.create("A(B,C(D,E,F))"); final List list = Arrays.asList("A", "C", "E", "F"); final Set selected = new NodeSelector(original).select((node, parents) -> list.contains(node.getTypeName())); - final Subtree algorithm = new Subtree(original, Subtree.INCLUDE); + final SubtreeBuilder algorithm = new SubtreeBuilder(original, SubtreeBuilder.INCLUDE); final Node subtree = algorithm.create(selected); final Node expected = DraftNode.create("A(C(E,F))"); Assertions.assertTrue(expected.deepCompare(subtree)); @@ -54,7 +54,7 @@ void testSubtreeCreation() { @Test void testUsingOneSubtreeInstanceForCreatingTwoSubtrees() { final Node original = DraftNode.create("X(A,B,C,D,E)"); - final Subtree algorithm = new Subtree(original, Subtree.INCLUDE); + final SubtreeBuilder algorithm = new SubtreeBuilder(original, SubtreeBuilder.INCLUDE); final Node first = algorithm.create( new HashSet<>( Arrays.asList( @@ -86,7 +86,7 @@ void testingParametersThatProduceEmptyTree() { DraftNode.create("E") ) ); - final Subtree algorithm = new Subtree(original, Subtree.INCLUDE); + final SubtreeBuilder algorithm = new SubtreeBuilder(original, SubtreeBuilder.INCLUDE); final Node subtree = algorithm.create(set); Assertions.assertSame(subtree, DummyNode.INSTANCE); } @@ -96,7 +96,7 @@ void testingParametersThatProduceTreeIdenticalToOriginal() { final Node original = DraftNode.create("X(A,B,C,D(E,F))"); final Set selected = new NodeSelector(original).select((node, parents) -> true); - final Subtree algorithm = new Subtree(original, Subtree.INCLUDE); + final SubtreeBuilder algorithm = new SubtreeBuilder(original, SubtreeBuilder.INCLUDE); final Node subtree = algorithm.create(selected); Assertions.assertTrue(original.deepCompare(subtree)); } @@ -111,7 +111,7 @@ void testSubtreeCreationWithExcludedNodes() { return name.equals("B") || name.equals("E"); } ); - final Subtree algorithm = new Subtree(original, Subtree.EXCLUDE); + final SubtreeBuilder algorithm = new SubtreeBuilder(original, SubtreeBuilder.EXCLUDE); final Node subtree = algorithm.create(selected); final Node expected = DraftNode.create("A(C(D,F))"); Assertions.assertTrue(expected.deepCompare(subtree)); @@ -122,7 +122,7 @@ void testSubtreeCreationWhenAllNodesAreExcluded() { final Node original = DraftNode.create("X(A,B,C(D,E))"); final Set selected = new NodeSelector(original).select((node, parents) -> true); - final Subtree algorithm = new Subtree(original, Subtree.EXCLUDE); + final SubtreeBuilder algorithm = new SubtreeBuilder(original, SubtreeBuilder.EXCLUDE); final Node subtree = algorithm.create(selected); Assertions.assertSame(subtree, DummyNode.INSTANCE); }