Repository: decorators-squad/eo-yaml
Pull request #159 (2020-03-06 13:20:57)

Renamed AbstractMap/Seq -> ComparableMap/Seq
PR for #158 
Renamed classes AbstractYamlMapping and AbstractYamlSequence to ComparableYamlMapping and ComparableYamlSequence respectively. 

Also made StrictYamlMapping to work with YamlMapping instead of Abstract(Comparable)YamlMapping.


Patch:
diff --git a/checkstyle.xml b/checkstyle.xml
index 5154128..52468d3 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -255,7 +255,6 @@
             <property name="allowedAbbreviations" value="IT"/>
             <property name="allowedAbbreviationLength" value="1"/>
         </module>
-        <module name="AbstractClassName"/>
         <module name="ClassTypeParameterName"/>
         <module name="ConstantName"/>
         <module name="LocalFinalVariableName">
diff --git a/src/main/java/com/amihaiemil/eoyaml/AbstractYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/ComparableYamlMapping.java
similarity index 92%
rename from src/main/java/com/amihaiemil/eoyaml/AbstractYamlMapping.java
rename to src/main/java/com/amihaiemil/eoyaml/ComparableYamlMapping.java
index c2bee3e..7891fc7 100644
--- a/src/main/java/com/amihaiemil/eoyaml/AbstractYamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ComparableYamlMapping.java
@@ -31,13 +31,17 @@ import java.util.Iterator;
 import java.util.Set;
 
 /**
- * AbstractYamlMapping implementing methods which should be the same across
- * all final implementations of YamlMapping.
+ * Comparable YamlMapping implementing equals, hashcode and compareTo methods.
+ * <br><br>
+ * These methods should be default methods on the interface,
+ * but we are not allowed to have default implementations of java.lang.Object
+ * methods.
+ * 
  * @author Mihai Andronache (amihaiemil@gmail.com)
  * @version $Id$
  * @since 1.0.0
  */
