Repository: decorators-squad/eo-yaml
Pull request #297 (2020-04-08 14:57:34)

#295 Add Java module support
Add support for Java modules while maintaining Java 8 compatibility.


Patch:
diff --git a/pom.xml b/pom.xml
index 2e87f79..4e98c38 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>com.amihaiemil.web</groupId>
 	<artifactId>eo-yaml</artifactId>
-	<version>4.1.1-SNAPSHOT</version><!--rrv-sed-flag-->
+	<version>4.2.0-SNAPSHOT</version><!--rrv-sed-flag-->
 	<packaging>jar</packaging>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -107,6 +107,57 @@
 		</plugins>
 	</build>
 	<profiles>
+		<profile>
+			<id>jdk9</id>
+			<activation>
+				<jdk>[9,)</jdk>
+			</activation>
+			<build>
+				<pluginManagement>
+					<plugins>
+						<plugin>
+							<groupId>org.apache.maven.plugins</groupId>
+							<artifactId>maven-compiler-plugin</artifactId>
+							<executions>
+								<execution>
+									<id>jdk9</id>
+									<goals>
+										<goal>compile</goal>
+									</goals>
+									<configuration>
+										<release>9</release>
+										<compileSourceRoots>
+											<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
+										</compileSourceRoots>
+										<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
+										<compilerArgs>
+											<arg>--patch-module</arg>
+											<arg>com.amihaiemil.eoyaml=${project.build.outputDirectory}</arg>
+										</compilerArgs>
+									</configuration>
+								</execution>
+							</executions>
+						</plugin>
+						<plugin>
+							<groupId>org.apache.maven.plugins</groupId>
+							<artifactId>maven-jar-plugin</artifactId>
+							<executions>
+								<execution>
+									<id>default-jar</id>
+									<configuration>
+										<archive>
+											<manifestEntries>
+												<Multi-Release>true</Multi-Release>
+											</manifestEntries>
+										</archive>
+									</configuration>
+								</execution>
+							</executions>
+						</plugin>
+					</plugins>
+				</pluginManagement>
+			</build>
+		</profile>
 		<profile>
 			<id>checkstyle</id>
 			<build>
