Repository: decorators-squad/eo-yaml
Pull request #168 (2020-03-09 18:20:48)

For #165 Redesigned implementations of YamlLines
PR for #165 
Pretty big redesign of the ``YamlLines`` implementation. 

* dropped ``AbstractYamlLines`` in favor of default methods to ``YamlLines`` interface
* Separated iteration logic:
    - ``AllYamlLines`` iterates over all the lines, irrespective to indentation
    - ``SameIndentationLevel`` iterates only over the lines at the same indentation level with the first one.
* Left puzzle for proper testing of ``YamlLines`` printing/indentation.

This refactoring was needed since the previous ``RtYamlLines``, used in every place, was iterating only over the lines with the same indentation level (what SameIndentationLevel will do from now on). This was not correct, there are cases where we need to take all the lines into account. 

Dropped ``OrderedYamlLines`` in favor of a better design (will be done in #166).


Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/AbstractYamlLines.java b/src/main/java/com/amihaiemil/eoyaml/AllYamlLines.java
similarity index 76%
rename from src/main/java/com/amihaiemil/eoyaml/AbstractYamlLines.java
rename to src/main/java/com/amihaiemil/eoyaml/AllYamlLines.java
index 89cef39..d93be12 100644
--- a/src/main/java/com/amihaiemil/eoyaml/AbstractYamlLines.java
+++ b/src/main/java/com/amihaiemil/eoyaml/AllYamlLines.java
@@ -27,43 +27,54 @@
  */
 package com.amihaiemil.eoyaml;
 
+import java.util.Collection;
+
 /**
- * Iterable yaml lines.
+ * YamlLines default implementation. "All" refers to the fact that
+ * we iterate over all of them, irrespective of indentation. There
+ * are cases where we need to iterate only over the lines which are
+ * at the same indentation level and for that we use the decorator
+ * {@link SameIndentationLevel}.
  * @author Mihai Andronache (amihaiemil@gmail.com)
  * @version $Id$
  * @since 1.0.0
  */
-abstract class AbstractYamlLines implements Iterable<YamlLine> {
+final class AllYamlLines implements YamlLines {
 
     /**
-     * Lines which are nested after the given YamlLine (lines which are
-     * <br> indented by 2 or more spaces beneath it).
-     * @param after Number of a YamlLine
-     * @return YamlLines
+     * Yaml lines.
      */
-    abstract AbstractYamlLines nested(final int after);
+    private Collection<YamlLine> lines;
 
     /**
-     * Number of lines.
-     * @return Integer.
+     * Ctor.
+     * @param lines Yaml lines collection.
      */
-    abstract int count();
+    AllYamlLines(final Collection<YamlLine> lines) {
+        this.lines = lines;
+    }
 
-    /**
-     * Indent these lines.
-     * @param indentation Spaces to precede each line.
-     * @return String with the pretty-printed, indented lines.
-     */
-    abstract String indent(int indentation);
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder();
+        for (final YamlLine line : this.lines) {
+            builder.append(line.toString()).append("\n");
+        }
+        return builder.toString();
+    }
 
-    /**
-     * Turn these lines into a YamlNode.
-     * @param prev Previous YamlLine
-     * @return YamlNode
-     * @todo #107:30min/DEV Add more tests to cover all the nested node
-     *  possibilities.
-     */
-    YamlNode toYamlNode(final YamlLine prev) {
+    @Override
+    public Collection<YamlLine> lines() {
+        return this.lines;
+    }
+    
+    @Override
+    public int count() {
+        return this.lines.size();
+    }
+
+    @Override
+    public YamlNode toYamlNode(final YamlLine prev) {
         final String trimmed = prev.trimmed();
         final String last = trimmed.substring(trimmed.length()-1);
         final YamlNode node;
@@ -113,5 +124,5 @@ abstract class AbstractYamlLines implements Iterable<YamlLine> {
         }
         return node;
     }
-
+    
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/OrderedYamlLines.java b/src/main/java/com/amihaiemil/eoyaml/OrderedYamlLines.java
deleted file mode 100644
index 7d1e99c..0000000
--- a/src/main/java/com/amihaiemil/eoyaml/OrderedYamlLines.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * Copyright (c) 2016-2020, Mihai Emil Andronache
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- *  list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright notice,
- *  this list of conditions and the following disclaimer in the documentation
- *  and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-package com.amihaiemil.eoyaml;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Ordered YamlLines. Use this decorator only punctually, when it the
- * AbstractYamlLines you're working with need to be ordered.
- * @author Mihai Andronache (amihaiemil@gmail.com)
- * @version $Id$
- * @since 1.0.0
- */
-final class OrderedYamlLines extends AbstractYamlLines {
-
-    /**
-     * Lines to order.
-     */
-    private AbstractYamlLines unordered;
-
-    /**
-     * Ctor.
-     * @param unordered Decorated lines.
-     */
-    OrderedYamlLines(final AbstractYamlLines unordered) {
-        this.unordered = unordered;
-    }
-
-    /**
-     * Iterates over the lines with the same indentation. The lines
-     * are ordered. <br><br> This method is a little more complex - we're not
-     * simply sorting the lines. We have to also cover the case when these
-     * lines are a sequence; then a line might be just a simple dash,
-     * so we have to order these "dash" lines by the node that is nested under
-     * them.
-     * @return Iterator over the ordered lines.
-     */
-    @Override
-    public Iterator<YamlLine> iterator() {
-        final Iterator<YamlLine> lines = this.unordered.iterator();
-        final List<YamlLine> ordered = new LinkedList<>();
-        final List<YamlLine> dashes = new LinkedList<>();
-        final Map<YamlNode, Integer> nodesInSequence = new TreeMap<>();
-        int index = 0;
-        while (lines.hasNext()) {
-            final YamlLine line = lines.next();
-            if("-".equals(line.trimmed())) {
-                nodesInSequence.put(
-                    this.nested(line.number()).toYamlNode(line),
-                    index
-                );
-                dashes.add(line);
-                index = index + 1;
-            } else {
-                ordered.add(line);
-            }
-        }
-        Collections.sort(ordered);
-        for (final Integer idx : nodesInSequence.values()) {
-            ordered.add(dashes.get(idx));
-        }
-        return ordered.iterator();
-    }
-
-    /**
-     * Returns the lines which are nested after the given line.
-     * The lines are not necessarily ordered. If the resulting lines
-     * should be ordered (be iterated in order), then they have
-     * to be wrapped inside a new OrderedYamlLines.
-     * @return AbstractYamlLines
-     * @param after The number of the parent line
-     */
-    @Override
-    AbstractYamlLines nested(final int after) {
-        return this.unordered.nested(after);
-    }
-
-    @Override
-    int count() {
-        return this.unordered.count();
-    }
-
-    @Override
-    String indent(final int indentation) {
-        final StringBuilder indented = new StringBuilder();
-        final Iterator<YamlLine> linesIt = this.iterator();
-        if(linesIt.hasNext()) {
-            final YamlLine first = linesIt.next();
-            final int offset = indentation - first.indentation();
-            indented.append(this.indentLine(first, offset));
-            while(linesIt.hasNext()) {
-                indented.append(
-                    this.indentLine(linesIt.next(), offset)
-                );
-            }
-        }
-        return indented.toString();
-    }
-
-    /**
-     * Indent the given line (and its possible nested nodes) with the given
-     * offset.
-     * @param line YamlLine to indent.
-     * @param offset Offset added to its already existing indentation.
-     * @return String indented result.
-     */
-    private String indentLine(final YamlLine line, final int offset){
-        final StringBuilder indented = new StringBuilder();
-        int indentation = line.indentation() + offset;
-        while (indentation > 0) {
-            indented.append(" ");
-            indentation--;
-        }
-        indented.append(line.toString()).append("\n");
-        if (line.hasNestedNode()) {
-            final OrderedYamlLines nested = new OrderedYamlLines(
-                this.unordered.nested(line.number())
-            );
-            indented.append(nested.indent(indentation + offset));
-        }
-        return indented.toString();
-    }
-}
diff --git a/src/main/java/com/amihaiemil/eoyaml/ReadPipeScalar.java b/src/main/java/com/amihaiemil/eoyaml/ReadPipeScalar.java
index bd612e4..95ce767 100644
--- a/src/main/java/com/amihaiemil/eoyaml/ReadPipeScalar.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ReadPipeScalar.java
@@ -42,13 +42,13 @@ final class ReadPipeScalar implements YamlNode {
     /**
      * Lines to be represented as a wrapped scalar.
      */
-    private AbstractYamlLines lines;
+    private YamlLines lines;
 
     /**
      * Ctor.
      * @param lines Given lines to represent.
      */
-    ReadPipeScalar(final AbstractYamlLines lines) {
+    ReadPipeScalar(final YamlLines lines) {
         this.lines = lines;
     }
 
diff --git a/src/main/java/com/amihaiemil/eoyaml/ReadPointedScalar.java b/src/main/java/com/amihaiemil/eoyaml/ReadPointedScalar.java
index 11e23a2..8a4c0f3 100644
--- a/src/main/java/com/amihaiemil/eoyaml/ReadPointedScalar.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ReadPointedScalar.java
@@ -43,13 +43,13 @@ final class ReadPointedScalar implements YamlNode {
     /**
      * Lines to be represented as a wrapped scalar.
      */
-    private AbstractYamlLines lines;
+    private YamlLines lines;
 
     /**
      * Ctor.
      * @param lines Given lines to represent.
      */
-    ReadPointedScalar(final AbstractYamlLines lines) {
+    ReadPointedScalar(final YamlLines lines) {
         this.lines = lines;
     }
 
diff --git a/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
index 466bd1f..c702e16 100644
--- a/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
@@ -36,7 +36,7 @@ import java.util.Set;
 /**
  * YamlMapping read from somewhere.
  * @author Mihai Andronache (amihaiemil@gmail.com)
- * @version $Id$
+ * @version $Id: 45ce321b60d6fd26daf9a93c6f6d860253ad190f $
  * @since 1.0.0
  */
 final class ReadYamlMapping extends ComparableYamlMapping {
@@ -44,27 +44,26 @@ final class ReadYamlMapping extends ComparableYamlMapping {
     /**
      * Lines read.
      */
-    private AbstractYamlLines lines;
+    private YamlLines lines;
 
     /**
      * Ctor.
      * @param lines Given lines.
      */
-    ReadYamlMapping(final AbstractYamlLines lines) {
-        this.lines = lines;
+    ReadYamlMapping(final AllYamlLines lines) {
+        this.lines = new SameIndentationLevel((AllYamlLines) lines);
     }
 
     @Override
     public Collection<YamlNode> children() {
         final List<YamlNode> kids = new LinkedList<>();
-        final OrderedYamlLines ordered = new OrderedYamlLines(this.lines);
-        for (final YamlLine line : ordered) {
+        for (final YamlLine line : this.lines) {
             final String trimmed = line.trimmed();
             if("?".equals(trimmed) || ":".equals(trimmed)) {
                 continue;
             } else {
                 if(trimmed.endsWith(":")) {
-                    kids.add(ordered.nested(line.number()).toYamlNode(line));
+                    kids.add(this.lines.nested(line.number()).toYamlNode(line));
                 } else {
                     final String[] parts = trimmed.split(":");
                     if(parts.length < 2) {
@@ -147,7 +146,7 @@ final class ReadYamlMapping extends ComparableYamlMapping {
 
     @Override
     public String indent(final int indentation) {
-        return new OrderedYamlLines(this.lines).indent(indentation);
+        return this.lines.indent(indentation);
     }
 
     /**
@@ -186,7 +185,7 @@ final class ReadYamlMapping extends ComparableYamlMapping {
         for (final YamlLine line : this.lines) {
             final String trimmed = line.trimmed();
             if("?".equals(trimmed)) {
-                final AbstractYamlLines keyLines = this.lines.nested(
+                final YamlLines keyLines = this.lines.nested(
                     line.number()
                 );
                 final YamlNode keyNode = keyLines.toYamlNode(line);
diff --git a/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java
index 5f639f3..f0869ef 100644
--- a/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java
@@ -35,7 +35,7 @@ import java.util.List;
 /**
  * YamlSequence read from somewhere.
  * @author Mihai Andronache (amihaiemil@gmail.com)
- * @version $Id$
+ * @version $Id: 5f639f30162909d9510a7013ccbbfa12c5e8175a $
  * @since 1.0.0
  */
 final class ReadYamlSequence extends ComparableYamlSequence {
@@ -43,14 +43,14 @@ final class ReadYamlSequence extends ComparableYamlSequence {
     /**
      * Lines read.
      */
-    private AbstractYamlLines lines;
+    private YamlLines lines;
 
     /**
      * Ctor.
      * @param lines Given lines.
      */
-    ReadYamlSequence(final AbstractYamlLines lines) {
-        this.lines = lines;
+    ReadYamlSequence(final AllYamlLines lines) {
+        this.lines = new SameIndentationLevel((AllYamlLines) lines);
     }
 
     @Override
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java
index c34ff77..fed82ec 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java
@@ -67,10 +67,10 @@ final class RtYamlInput implements YamlInput {
 
     /**
      * Read the input's lines.
-     * @return YamlLines
+     * @return All read YamlLines
      * @throws IOException If something goes wrong while reading the input.
      */
-    private AbstractYamlLines readInput() throws IOException {
+    private AllYamlLines readInput() throws IOException {
         final List<YamlLine> lines = new ArrayList<>();
         try (
             BufferedReader reader = new BufferedReader(
@@ -98,6 +98,6 @@ final class RtYamlInput implements YamlInput {
                 }
             }
         }
-        return new RtYamlLines(lines);
+        return new AllYamlLines(lines);
     }
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/SameIndentationLevel.java b/src/main/java/com/amihaiemil/eoyaml/SameIndentationLevel.java
new file mode 100644
index 0000000..f296c09
--- /dev/null
+++ b/src/main/java/com/amihaiemil/eoyaml/SameIndentationLevel.java
@@ -0,0 +1,97 @@
+/**
+ * Copyright (c) 2016-2020, Mihai Emil Andronache
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ *  list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright notice,
+ *  this list of conditions and the following disclaimer in the documentation
+ *  and/or other materials provided with the distribution.
+ * Neither the name of the copyright holder nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+package com.amihaiemil.eoyaml;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * SameIndentationLevel. Decorates "all" the YamlLines
+ * and iterates only over those which are at the same
+ * indentation level with the first one.
+ * @author Mihai Andronache (amihaiemil@gmail.com)
+ * @version $Id$
+ * @since 3.0.2
+ */
+final class SameIndentationLevel implements YamlLines {
+
+    /**
+     * All YamlLines, unaltered.
+     */
+    private final AllYamlLines all;
+
+    /**
+     * Ctor.
+     * @param all All the Yaml lines.
+     */
+    SameIndentationLevel(final AllYamlLines all) {
+        this.all = all;
+    }
+
+    /**
+     * Returns an iterator over these Yaml lines.
+     * It <b>only</b> iterates over the lines which are at the same
+     * level of indentation with the first!
+     * @return Iterator over these yaml lines.
+     */
+    @Override
+    public Iterator<YamlLine> iterator() {
+        Iterator<YamlLine> iterator = this.all.iterator();
+        if (iterator.hasNext()) {
+            final List<YamlLine> sameIndentation = new ArrayList<>();
+            final YamlLine first = iterator.next();
+            sameIndentation.add(first);
+            while (iterator.hasNext()) {
+                YamlLine current = iterator.next();
+                if(current.indentation() == first.indentation()) {
+                    sameIndentation.add(current);
+                }
+            }
+            iterator = sameIndentation.iterator();
+        }
+        return iterator;
+    }
+
+    @Override
+    public Collection<YamlLine> lines() {
+        return this.all.lines();
+    }
+
+    @Override
+    public int count() {
+        return this.lines().size();
+    }
+
+    @Override
+    public YamlNode toYamlNode(final YamlLine prev) {
+        return this.all.toYamlNode(prev);
+    }
+
+}
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlLines.java b/src/main/java/com/amihaiemil/eoyaml/YamlLines.java
similarity index 63%
rename from src/main/java/com/amihaiemil/eoyaml/RtYamlLines.java
rename to src/main/java/com/amihaiemil/eoyaml/YamlLines.java
index db0f505..ec161d5 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlLines.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlLines.java
@@ -33,87 +33,54 @@ import java.util.Iterator;
 import java.util.List;
 
 /**
- * YamlLines default implementation.
+ * Iterable yaml lines.
  * @author Mihai Andronache (amihaiemil@gmail.com)
- * @version $Id$
+ * @version $Id: 89cef39c95fd016041b0779a81c6ce25ad9c8e44 $
  * @since 1.0.0
  */
-final class RtYamlLines extends AbstractYamlLines {
+interface YamlLines extends Iterable<YamlLine> {
 
     /**
-     * Yaml lines.
+     * All the YAML lines, as a collection.
+     * @return These YamlLines as a Collection.
      */
-    private Collection<YamlLine> lines;
-
+    Collection<YamlLine> lines();
+    
     /**
-     * Ctor.
-     * @param lines Yaml lines collection.
+     * Number of lines.
+     * @return Integer.
      */
-    RtYamlLines(final Collection<YamlLine> lines) {
-        this.lines = lines;
-    }
+    int count();
 
     /**
-     * Returns an iterator over these Yaml lines.
-     * It <b>only</b> iterates over the lines which are at the same
-     * level of indentation with the first!
-     * @return Iterator over these yaml lines.
+     * Turn these lines into a YamlNode.
+     * @param prev Previous YamlLine
+     * @return YamlNode
+     * @todo #107:30min/DEV Add more tests to cover all the nested node
+     *  possibilities.
      */
-    @Override
-    public Iterator<YamlLine> iterator() {
-        Iterator<YamlLine> iterator = this.lines.iterator();
-        if (iterator.hasNext()) {
-            final List<YamlLine> sameIndentation = new ArrayList<>();
-            final YamlLine first = iterator.next();
-            sameIndentation.add(first);
-            while (iterator.hasNext()) {
-                YamlLine current = iterator.next();
-                if(current.indentation() == first.indentation()) {
-                    sameIndentation.add(current);
-                }
-            }
-            iterator = sameIndentation.iterator();
-        }
-        return iterator;
-    }
-
-    @Override
-    AbstractYamlLines nested(final int after) {
-        final List<YamlLine> nestedLines = new ArrayList<YamlLine>();
-        YamlLine start = null;
-        for(final YamlLine line : this.lines) {
-            if(line.number() == after) {
-                start = line;
-            }
-            if(line.number() > after) {
-                if(line.indentation() > start.indentation()) {
-                    nestedLines.add(line);
-                } else {
-                    break;
-                }
-            }
-        }
-        return new RtYamlLines(nestedLines);
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder builder = new StringBuilder();
-        for (final YamlLine line : this.lines) {
-            builder.append(line.toString()).append("\n");
-        }
-        return builder.toString();
-    }
-
-    @Override
-    int count() {
-        return this.lines.size();
+    YamlNode toYamlNode(final YamlLine prev);
+    
+    /**
+     * Default iterator which doesn't skip any line,
+     * iterates over all of them.
+     * @return Iterator of YamlLine.
+     */
+    default Iterator<YamlLine> iterator() {
+        return this.lines().iterator();
     }
-
-    @Override
-    String indent(final int indentation) {
+    
+    /**
+     * Indent these lines.
+     * @param indentation Spaces to precede each line.
+     * @return String with the pretty-printed, indented lines.
+     * @todo #165:30min Add some integration tests to make sure that all types
+     *  of YAML are printed/indented correctly. It can get a little out of hand
+     *  with the different implementations of YamlLines.iterator() method.
+     */
+    default String indent(final int indentation) {
         final StringBuilder indented = new StringBuilder();
-        final Iterator<YamlLine> linesIt = this.lines.iterator();
+        final Iterator<YamlLine> linesIt = this.lines().iterator();
         if(linesIt.hasNext()) {
             final YamlLine first = linesIt.next();
             if (first.indentation() == indentation) {
@@ -123,7 +90,7 @@ final class RtYamlLines extends AbstractYamlLines {
                 }
             } else {
                 final int offset = indentation - first.indentation();
-                for (final YamlLine line : this.lines) {
+                for (final YamlLine line : this.lines()) {
                     int correct = line.indentation() + offset;
                     while (correct > 0) {
                         indented.append(" ");
@@ -135,6 +102,29 @@ final class RtYamlLines extends AbstractYamlLines {
         }
         return indented.toString();
     }
-
+    
+    /**
+     * Lines which are nested after the given YamlLine (lines which are
+     * <br> indented by 2 or more spaces beneath it).
+     * @param after Number of a YamlLine
+     * @return YamlLines
+     */
+    default AllYamlLines nested(final int after) {
+        final List<YamlLine> nestedLines = new ArrayList<YamlLine>();
+        YamlLine start = null;
+        for(final YamlLine line : this.lines()) {
+            if(line.number() == after) {
+                start = line;
+            }
+            if(line.number() > after) {
+                if(line.indentation() > start.indentation()) {
+                    nestedLines.add(line);
+                } else {
+                    break;
+                }
+            }
+        }
+        return new AllYamlLines(nestedLines);
+    }
 
 }


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/RtYamlLinesTest.java b/src/test/java/com/amihaiemil/eoyaml/AllYamlLinesTest.java
similarity index 91%
rename from src/test/java/com/amihaiemil/eoyaml/RtYamlLinesTest.java
rename to src/test/java/com/amihaiemil/eoyaml/AllYamlLinesTest.java
index 58260c4..7ceee5c 100644
--- a/src/test/java/com/amihaiemil/eoyaml/RtYamlLinesTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/AllYamlLinesTest.java
@@ -36,12 +36,12 @@ import org.hamcrest.Matchers;
 import org.junit.Test;
 
 /**
- * Unit tests for {@link RtYamlLines}.
+ * Unit tests for {@link AllYamlLines}.
  * @author Mihai Andronache (amihaiemil@gmail.com)
  * @version $Id$
  * @sinve 1.0.0
  */
-public final class RtYamlLinesTest {
+public final class AllYamlLinesTest {
 
     /**
      * RtYamlLines can iterate over the lines properly.
@@ -56,8 +56,10 @@ public final class RtYamlLinesTest {
         lines.add(new RtYamlLine("  - fifth", 2));
         lines.add(new RtYamlLine("second: something", 3));
         lines.add(new RtYamlLine("third: somethingElse", 4));
-        final Iterator<YamlLine> iterator = new RtYamlLines(lines).iterator();
+        final Iterator<YamlLine> iterator = new AllYamlLines(lines).iterator();
         MatcherAssert.assertThat(iterator.next().number(), Matchers.is(0));
+        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(1));
+        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(2));
         MatcherAssert.assertThat(iterator.next().number(), Matchers.is(3));
         MatcherAssert.assertThat(iterator.next().number(), Matchers.is(4));
         MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
@@ -74,7 +76,7 @@ public final class RtYamlLinesTest {
         lines.add(new RtYamlLine("    - fifth", 2));
         lines.add(new RtYamlLine("  second: something", 3));
         lines.add(new RtYamlLine("  third: somethingElse", 4));
-        final AbstractYamlLines yaml = new RtYamlLines(lines);
+        final YamlLines yaml = new AllYamlLines(lines);
         String expected = "first:\n"
             + "  - fourth\n"
             + "  - fifth\n"
@@ -95,7 +97,7 @@ public final class RtYamlLinesTest {
         lines.add(new RtYamlLine("second: something", 3));
         lines.add(new RtYamlLine("third: somethingElse", 4));
         lines.add(new RtYamlLine("  - sixth", 5));
-        AbstractYamlLines yamlLines = new RtYamlLines(lines);
+        YamlLines yamlLines = new AllYamlLines(lines);
 
         Iterator<YamlLine> iterator = yamlLines.nested(0).iterator();
         MatcherAssert.assertThat(iterator.next().number(), Matchers.is(1));
diff --git a/src/test/java/com/amihaiemil/eoyaml/OrderedYamlLinesTest.java b/src/test/java/com/amihaiemil/eoyaml/OrderedYamlLinesTest.java
deleted file mode 100644
index 0e5dbff..0000000
--- a/src/test/java/com/amihaiemil/eoyaml/OrderedYamlLinesTest.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- * Copyright (c) 2016-2020, Mihai Emil Andronache
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- *  list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright notice,
- *  this list of conditions and the following disclaimer in the documentation
- *  and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-package com.amihaiemil.eoyaml;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hamcrest.MatcherAssert;
-import org.hamcrest.Matchers;
-import org.junit.Test;
-
-/**
- * Unit tests for {@link OrderedYamlLines}.
- * @author Mihai Andronache (amihaiemil@gmail.com)
- * @version $Id$
- * @since 1.0.0
- */
-public final class OrderedYamlLinesTest {
-
-    /**
-     * OrderedYamlLines can iterate over the ordered a mapping's
-     * lines properly. It should iterate only over the lines which
-     * are at the same indentation level.
-     */
-    @Test
-    public void iteratesRightOverMap() {
-        final List<YamlLine> lines = new ArrayList<>();
-        lines.add(new RtYamlLine("first: ", 0));
-        lines.add(new RtYamlLine("  - fourth", 1));
-        lines.add(new RtYamlLine("  - fifth", 2));
-        lines.add(new RtYamlLine("bay: something", 3));
-        lines.add(new RtYamlLine("alba: somethingElse", 4));
-        final Iterator<YamlLine> iterator = new OrderedYamlLines(
-            new RtYamlLines(lines)
-        ).iterator();
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(4));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(3));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(0));
-        MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
-    }
-
-    /**
-     * OrderedYamlLines can iterate over the ordered a sequence's
-     * lines properly. It should iterate only over the lines which
-     * are at the same indentation level. Also, dashes lines should
-     * be ordered according to their nested value nodes.
-     */
-    @Test
-    public void iteratesRightOverSequence() {
-        final List<YamlLine> lines = new ArrayList<>();
-        lines.add(new RtYamlLine("- ", 0));
-        lines.add(new RtYamlLine("  - alfa", 1));
-        lines.add(new RtYamlLine("  - beta", 2));
-        lines.add(new RtYamlLine("- ", 3));
-        lines.add(new RtYamlLine("  key: value", 4));
-        lines.add(new RtYamlLine("- scalar", 5));
-        final AbstractYamlLines yaml = new OrderedYamlLines(
-            new RtYamlLines(lines)
-        );
-        final Iterator<YamlLine> iterator = yaml.iterator();
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(5));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(0));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(3));
-        MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
-
-    }
-
-    /**
-     * OrderedYamlLines can indent the ordered lines properly.
-     */
-    @Test
-    public void indentsRight() {
-        final List<YamlLine> lines = new ArrayList<>();
-        lines.add(new RtYamlLine("fish: ", 0));
-        lines.add(new RtYamlLine("  - beta", 1));
-        lines.add(new RtYamlLine("  - alfa", 2));
-        lines.add(new RtYamlLine("bear: something", 3));
-        lines.add(new RtYamlLine("fox: somethingElse", 4));
-        final AbstractYamlLines yaml = new OrderedYamlLines(
-            new RtYamlLines(lines)
-        );
-        String expected = "bear: something\n"
-            + "fish: \n"
-            + "  - alfa\n"
-            + "  - beta\n"
-            + "fox: somethingElse\n";
-        MatcherAssert.assertThat(yaml.indent(0), Matchers.equalTo(expected));
-    }
-
-    /**
-     * OrderedYamlLines can return nested lines (in initial order) for a given
-     * line.
-     */
-    @Test
-    public void returnsNestedLinesRight() {
-        final List<YamlLine> lines = new ArrayList<>();
-        lines.add(new RtYamlLine("first: ", 0));
-        lines.add(new RtYamlLine("  - bay", 1));
-        lines.add(new RtYamlLine("  - alba", 2));
-        lines.add(new RtYamlLine("second: something", 3));
-        lines.add(new RtYamlLine("third: somethingElse", 4));
-        lines.add(new RtYamlLine("  - sixth", 5));
-        AbstractYamlLines yamlLines = new RtYamlLines(lines);
-
-        Iterator<YamlLine> iterator = yamlLines.nested(0).iterator();
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(1));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(2));
-        MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
-
-        iterator = yamlLines.nested(1).iterator();
-        MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
-
-        iterator = yamlLines.nested(3).iterator();
-        MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
-
-        iterator = yamlLines.nested(4).iterator();
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(5));
-        MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
-    }
-
-    /**
-     * Test to check that YamlLine.compareTo(...) works fine.
-     */
-    @Test
-    public void yamlLinesAreOrdered() {
-        final List<YamlLine> lines = new ArrayList<>();
-        lines.add(new RtYamlLine("Einestien", 0));
-        lines.add(new RtYamlLine("  Ben", 1));
-        lines.add(new RtYamlLine("Charles", 2));
-        lines.add(new RtYamlLine("    Denise", 3));
-        lines.add(new RtYamlLine("      Albert", 4));
-        lines.add(new RtYamlLine("Sherif", 5));
-        Collections.sort(lines);
-
-        Iterator<YamlLine> iterator = lines.iterator();
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(4));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(1));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(2));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(3));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(0));
-        MatcherAssert.assertThat(iterator.next().number(), Matchers.is(5));
-        MatcherAssert.assertThat(iterator.hasNext(), Matchers.is(false));
-    }
-}
diff --git a/src/test/java/com/amihaiemil/eoyaml/ReadPipeScalarTest.java b/src/test/java/com/amihaiemil/eoyaml/ReadPipeScalarTest.java
index 15cc52b..284e436 100644
--- a/src/test/java/com/amihaiemil/eoyaml/ReadPipeScalarTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/ReadPipeScalarTest.java
@@ -54,7 +54,7 @@ public final class ReadPipeScalarTest {
         lines.add(new RtYamlLine("Second Line.", 2));
         lines.add(new RtYamlLine("Third Line.", 3));
         final ReadPipeScalar scalar =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.children(), Matchers.emptyIterable()
         );
@@ -70,7 +70,7 @@ public final class ReadPipeScalarTest {
         lines.add(new RtYamlLine("Second Line.", 2));
         lines.add(new RtYamlLine("Third Line.", 3));
         final ReadPipeScalar scalar =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.value(),
             Matchers.is("First Line.\nSecond Line.\nThird Line.")
@@ -87,7 +87,7 @@ public final class ReadPipeScalarTest {
         lines.add(new RtYamlLine("Second Line.", 2));
         lines.add(new RtYamlLine("Third Line.", 3));
         final ReadPipeScalar scalar =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         RtYamlMapping map = new RtYamlMapping(
             new HashMap<YamlNode, YamlNode>()
         );
@@ -104,7 +104,7 @@ public final class ReadPipeScalarTest {
         lines.add(new RtYamlLine("Second Line.", 2));
         lines.add(new RtYamlLine("Third Line.", 3));
         final ReadPipeScalar scalar =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         RtYamlSequence seq = new RtYamlSequence(new LinkedList<YamlNode>());
         MatcherAssert.assertThat(scalar.compareTo(seq), Matchers.lessThan(0));
     }
@@ -117,7 +117,7 @@ public final class ReadPipeScalarTest {
         final List<YamlLine> lines = new ArrayList<>();
         lines.add(new RtYamlLine("Java", 1));
         final ReadPipeScalar pipeScalar =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         final Scalar scalar = new Scalar("Java");
         MatcherAssert.assertThat(pipeScalar.compareTo(scalar), Matchers.is(0));
     }
@@ -130,9 +130,9 @@ public final class ReadPipeScalarTest {
         final List<YamlLine> lines = new ArrayList<>();
         lines.add(new RtYamlLine("Java", 1));
         final ReadPipeScalar first =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         final ReadPipeScalar second =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(first.compareTo(second), Matchers.is(0));
     }
 
@@ -146,7 +146,7 @@ public final class ReadPipeScalarTest {
         lines.add(new RtYamlLine("Second Line.", 2));
         lines.add(new RtYamlLine("Third Line.", 3));
         final ReadPipeScalar scalar =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.indent(4),
             Matchers.is("    First Line.\n    Second Line.\n    Third Line.")
diff --git a/src/test/java/com/amihaiemil/eoyaml/ReadPointedScalarTest.java b/src/test/java/com/amihaiemil/eoyaml/ReadPointedScalarTest.java
index 18bc998..59f643a 100644
--- a/src/test/java/com/amihaiemil/eoyaml/ReadPointedScalarTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/ReadPointedScalarTest.java
@@ -57,7 +57,7 @@ public final class ReadPointedScalarTest {
         lines.add(new RtYamlLine("Second Line.", 2));
         lines.add(new RtYamlLine("Third Line.", 3));
         final ReadPointedScalar scalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.children(), Matchers.emptyIterable()
         );
@@ -73,7 +73,7 @@ public final class ReadPointedScalarTest {
         lines.add(new RtYamlLine("Second Line", 2));
         lines.add(new RtYamlLine("Third Line", 3));
         final ReadPointedScalar scalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         RtYamlMapping map = new RtYamlMapping(
             new HashMap<YamlNode, YamlNode>()
         );
@@ -90,7 +90,7 @@ public final class ReadPointedScalarTest {
         lines.add(new RtYamlLine("Second Line", 2));
         lines.add(new RtYamlLine("Third Line", 3));
         final ReadPointedScalar scalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         RtYamlSequence seq = new RtYamlSequence(new LinkedList<YamlNode>());
         MatcherAssert.assertThat(scalar.compareTo(seq), Matchers.lessThan(0));
     }
@@ -103,7 +103,7 @@ public final class ReadPointedScalarTest {
         final List<YamlLine> lines = new ArrayList<>();
         lines.add(new RtYamlLine("Java", 1));
         final ReadPointedScalar pipeScalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         final Scalar scalar = new Scalar("Java");
         MatcherAssert.assertThat(pipeScalar.compareTo(scalar), Matchers.is(0));
     }
@@ -116,9 +116,9 @@ public final class ReadPointedScalarTest {
         final List<YamlLine> lines = new ArrayList<>();
         lines.add(new RtYamlLine("Java", 1));
         final ReadPointedScalar first =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         final ReadPipeScalar second =
-            new ReadPipeScalar(new RtYamlLines(lines));
+            new ReadPipeScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(first.compareTo(second), Matchers.is(0));
     }
 
@@ -130,9 +130,9 @@ public final class ReadPointedScalarTest {
         final List<YamlLine> lines = new ArrayList<>();
         lines.add(new RtYamlLine("Java", 1));
         final ReadPointedScalar first =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         final ReadPointedScalar second =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(first.compareTo(second), Matchers.is(0));
     }
 
@@ -146,7 +146,7 @@ public final class ReadPointedScalarTest {
         lines.add(new RtYamlLine("year was crippled", 2));
         lines.add(new RtYamlLine("by a knee injury.", 3));
         final ReadPointedScalar scalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.value(),
             Matchers.is("Mark McGwire's year was crippled by a knee injury.")
@@ -166,7 +166,7 @@ public final class ReadPointedScalarTest {
         lines.add(new RtYamlLine("  63 Home Runs", 4));
         lines.add(new RtYamlLine("What a year!", 5));
         final ReadPointedScalar scalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.value(),
             Matchers.is("Sammy Sosa completed another"
@@ -185,7 +185,7 @@ public final class ReadPointedScalarTest {
         lines.add(new RtYamlLine("year was crippled", 2));
         lines.add(new RtYamlLine("by an injury.", 3));
         final ReadPointedScalar scalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.indent(4),
             Matchers.is("    Mark McGwire's year was crippled by an injury.")
@@ -205,7 +205,7 @@ public final class ReadPointedScalarTest {
         lines.add(new RtYamlLine("  63 Home Runs", 4));
         lines.add(new RtYamlLine("What a year!", 5));
         final ReadPointedScalar scalar =
-            new ReadPointedScalar(new RtYamlLines(lines));
+            new ReadPointedScalar(new AllYamlLines(lines));
         MatcherAssert.assertThat(
             scalar.indent(4),
             Matchers.is("    Sammy Sosa completed another"
diff --git a/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java b/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java
index a804211..6cb1e5f 100644
--- a/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java
@@ -56,7 +56,8 @@ public final class ReadYamlMappingTest {
         lines.add(new RtYamlLine("  fourth: some", 2));
         lines.add(new RtYamlLine("  fifth: values", 3));
         lines.add(new RtYamlLine("third: something", 4));
-        final YamlMapping map = new ReadYamlMapping(new RtYamlLines(lines));
+        final YamlMapping map = new ReadYamlMapping(new AllYamlLines(lines));
+        System.out.println(map);
         final YamlMapping second = map.yamlMapping("second");
         MatcherAssert.assertThat(second, Matchers.notNullValue());
         MatcherAssert.assertThat(
@@ -78,7 +79,7 @@ public final class ReadYamlMappingTest {
         lines.add(new RtYamlLine("  fourth: some", 2));
         lines.add(new RtYamlLine("  fifth: values", 3));
         lines.add(new RtYamlLine("third: something", 4));
-        final YamlMapping map = new ReadYamlMapping(new RtYamlLines(lines));
+        final YamlMapping map = new ReadYamlMapping(new AllYamlLines(lines));
         final Set<YamlNode> keys = map.keys();
         MatcherAssert.assertThat(
             keys, Matchers.not(Matchers.emptyIterable())
@@ -114,7 +115,7 @@ public final class ReadYamlMappingTest {
         lines.add(new RtYamlLine(": ", 4));
         lines.add(new RtYamlLine("  map: value", 5));
         lines.add(new RtYamlLine("second: something", 6));
-        final YamlMapping map = new ReadYamlMapping(new RtYamlLines(lines));
+        final YamlMapping map = new ReadYamlMapping(new AllYamlLines(lines));
         final YamlMapping value = map.yamlMapping(key);
         MatcherAssert.assertThat(value, Matchers.notNullValue());
         MatcherAssert.assertThat(
@@ -137,7 +138,7 @@ public final class ReadYamlMappingTest {
         lines.add(new RtYamlLine("  - some", 2));
         lines.add(new RtYamlLine("  - sequence", 3));
         lines.add(new RtYamlLine("third: something", 4));
-        final YamlMapping map = new ReadYamlMapping(new RtYamlLines(lines));
+        final YamlMapping map = new ReadYamlMapping(new AllYamlLines(lines));
         final YamlSequence second = map.yamlSequence("second");
         MatcherAssert.assertThat(second, Matchers.notNullValue());
         MatcherAssert.assertThat(
@@ -160,7 +161,8 @@ public final class ReadYamlMappingTest {
         lines.add(new RtYamlLine("  complex2: mapping2", 3));
         lines.add(new RtYamlLine(": value", 4));
         lines.add(new RtYamlLine("second: something", 6));
-        final YamlMapping map = new ReadYamlMapping(new RtYamlLines(lines));
+        final YamlMapping map = new ReadYamlMapping(new AllYamlLines(lines));
+        System.out.println(map);
         final String value = map.string(key);
         MatcherAssert.assertThat(value, Matchers.notNullValue());
         MatcherAssert.assertThat(value, Matchers.equalTo("value"));
@@ -178,7 +180,8 @@ public final class ReadYamlMappingTest {
         lines.add(new RtYamlLine("  - some", 2));
         lines.add(new RtYamlLine("  - sequence", 3));
         lines.add(new RtYamlLine("third: something", 4));
-        final YamlMapping map = new ReadYamlMapping(new RtYamlLines(lines));
+        final YamlMapping map = new ReadYamlMapping(new AllYamlLines(lines));
+        System.out.println(map);
         final String third = map.string("third");
         MatcherAssert.assertThat(third, Matchers.notNullValue());
         MatcherAssert.assertThat(
@@ -193,7 +196,7 @@ public final class ReadYamlMappingTest {
     @Test
     public void printsEmptyYaml() throws Exception {
         final YamlMapping map = new ReadYamlMapping(
-            new RtYamlLines(new ArrayList<YamlLine>())
+            new AllYamlLines(new ArrayList<YamlLine>())
         );
         MatcherAssert.assertThat(map.toString(), Matchers.isEmptyString());
     }
diff --git a/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java b/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java
index c07f6fc..8d3e6c2 100644
--- a/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java
@@ -59,8 +59,9 @@ public final class ReadYamlSequenceTest {
         lines.add(new RtYamlLine("    fourth: some", 5));
         lines.add(new RtYamlLine("    key: value", 6));
         final YamlSequence sequence = new ReadYamlSequence(
-            new RtYamlLines(lines)
+            new AllYamlLines(lines)
         );
+        System.out.println(sequence);
         final YamlMapping alfa = sequence.yamlMapping(2);
         MatcherAssert.assertThat(alfa, Matchers.notNullValue());
         MatcherAssert.assertThat(alfa, Matchers.instanceOf(YamlMapping.class));
@@ -83,8 +84,9 @@ public final class ReadYamlSequenceTest {
         lines.add(new RtYamlLine("- scalar", 3));
         lines.add(new RtYamlLine("- otherScalar", 4));
         final YamlSequence sequence = new ReadYamlSequence(
-            new RtYamlLines(lines)
+            new AllYamlLines(lines)
         );
+        System.out.println(sequence);
         final YamlSequence devops = sequence.yamlSequence(0);
         MatcherAssert.assertThat(devops, Matchers.notNullValue());
         MatcherAssert.assertThat(
@@ -104,8 +106,9 @@ public final class ReadYamlSequenceTest {
         lines.add(new RtYamlLine("- rultor", 0));
         lines.add(new RtYamlLine("- 0pdd", 1));
         final YamlSequence devops = new ReadYamlSequence(
-            new RtYamlLines(lines)
+            new AllYamlLines(lines)
         );
+        System.out.println(devops);
         MatcherAssert.assertThat(devops.string(0), Matchers.equalTo("rultor"));
         MatcherAssert.assertThat(devops.string(1), Matchers.equalTo("0pdd"));
     }
@@ -124,8 +127,9 @@ public final class ReadYamlSequenceTest {
         lines.add(new RtYamlLine("    fourth: some", 5));
         lines.add(new RtYamlLine("    key: value", 6));
         final YamlSequence sequence = new ReadYamlSequence(
-            new RtYamlLines(lines)
+            new AllYamlLines(lines)
         );
+        System.out.println(sequence);
         MatcherAssert.assertThat(sequence.size(), Matchers.is(3));
     }
 
@@ -143,8 +147,9 @@ public final class ReadYamlSequenceTest {
         lines.add(new RtYamlLine("    fourth: some", 5));
         lines.add(new RtYamlLine("    key: value", 6));
         final YamlSequence seq = new ReadYamlSequence(
-            new RtYamlLines(lines)
+            new AllYamlLines(lines)
         );
+        System.out.println(seq);
         MatcherAssert.assertThat(seq, Matchers.not(Matchers.emptyIterable()));
         MatcherAssert.assertThat(seq, Matchers.iterableWithSize(3));
     }
@@ -156,7 +161,7 @@ public final class ReadYamlSequenceTest {
     @Test
     public void printsEmptyYaml() throws Exception {
         final YamlSequence sequence = new ReadYamlSequence(
-            new RtYamlLines(new ArrayList<YamlLine>())
+            new AllYamlLines(new ArrayList<YamlLine>())
         );
         MatcherAssert.assertThat(sequence.toString(), Matchers.isEmptyString());
     }
diff --git a/src/test/java/com/amihaiemil/eoyaml/SameIndentationLevelTestCase.java b/src/test/java/com/amihaiemil/eoyaml/SameIndentationLevelTestCase.java
new file mode 100644
index 0000000..2748b12
--- /dev/null
+++ b/src/test/java/com/amihaiemil/eoyaml/SameIndentationLevelTestCase.java
@@ -0,0 +1,158 @@
+/**
+ * Copyright (c) 2016-2020, Mihai Emil Andronache
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ *  list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright notice,
+ *  this list of conditions and the following disclaimer in the documentation
+ *  and/or other materials provided with the distribution.
+ * Neither the name of the copyright holder nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+package com.amihaiemil.eoyaml;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link SameIndentationLevel}.
+ * @author Mihai Andronache (amihaiemil@gmail.com)
+ * @version $Id$
+ * @since 3.0.2
+ */
+public final class SameIndentationLevelTestCase {
+
+    /**
+     * SameIndentationLevel should return all the lines
+     * that it encapsulates.
+     */
+    @Test
+    public void fetchesTheLines() {
+        final List<YamlLine> lines = new ArrayList<>();
+        lines.add(new RtYamlLine("first: somethingElse", 0));
+        lines.add(new RtYamlLine("second: ", 1));
+        lines.add(new RtYamlLine("  fourth: some", 2));
+        lines.add(new RtYamlLine("  fifth: values", 3));
+        lines.add(new RtYamlLine("third: something", 4));
+        final YamlLines yaml = new SameIndentationLevel(
+            new AllYamlLines(lines)
+        );
+        MatcherAssert.assertThat(
+            yaml.lines().size(),
+            Matchers.equalTo(lines.size())
+        );
+    }
+    
+    /**
+     * SameIndentationLevel should return its line count, the number
+     * of all the lines that it encapsulates.
+     */
+    @Test
+    public void fetchesCount() {
+        final List<YamlLine> lines = new ArrayList<>();
+        lines.add(new RtYamlLine("first: somethingElse", 0));
+        lines.add(new RtYamlLine("second: ", 1));
+        lines.add(new RtYamlLine("  fourth: some", 2));
+        lines.add(new RtYamlLine("  fifth: values", 3));
+        lines.add(new RtYamlLine("third: something", 4));
+        final YamlLines yaml = new SameIndentationLevel(
+            new AllYamlLines(lines)
+        );
+        MatcherAssert.assertThat(
+            yaml.count(),
+            Matchers.equalTo(lines.size())
+        );
+    }
+    
+    /**
+     * SameIndentationLevel should iterate only over the lines,
+     * which have the same level of indentation.
+     */
+    @Test
+    public void iteratesSameLevelOfIndentation() {
+        final List<YamlLine> lines = new ArrayList<>();
+        lines.add(new RtYamlLine("first: somethingElse", 0));
+        lines.add(new RtYamlLine("second: ", 1));
+        lines.add(new RtYamlLine("  fourth: some", 2));
+        lines.add(new RtYamlLine("  fifth: values", 3));
+        lines.add(new RtYamlLine("third: something", 4));
+        final YamlLines yaml = new SameIndentationLevel(
+            new AllYamlLines(lines)
+        );
+        MatcherAssert.assertThat(yaml, Matchers.iterableWithSize(3));
+        final Iterator<YamlLine> iterator = yaml.iterator();
+        MatcherAssert.assertThat(
+            iterator.next(),
+            Matchers.equalTo(lines.get(0))
+        );
+        MatcherAssert.assertThat(
+            iterator.next(),
+            Matchers.equalTo(lines.get(1))
+        );
+        MatcherAssert.assertThat(
+            iterator.next(),
+            Matchers.equalTo(lines.get(4))
+        );
+    }
+    
+    /**
+     * SameIndentationLevel should iterate only over the lines,
+     * which have the same level of indentation. In this case,
+     * all the lines are already at the same indentation level.
+     */
+    @Test
+    public void iteratesSameLevelOfIndentationAll() {
+        final List<YamlLine> lines = new ArrayList<>();
+        lines.add(new RtYamlLine("first: somethingElse", 0));
+        lines.add(new RtYamlLine("second: test", 1));
+        lines.add(new RtYamlLine("third: some", 2));
+        lines.add(new RtYamlLine("fourth: values", 3));
+        final YamlLines yaml = new SameIndentationLevel(
+            new AllYamlLines(lines)
+        );
+        MatcherAssert.assertThat(yaml, Matchers.iterableWithSize(lines.size()));
+        final Iterator<YamlLine> iterator = yaml.iterator();
+        for(final YamlLine inputLine : lines) {
+            MatcherAssert.assertThat(
+                iterator.next(),
+                Matchers.equalTo(inputLine)
+            );
+        }
+    }
+
+    /**
+     * SameIndentationLevel should iterate only over the lines,
+     * which have the same level of indentation. In this case, we
+     * actually have no lines.
+     */
+    @Test
+    public void iteratesSameLevelOfIndentationEmpty() {
+        final List<YamlLine> lines = new ArrayList<>();
+        final YamlLines yaml = new SameIndentationLevel(
+            new AllYamlLines(lines)
+        );
+        MatcherAssert.assertThat(yaml, Matchers.iterableWithSize(lines.size()));
+    }
+    
+}
diff --git a/src/test/resources/commentedMapping.yml b/src/test/resources/commentedMapping.yml
index af9ab37..d7433ec 100644
--- a/src/test/resources/commentedMapping.yml
+++ b/src/test/resources/commentedMapping.yml
@@ -1,7 +1,7 @@
 # Yaml for test
+architect: mihai
 developers: # all the contributors here
   - rultor # bot used for devops
   - salikjan
   - sherif
-architect: mihai
 name: eo-yaml
\ No newline at end of file