-abstract class AbstractYamlMapping implements YamlMapping {
+abstract class ComparableYamlMapping implements YamlMapping {
 
     @Override
     public int hashCode() {
@@ -95,7 +99,7 @@ abstract class AbstractYamlMapping implements YamlMapping {
         if (other == null || !(other instanceof YamlMapping)) {
             result = 1;
         } else if (this != other) {
-            final AbstractYamlMapping map = (AbstractYamlMapping) other;
+            final ComparableYamlMapping map = (ComparableYamlMapping) other;
             final Set<YamlNode> keys = this.keys();
             final Set<YamlNode> otherKeys = map.keys();
             if(keys.size() > otherKeys.size()) {
diff --git a/src/main/java/com/amihaiemil/eoyaml/AbstractYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/ComparableYamlSequence.java
similarity index 93%
rename from src/main/java/com/amihaiemil/eoyaml/AbstractYamlSequence.java
rename to src/main/java/com/amihaiemil/eoyaml/ComparableYamlSequence.java
index aede4b8..2d222bb 100644
--- a/src/main/java/com/amihaiemil/eoyaml/AbstractYamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ComparableYamlSequence.java
@@ -31,13 +31,17 @@ import java.util.Collection;
 import java.util.Iterator;
 
 /**
- * AbstractYamlSequence implementing methods which should be the same across 
- * all final implementations of YamlSequence.
+ * Comparable YamlSequence implementing equals, hashcode and compareTo methods.
+ * <br><br>
+ * These methods should be default methods on the interface,
+ * but we are not allowed to have default implementations of java.lang.Object
+ * methods.
+ * 
  * @author Mihai Andronache (amihaiemil@gmail.com)
  * @version $Id$
  * @since 1.0.0
  */
-abstract class AbstractYamlSequence implements YamlSequence {
+abstract class ComparableYamlSequence implements YamlSequence {
     
     @Override
     public int hashCode() {
diff --git a/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
index 743ff1f..782de3f 100644
--- a/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java
@@ -39,7 +39,7 @@ import java.util.Set;
  * @version $Id$
  * @since 1.0.0
  */
-final class ReadYamlMapping extends AbstractYamlMapping {
+final class ReadYamlMapping extends ComparableYamlMapping {
 
     /**
      * Lines read.
diff --git a/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java
index 6b2e5d3..c39b3c5 100644
--- a/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/ReadYamlSequence.java
@@ -11,7 +11,7 @@ import java.util.List;
  * @version $Id$
  * @since 1.0.0
  */
-final class ReadYamlSequence extends AbstractYamlSequence {
+final class ReadYamlSequence extends ComparableYamlSequence {
 
     /**
      * Lines read.
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java
index a717818..b1fb89f 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlMapping.java
@@ -40,7 +40,7 @@ import java.util.TreeMap;
  * @since 1.0.0
  * @see http://yaml.org/spec/1.2/spec.html#mapping//
  */
-final class RtYamlMapping extends AbstractYamlMapping {
+final class RtYamlMapping extends ComparableYamlMapping {
 
     /**
      * Key:value tree map (ordered keys).
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java
index 975630b..519bc49 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlSequence.java
@@ -39,7 +39,7 @@ import java.util.List;
  * @since 1.0.0
  * @see http://yaml.org/spec/1.2/spec.html#sequence//
  */
-final class RtYamlSequence extends AbstractYamlSequence {
+final class RtYamlSequence extends ComparableYamlSequence {
 
     /**
      * Nodes in this sequence.
diff --git a/src/main/java/com/amihaiemil/eoyaml/StrictYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/StrictYamlMapping.java
index da842c7..f148369 100644
--- a/src/main/java/com/amihaiemil/eoyaml/StrictYamlMapping.java
+++ b/src/main/java/com/amihaiemil/eoyaml/StrictYamlMapping.java
@@ -41,18 +41,18 @@ import java.util.Set;
  * @version $Id$
  * @since 1.0.0
  */
-public final class StrictYamlMapping extends AbstractYamlMapping {
+public final class StrictYamlMapping extends ComparableYamlMapping {
 
     /**
      * Original YamlMapping.
      */
-    private AbstractYamlMapping decorated;
+    private YamlMapping decorated;
 
     /**
      * Ctor.
      * @param decorated Original YamlMapping
      */
-    public StrictYamlMapping(final AbstractYamlMapping decorated) {
+    public StrictYamlMapping(final YamlMapping decorated) {
         this.decorated = decorated;
     }
 
diff --git a/src/main/java/com/amihaiemil/eoyaml/StrictYamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/StrictYamlSequence.java
index bea5319..5efc0ff 100644
--- a/src/main/java/com/amihaiemil/eoyaml/StrictYamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/StrictYamlSequence.java
@@ -39,7 +39,7 @@ import java.util.Iterator;
  * @version $Id$
  * @since 1.0.0
  */
-public final class StrictYamlSequence extends AbstractYamlSequence {
+public final class StrictYamlSequence extends ComparableYamlSequence {
 
     /**
      * Original YamlSequence.


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/StrictYamlMappingTest.java b/src/test/java/com/amihaiemil/eoyaml/StrictYamlMappingTest.java
index 254b85d..f57a9f6 100644
--- a/src/test/java/com/amihaiemil/eoyaml/StrictYamlMappingTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/StrictYamlMappingTest.java
@@ -81,7 +81,7 @@ public final class StrictYamlMappingTest {
      */
     @Test (expected = YamlNodeNotFoundException.class)
     public void exceptionOnNullMapping() {
-        AbstractYamlMapping origin = Mockito.mock(AbstractYamlMapping.class);
+        YamlMapping origin = Mockito.mock(YamlMapping.class);
         Mockito.when(origin.yamlMapping("key")).thenReturn(null);
         YamlMapping strict = new StrictYamlMapping(origin);
         strict.yamlMapping("key");
@@ -93,7 +93,7 @@ public final class StrictYamlMappingTest {
      */
     @Test (expected = YamlNodeNotFoundException.class)
     public void exceptionOnNullSequence() {
-        AbstractYamlMapping origin = Mockito.mock(AbstractYamlMapping.class);
+        YamlMapping origin = Mockito.mock(YamlMapping.class);
         Mockito.when(origin.yamlSequence("key")).thenReturn(null);
         YamlMapping strict = new StrictYamlMapping(origin);
         strict.yamlSequence("key");
@@ -105,7 +105,7 @@ public final class StrictYamlMappingTest {
      */
     @Test (expected = YamlNodeNotFoundException.class)
     public void exceptionOnNullString() {
-        AbstractYamlMapping origin = Mockito.mock(AbstractYamlMapping.class);
+        YamlMapping origin = Mockito.mock(YamlMapping.class);
         Mockito.when(origin.string("key")).thenReturn(null);
         YamlMapping strict = new StrictYamlMapping(origin);
         strict.string("key");
@@ -116,7 +116,7 @@ public final class StrictYamlMappingTest {
      */
     @Test
     public void returnsMapping() {
-        AbstractYamlMapping origin = Mockito.mock(AbstractYamlMapping.class);
+        YamlMapping origin = Mockito.mock(YamlMapping.class);
         YamlMapping found = Mockito.mock(YamlMapping.class);
         YamlNode key = new Scalar("key");
         Mockito.when(origin.yamlMapping(key)).thenReturn(found);
@@ -131,7 +131,7 @@ public final class StrictYamlMappingTest {
      */
     @Test
     public void returnsSequence() {
-        AbstractYamlMapping origin = Mockito.mock(AbstractYamlMapping.class);
+        YamlMapping origin = Mockito.mock(YamlMapping.class);
         YamlSequence found = Mockito.mock(YamlSequence.class);
         YamlNode key = new Scalar("key");
         Mockito.when(origin.yamlSequence(key)).thenReturn(found);
@@ -146,7 +146,7 @@ public final class StrictYamlMappingTest {
      */
     @Test
     public void returnsString() {
-        AbstractYamlMapping origin = Mockito.mock(AbstractYamlMapping.class);
+        YamlMapping origin = Mockito.mock(YamlMapping.class);
         YamlNode key = new Scalar("key");
         Mockito.when(origin.string(key)).thenReturn("found");
         YamlMapping strict = new StrictYamlMapping(origin);