diff --git a/src/main/java/com/amihaiemil/eoyaml/BaseYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/BaseYamlMapping.java
index 07eee29..4e7a5d2 100644
--- a/src/main/java/com/amihaiemil/eoyaml/BaseYamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/BaseYamlMapping.java
@@ -47,6 +47,26 @@ import java.util.*;
 public abstract class BaseYamlMapping
     extends BaseYamlNode implements YamlMapping {
 
+    /**
+     * Comments referring the key:value pairs.
+     */
+    private Comments comments;
+
+    /**
+     * Default ctor.
+     */
+    public BaseYamlMapping() {
+        this(new Comments.Empty());
+    }
+
+    /**
+     * Constructor.
+     * @param comments Comments referring to the key: value entries.
+     */
+    public BaseYamlMapping(final Comments comments) {
+        this.comments = comments;
+    }
+
     @Override
     public final int hashCode() {
         int hash = 0;
@@ -136,6 +156,11 @@ public abstract class BaseYamlMapping
         return result;
     }
 
+    @Override
+    public final Comments comments() {
+        return this.comments;
+    }
+
     /**
      * Indent this YamlMapping. This is a base method since indentation
      * logic should be identical for any kind of YamlMapping, regardless of
@@ -162,16 +187,14 @@ public abstract class BaseYamlMapping
             alignment.append(" ");
             spaces--;
         }
+        this.printPossibleComment(this.comment(), print, alignment.toString());
         for(final YamlNode key : this.keys()) {
             this.printPossibleComment(
-                key.comment(), print, alignment.toString()
+                this.comments().referringTo(key), print, alignment.toString()
             );
             print.append(alignment);
             final BaseYamlNode indKey = (BaseYamlNode) key;
             final BaseYamlNode value = (BaseYamlNode) this.value(key);
-            this.printPossibleComment(
-                value.comment(), print, alignment.toString()
-            );
             if(indKey instanceof Scalar) {
                 print
                     .append(indKey.indent(0))
@@ -285,9 +308,6 @@ public abstract class BaseYamlMapping
      */
     @Override
     public final String toString() {
-        final StringBuilder print = new StringBuilder();
-        this.printPossibleComment(this.comment(), print, "");
-        print.append(this.indent(0));
-        return print.toString();
+        return this.indent(0);
     }
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/BaseYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/BaseYamlSequence.java
index 5157930..95a6d99 100644
--- a/src/main/java/com/amihaiemil/eoyaml/BaseYamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/BaseYamlSequence.java
@@ -46,6 +46,27 @@ import java.util.*;
 public abstract class BaseYamlSequence
     extends BaseYamlNode implements YamlSequence {
 
+    /**
+     * Comments referring the elements of this YamlSequence.
+     */
+    private Comments comments;
+
+    /**
+     * Default ctor.
+     */
+    public BaseYamlSequence() {
+        this(new Comments.Empty());
+    }
+
+    /**
+     * Constructor.
+     * @param comments Comments referring to the elements of the sequence.
+     */
+    public BaseYamlSequence(final Comments comments) {
+        this.comments = comments;
+    }
+
+
     @Override
     public final int hashCode() {
         int hash = 0;
@@ -122,6 +143,11 @@ public abstract class BaseYamlSequence
         return result;
     }
 
+    @Override
+    public final Comments comments() {
+        return this.comments;
+    }
+
     /**
      * Indent this YamlSequence. This is a base method since indentation
      * logic should be identical for any kind of YamlSequence, regardless of
@@ -148,8 +174,13 @@ public abstract class BaseYamlSequence
             alignment.append(" ");
             spaces--;
         }
+        this.printPossibleComment(this.comment(), print, alignment.toString());
         for (final YamlNode node : this.values()) {
-            this.printPossibleComment(node.comment(), print, alignment.toString());
+            this.printPossibleComment(
+                this.comments.referringTo(node),
+                print,
+                alignment.toString()
+            );
             print
                 .append(alignment)
                 .append("-");
@@ -246,9 +277,6 @@ public abstract class BaseYamlSequence
      */
     @Override
     public final String toString() {
-        final StringBuilder print = new StringBuilder();
-        this.printPossibleComment(this.comment(), print, "");
-        print.append(this.indent(0));
-        return print.toString();
+        return this.indent(0);
     }
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/Comments.java b/src/main/java/com/amihaiemil/eoyaml/Comments.java
index 16cbafd..697ef1d 100644
--- a/src/main/java/com/amihaiemil/eoyaml/Comments.java
+++ b/src/main/java/com/amihaiemil/eoyaml/Comments.java
@@ -39,7 +39,7 @@ import java.util.Iterator;
  * @version $Id$
  * @since 4.2.0
  */
-interface Comments extends Iterable<Comment> {
+public interface Comments extends Iterable<Comment> {
 
     /**
      * Get the Comment referring to the specified YamlNode.
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java
index 8570032..f228c23 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java
@@ -54,18 +54,21 @@ final class RtYamlMapping extends BaseYamlMapping {
      * @param entries Entries contained in this mapping.
      */
     RtYamlMapping(final Map<YamlNode, YamlNode> entries) {
-        this(entries, "");
+        this(entries, new ArrayList<>(), "");
     }
 
     /**
      * Ctor.
      * @param entries Entries contained in this mapping.
+     * @param keyComments Comments on top of the key: value pairs.
      * @param comment Comment on top of this YamlMapping.
      */
     RtYamlMapping(
         final Map<YamlNode, YamlNode> entries,
+        final List<Comment> keyComments,
         final String comment
     ) {
+        super(new BuiltComments(keyComments));
         this.mappings.putAll(entries);
         this.comment = new BuiltComment(this, comment);
     }
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlMappingBuilder.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlMappingBuilder.java
index c7f5f19..3608100 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlMappingBuilder.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlMappingBuilder.java
@@ -28,6 +28,8 @@
 package com.amihaiemil.eoyaml;
 
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -45,50 +47,50 @@ final class RtYamlMappingBuilder implements YamlMappingBuilder {
      */
     private final Map<YamlNode, YamlNode> pairs;
 
+    /**
+     * Comments referring to the key:value pairs.
+     */
+    private final List<Comment> comments;
+
     /**
      * Default ctor.
      */
     RtYamlMappingBuilder() {
-        this(new LinkedHashMap<>());
+        this(new LinkedHashMap<>(), new LinkedList<>());
     }
 
     /**
      * Constructor.
      * @param pairs Pairs used in building the YamlMapping.
+     * @param comments Comments referring to the key:value pairs.
      */
-    RtYamlMappingBuilder(final Map<YamlNode, YamlNode> pairs) {
+    RtYamlMappingBuilder(
+        final Map<YamlNode, YamlNode> pairs,
+        final List<Comment> comments
+    ) {
         this.pairs = pairs;
+        this.comments = comments;
     }
 
     @Override
-    public YamlMappingBuilder add(final String key, final String value) {
-        return this.add(
-            new PlainStringScalar(key),
-            new PlainStringScalar(value)
-        );
-    }
-
-    @Override
-    public YamlMappingBuilder add(final YamlNode key, final String value) {
-        return this.add(key, new PlainStringScalar(value));
-    }
-
-    @Override
-    public YamlMappingBuilder add(final String key, final YamlNode value) {
-        return this.add(new PlainStringScalar(key), value);
-    }
-
-    @Override
-    public YamlMappingBuilder add(final YamlNode key, final YamlNode value) {
+    public YamlMappingBuilder add(
+        final YamlNode key,
+        final YamlNode value,
+        final String comment
+    ) {
         final Map<YamlNode, YamlNode> withAddedPair = new LinkedHashMap<>();
         withAddedPair.putAll(this.pairs);
         withAddedPair.put(key, value);
-        return new RtYamlMappingBuilder(withAddedPair);
+
+        final List<Comment> withAddedComment = new LinkedList<>();
+        withAddedComment.addAll(this.comments);
+        withAddedComment.add(new BuiltComment(key, comment));
+        return new RtYamlMappingBuilder(withAddedPair, withAddedComment);
     }
 
     @Override
     public YamlMapping build(final String comment) {
-        return new RtYamlMapping(this.pairs, comment);
+        return new RtYamlMapping(this.pairs, this.comments, comment);
     }
 
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java
index 7141e76..b242de6 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java
@@ -53,18 +53,21 @@ final class RtYamlSequence extends BaseYamlSequence {
      * @param elements Elements of this sequence.
      */
     RtYamlSequence(final Collection<YamlNode> elements) {
-        this(elements, "");
+        this(elements, new ArrayList<>(), "");
     }
 
     /**
      * Constructor.
      * @param elements Elements of this sequence.
+     * @param comments Comments referring to the elements of this sequence.
      * @param comment Comment referring to this sequence itself.
      */
     RtYamlSequence(
         final Collection<YamlNode> elements,
+        final List<Comment> comments,
         final String comment
     ) {
+        super(new BuiltComments(comments));
         this.nodes.addAll(elements);
         this.comment = new BuiltComment(this, comment);
     }
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlSequenceBuilder.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlSequenceBuilder.java
index 79ce93c..613dc45 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlSequenceBuilder.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlSequenceBuilder.java
@@ -43,36 +43,46 @@ final class RtYamlSequenceBuilder implements YamlSequenceBuilder {
      */
     private final List<YamlNode> nodes;
 
+    /**
+     * Comments referring to the elements of the YamlSequence.
+     */
+    private final List<Comment> comments;
+
     /**
      * Default ctor.
      */
     RtYamlSequenceBuilder() {
-        this(new LinkedList<>());
+        this(new LinkedList<>(), new LinkedList<>());
     }
 
     /**
      * Constructor.
      * @param nodes Nodes used in building the YamlSequence
+     * @param comments Comments referring to the elements of the YamlSequence.
      */
-    RtYamlSequenceBuilder(final List<YamlNode> nodes) {
+    RtYamlSequenceBuilder(
+        final List<YamlNode> nodes,
+        final List<Comment> comments
+    ) {
         this.nodes = nodes;
+        this.comments = comments;
     }
 
     @Override
-    public YamlSequenceBuilder add(final String value) {
-        return this.add(new PlainStringScalar(value));
-    }
+    public YamlSequenceBuilder add(final YamlNode node, final String comment) {
+        final List<YamlNode> elements = new LinkedList<>();
+        elements.addAll(this.nodes);
+        elements.add(node);
 
-    @Override
-    public YamlSequenceBuilder add(final YamlNode node) {
-        final List<YamlNode> list = new LinkedList<>();
-        list.addAll(this.nodes);
-        list.add(node);
-        return new RtYamlSequenceBuilder(list);
+        final List<Comment> withComments = new LinkedList<>();
+        withComments.addAll(this.comments);
+        withComments.add(new BuiltComment(node, comment));
+
+        return new RtYamlSequenceBuilder(elements, withComments);
     }
 
     @Override
     public YamlSequence build(final String comment) {
-        return new RtYamlSequence(this.nodes, comment);
+        return new RtYamlSequence(this.nodes, this.comments, comment);
     }
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/Scalar.java b/src/main/java/com/amihaiemil/eoyaml/Scalar.java
index a3fc0cf..248383e 100644
--- a/src/main/java/com/amihaiemil/eoyaml/Scalar.java
+++ b/src/main/java/com/amihaiemil/eoyaml/Scalar.java
@@ -46,4 +46,10 @@ public interface Scalar extends YamlNode {
      *  supposed to be.
      */
     String value();
+
+    /**
+     * Comment referring to this Scalar.
+     * @return Comment.
+     */
+    Comment comment();
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/YamlMapping.java
index 2426c92..93c92e0 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlMapping.java
@@ -410,4 +410,18 @@ public interface YamlMapping extends YamlNode {
         }
         return null;
     }
+
+    /**
+     * Comment referring to this YamlMapping.
+     * @return Comment.
+     */
+    Comment comment();
+
+    /**
+     * Comments referring to the key:value pairs of this
+     * mapping.
+     * @return Comments or Comments.Empty() if there are no
+     *  comments to be returned.
+     */
+    Comments comments();
 }
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlMappingBuilder.java b/src/main/java/com/amihaiemil/eoyaml/YamlMappingBuilder.java
index 8742627..a8b97b5 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlMappingBuilder.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlMappingBuilder.java
@@ -34,13 +34,35 @@ package com.amihaiemil.eoyaml;
  * @since 1.0.0
  */
 public interface YamlMappingBuilder {
+
+    /**
+     * Add a pair to the mapping.
+     * @param key String
+     * @param value String
+     * @return This builder
+     */
+    default YamlMappingBuilder add(final String key, final String value) {
+        return this.add(key, value, "");
+    }
+
     /**
      * Add a pair to the mapping.
      * @param key String
      * @param value String
+     * @param comment Comment that will appear on top of the pair.
      * @return This builder
      */
-    YamlMappingBuilder add(final String key, final String value);
+    default YamlMappingBuilder add(
+        final String key,
+        final String value,
+        final String comment
+    ) {
+        return this.add(
+            Yaml.createYamlScalarBuilder().addLine(key).buildPlainScalar(),
+            Yaml.createYamlScalarBuilder().addLine(value).buildPlainScalar(),
+            comment
+        );
+    }
 
     /**
      * Add a pair to the mapping.
@@ -48,23 +70,80 @@ public interface YamlMappingBuilder {
      * @param value String
      * @return This builder
      */
-    YamlMappingBuilder add(final YamlNode key, final String value);
+    default YamlMappingBuilder add(final YamlNode key, final String value) {
+        return this.add(key, value, "");
+    }
 
     /**
      * Add a pair to the mapping.
      * @param key YamlNode (sequence or mapping)
+     * @param value String
+     * @param comment Comment that will appear on top of the pair.
+     * @return This builder
+     */
+    default YamlMappingBuilder add(
+        final YamlNode key,
+        final String value,
+        final String comment
+    ) {
+        return this.add(
+            key,
+            Yaml.createYamlScalarBuilder().addLine(value).buildPlainScalar(),
+            comment
+        );
+    }
+
+    /**
+     * Add a pair to the mapping.
+     * @param key String
      * @param value YamlNode (sequence or mapping)
      * @return This builder
      */
-    YamlMappingBuilder add(final YamlNode key, final YamlNode value);
+    default YamlMappingBuilder add(final String key, final YamlNode value) {
+        return this.add(key, value, "");
+    }
 
     /**
      * Add a pair to the mapping.
      * @param key String
      * @param value YamlNode (sequence or mapping)
+     * @param comment Comment that will appear on top of the pair.
+     * @return This builder
+     */
+    default YamlMappingBuilder add(
+        final String key,
+        final YamlNode value,
+        final String comment
+    ) {
+        return this.add(
+            Yaml.createYamlScalarBuilder().addLine(key).buildPlainScalar(),
+            value,
+            comment
+        );
+    }
+
+    /**
+     * Add a pair to the mapping.
+     * @param key YamlNode (sequence or mapping)
+     * @param value YamlNode (sequence or mapping)
+     * @return This builder
+     */
+    default YamlMappingBuilder add(final YamlNode key, final YamlNode value) {
+        return this.add(key, value, "");
+    }
+
+    /**
+     * Add a pair to the mapping.
+     * @param key YamlNode (sequence or mapping)
+     * @param value YamlNode (sequence or mapping)
+     * @param comment Comment that will appear on top of this pair.
      * @return This builder
      */
-    YamlMappingBuilder add(final String key, final YamlNode value);
+    YamlMappingBuilder add(
+        final YamlNode key,
+        final YamlNode value,
+        final String comment
+    );
 
     /**
      * Build the YamlMapping.
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlNode.java b/src/main/java/com/amihaiemil/eoyaml/YamlNode.java
index a4b38b7..3df07b7 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlNode.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlNode.java
@@ -34,14 +34,4 @@ package com.amihaiemil.eoyaml;
  * @since 1.0.0
  * @see <a href="http://yaml.org/spec/1.2/spec.html#node/">Spec1.2/node</a>
  */
-public interface YamlNode extends Comparable<YamlNode> {
-
-    /**
-     * Comment referring to this Node.
-     * @return Comment. If there is no comment, it will return
-     *  an "empty" comment (an instance of Comment with empty-string value()).
-     */
-    Comment comment();
-
-
-}
+public interface YamlNode extends Comparable<YamlNode> { }
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java
index 8486ad8..4063632 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java
@@ -97,6 +97,19 @@ public interface YamlSequence extends YamlNode, Iterable<YamlNode> {
      */
     Iterator<YamlNode> iterator();
 
+    /**
+     * Comment referring to this YamlSequence.
+     * @return Comment.
+     */
+    Comment comment();
+
+    /**
+     * Comments referring to the elements of this sequence.
+     * @return Comments or Comments.Empty if there are no comments
+     *  to return.
+     */
+    Comments comments();
+
     /**
      * Convenience method to directly read an integer value
      * from this sequence. It is equivalent to:
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlSequenceBuilder.java b/src/main/java/com/amihaiemil/eoyaml/YamlSequenceBuilder.java
index 8f41be1..7beae33 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlSequenceBuilder.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlSequenceBuilder.java
@@ -40,14 +40,39 @@ public interface YamlSequenceBuilder {
      * @param value String
      * @return This builder
      */
-    YamlSequenceBuilder add(final String value);
+    default YamlSequenceBuilder add(final String value) {
+        return this.add(value, "");
+    }
+
+    /**
+     * Add a value to the sequence.
+     * @param value String
+     * @param comment Comment referring to the added value.
+     * @return This builder
+     */
+    default YamlSequenceBuilder add(final String value, final String comment) {
+        return this.add(
+            Yaml.createYamlScalarBuilder().addLine(value).buildPlainScalar(),
+            comment
+        );
+    }
+
+    /**
+     * Add a value to the sequence.
+     * @param node YamlNode
+     * @return This builder
+     */
+    default YamlSequenceBuilder add(final YamlNode node) {
+        return this.add(node, "");
+    }
 
     /**
      * Add a value to the sequence.
      * @param node YamlNode
+     * @param comment Comment referring to the added YamlNode.
      * @return This builder
      */
-    YamlSequenceBuilder add(final YamlNode node);
+    YamlSequenceBuilder add(final YamlNode node, final String comment);
 
     /**
      * Build the YamlSequence.
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlStream.java b/src/main/java/com/amihaiemil/eoyaml/YamlStream.java
index aad913b..2c7ba43 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlStream.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlStream.java
@@ -54,10 +54,6 @@ public interface YamlStream extends YamlNode, Stream<YamlNode> {
      */
     Collection<YamlNode> values();
 
-    default Comment comment() {
-        return new BuiltComment(this, "");
-    }
-
     default Iterator<YamlNode> iterator() {
         return this.values().stream().iterator();
     }
diff --git a/src/main/java9/module-info.java b/src/main/java9/module-info.java
new file mode 100644
index 0000000..00ebcc7
--- /dev/null
+++ b/src/main/java9/module-info.java
@@ -0,0 +1,7 @@
+module com.amihaiemil.eoyaml {
+    requires static commons.beanutils;
+
+    exports com.amihaiemil.eoyaml;
+    exports com.amihaiemil.eoyaml.exceptions;
+    exports com.amihaiemil.eoyaml.extensions;
+}


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/YamlMappingCommentsPrintTest.java b/src/test/java/com/amihaiemil/eoyaml/YamlMappingCommentsPrintTest.java
index b0627a8..bd67c22 100644
--- a/src/test/java/com/amihaiemil/eoyaml/YamlMappingCommentsPrintTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/YamlMappingCommentsPrintTest.java
@@ -54,20 +54,20 @@ public final class YamlMappingCommentsPrintTest {
     @Test
     public void printsBuiltYamlMappingWithComments() throws Exception {
         final YamlMapping commented = Yaml.createYamlMappingBuilder()
-            .add("architect", "mihai")
+            .add("architect", "mihai", "the Dictator")
             .add(
                 "developers",
                 Yaml.createYamlSequenceBuilder()
                     .add("rultor")
                     .add("salikjan")
                     .add("sherif")
-                    .build("all the contributors here")
+                    .build(),
+                "all the contributors here"
             )
             .add(
                 "name",
-                Yaml.createYamlScalarBuilder()
-                    .addLine("eo-yaml")
-                    .buildPlainScalar("name of the project")
+                "eo-yaml",
+                "name of the project"
             ).build("YamlMapping for test");
         System.out.println(commented);
         MatcherAssert.assertThat(
diff --git a/src/test/java/com/amihaiemil/eoyaml/YamlSequenceCommentsPrintTest.java b/src/test/java/com/amihaiemil/eoyaml/YamlSequenceCommentsPrintTest.java
index 66a021e..b80b43a 100644
--- a/src/test/java/com/amihaiemil/eoyaml/YamlSequenceCommentsPrintTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/YamlSequenceCommentsPrintTest.java
@@ -55,16 +55,14 @@ public final class YamlSequenceCommentsPrintTest {
     public void printsBuiltYamlSequenceWithComments() throws Exception {
         final YamlSequence commented = Yaml.createYamlSequenceBuilder()
             .add("element1")
-            .add(
-                Yaml.createYamlScalarBuilder()
-                    .addLine("element2")
-                    .buildPlainScalar("a plain scalar string in a sequence"))
+            .add("element2", "a plain scalar string in a sequence")
             .add("element3")
             .add(
                 Yaml.createYamlMappingBuilder()
                     .add("key", "value")
                     .add("key2", "value2")
-                    .build("a mapping as an element of a sequence")
+                    .build(),
+                "a mapping as an element of a sequence"
             )
             .build("a sequence with comments");
         System.out.println(commented);
diff --git a/src/test/resources/commentedMapping.yml b/src/test/resources/commentedMapping.yml
index 49020e3..12b6dbe 100644
--- a/src/test/resources/commentedMapping.yml
+++ b/src/test/resources/commentedMapping.yml
@@ -1,4 +1,5 @@
 # YamlMapping for test
+# the Dictator
 architect: mihai
 # all the contributors here
 developers: