Refactor: introduce Chomping to avoid using null as value for Boolean
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a507ba7..2c5366b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -8,6 +8,10 @@
<body>
<release version="1.6-SNAPSHOT" date="in Mercurial" description="development">
<action dev="py4fun" type="update">
+ Refactor: introduce Chomping to avoid using null as value for Boolean.
+ Stay in line with Scala friens where null is not allowed (2010-01-19)
+ </action>
+ <action dev="py4fun" type="update">
Refactor: change signature for Constant.has(). When the additional String is
at the end it is possible to use default arguments in Scala (2010-01-18)
</action>
diff --git a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
index 9b4f35c..96fb8dc 100644
--- a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
+++ b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
@@ -1234,9 +1234,8 @@
Mark startMark = reader.getMark();
// Scan the header.
reader.forward();
- Object[] chompi = scanBlockScalarIndicators(startMark);
- Boolean chomping = (Boolean) chompi[0];
- int increment = ((Integer) chompi[1]).intValue();
+ Chomping chompi = scanBlockScalarIndicators(startMark);
+ int increment = chompi.getIncrement();
scanBlockScalarIgnoredLine(startMark);
// Determine the indentation level and go to the first non-empty line.
@@ -1297,17 +1296,17 @@
}
}
// Chomp the tail.
- if (chomping == null || chomping.booleanValue()) {
+ if (chompi.chompTailIsNotFalse()) {
chunks.append(lineBreak);
}
- if (chomping != null && chomping.booleanValue()) {
+ if (chompi.chompTailIsTrue()) {
chunks.append(breaks);
}
// We are done.
return new ScalarToken(chunks.toString(), false, startMark, endMark, style);
}
- private Object[] scanBlockScalarIndicators(Mark startMark) {
+ private Chomping scanBlockScalarIndicators(Mark startMark) {
// See the specification for details.
Boolean chomping = null;
int increment = -1;
@@ -1353,7 +1352,7 @@
"expected chomping or indentation indicators, but found " + ch, reader
.getMark());
}
- return new Object[] { chomping, new Integer(increment) };
+ return new Chomping(chomping, increment);
}
private String scanBlockScalarIgnoredLine(Mark startMark) {
@@ -1750,4 +1749,29 @@
}
return "";
}
+
+ /**
+ * Chomping the tail may have 3 values - yes, no, not defined.
+ */
+ private class Chomping {
+ private final Boolean value;
+ private final int increment;
+
+ public Chomping(Boolean value, int increment) {
+ this.value = value;
+ this.increment = increment;
+ }
+
+ public boolean chompTailIsNotFalse() {
+ return value == null || value;
+ }
+
+ public boolean chompTailIsTrue() {
+ return value != null && value;
+ }
+
+ public int getIncrement() {
+ return increment;
+ }
+ }
}