Repository: decorators-squad/eo-yaml (java)

Issue:
Allow building of plain scalar with above and inline comment
Let's add an overloaded method for building plain scalars with comments above and inline.

Pull request description:
#464 Build scalar with above and inline comments
Fixes #464 

The user can now build a scalar with above *and* inline comments.

Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/PlainStringScalar.java b/src/main/java/com/amihaiemil/eoyaml/PlainStringScalar.java
index 5332a71..684d2d8 100644
--- a/src/main/java/com/amihaiemil/eoyaml/PlainStringScalar.java
+++ b/src/main/java/com/amihaiemil/eoyaml/PlainStringScalar.java
@@ -61,13 +61,30 @@ final class PlainStringScalar extends BaseScalar {
 
     /**
      * Ctor.
-     * @param comment Comment referring to this Scalar.
      * @param value Given value for this scalar.
+     * @param inline Comment inline with the scalar (after it).
      */
-    PlainStringScalar(final String value, final String comment) {
+    PlainStringScalar(final String value, final String inline) {
+        this(value, "", inline);
+    }
+
+    /**
+     * Ctor.
+     * @param value Given value for this scalar.
+     * @param above Comment above the scalar.
+     * @param inline Comment inline with the scalar.
+     */
+    PlainStringScalar(
+        final String value, final String above, final String inline
+    ) {
         this.value = value;
-        this.comment = new InlineComment(
-            new BuiltComment(this, comment)
+        this.comment = new Concatenated(
+            new BuiltComment(
+                this, above
+            ),
+            new InlineComment(
+                new BuiltComment(this, inline)
+            )
         );
     }
 
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlScalarBuilder.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlScalarBuilder.java
index f17b8fb..058edd6 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlScalarBuilder.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlScalarBuilder.java
@@ -70,11 +70,16 @@ final class RtYamlScalarBuilder implements YamlScalarBuilder {
     }
 
     @Override
-    public Scalar buildPlainScalar(final String comment) {
+    public Scalar buildPlainScalar(final String inline) {
+        return this.buildPlainScalar("", inline);
+    }
+
+    @Override
+    public Scalar buildPlainScalar(final String above, final String inline) {
         final String plain = this.lines.stream().filter(line -> line!=null).map(
             line -> line.replaceAll(System.lineSeparator(), " ")
         ).collect(Collectors.joining(" "));
-        return new PlainStringScalar(plain, comment);
+        return new PlainStringScalar(plain, above, inline);
     }
 
     @Override
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlScalarBuilder.java b/src/main/java/com/amihaiemil/eoyaml/YamlScalarBuilder.java
index 285d8f4..a11d74c 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlScalarBuilder.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlScalarBuilder.java
@@ -90,10 +90,23 @@ public interface YamlScalarBuilder {
      * your scalar is short, a single line of text.<br><br>
      * If you added more lines of text, all of them will be put together,
      * separated by spaces.
-     * @param comment Comment referring to the built scalar.
+     * @param inline Inline comment referring to the built scalar. If it has
+     *  more lines, they will be concatenated into a single line.
+     * @return The built Scalar.
+     */
+    Scalar buildPlainScalar(final String inline);
+
+    /**
+     * Build a plain Scalar. Ideally, you should use this when
+     * your scalar is short, a single line of text.<br><br>
+     * If you added more lines of text, all of them will be put together,
+     * separated by spaces.
+     * @param above Comment above the scalar. It may have multiple lines.
+     * @param inline Inline comment referring to the built scalar. If it has
+     *  more lines, they will be concatenated into a single line.
      * @return The built Scalar.
      */
-    Scalar buildPlainScalar(final String comment);
+    Scalar buildPlainScalar(final String above, final String inline);
 
     /**
      * Build a Folded Block Scalar. Use this when your scalar has multiple


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/PlainStringScalarTest.java b/src/test/java/com/amihaiemil/eoyaml/PlainStringScalarTest.java
index 5d673d3..f24147b 100644
--- a/src/test/java/com/amihaiemil/eoyaml/PlainStringScalarTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/PlainStringScalarTest.java
@@ -56,10 +56,10 @@ public final class PlainStringScalarTest {
     }
 
     /**
-     * Scalar can return its comment.
+     * Scalar can return its inline comment.
      */
     @Test
-    public void returnsComment() {
+    public void returnsInlineComment() {
         final String val = "test scalar value";
         final PlainStringScalar scl = new PlainStringScalar(val, "comment");
         MatcherAssert.assertThat(
@@ -72,6 +72,27 @@ public final class PlainStringScalarTest {
         );
     }
 
+    /**
+     * Scalar can return its above and inline comments concatenated.
+     */
+    @Test
+    public void returnsConcatenatedComment() {
+        final String val = "test scalar value";
+        final PlainStringScalar scl = new PlainStringScalar(
+            val, "above", "inline"
+        );
+        MatcherAssert.assertThat(
+            scl.comment().value(),
+            Matchers.equalTo(
+                "above" + System.lineSeparator() + "inline"
+            )
+        );
+        MatcherAssert.assertThat(
+            scl.comment().yamlNode(),
+            Matchers.is(scl)
+        );
+    }
+
     /**
      * Make sure that equals and hash code are reflexive
      * and symmetric.