summaryrefslogtreecommitdiff
path: root/clformat/src/main/java/bjc
diff options
context:
space:
mode:
Diffstat (limited to 'clformat/src/main/java/bjc')
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java291
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLModifiers.java18
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java81
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLString.java10
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java43
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java7
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java44
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/Decree.java8
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java31
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java14
10 files changed, 245 insertions, 302 deletions
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java
index db137a5..34da857 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java
@@ -304,99 +304,87 @@ public class CLFormatter {
if (decr.isLiteral) {
rw.write(decr.name);
- continue;
- }
-
- Object item = tParams.item();
-
- if (decr.isUserCall) {
+ } else if (decr.isUserCall) {
/*
* @TODO implement user-called functions.
*/
- continue;
- }
-
- if (extraDirectives.containsKey(decr.name)) {
+ } else if (extraDirectives.containsKey(decr.name)) {
FormatParameters params
- = new FormatParameters(rw, item, decr, tParams, cltok, this);
+ = new FormatParameters(rw, tParams.item(), decr,
+ tParams, cltok, this);
extraDirectives.get(decr.name).format(params);
-
- continue;
- }
-
- if (builtinDirectives.containsKey(decr.name)) {
+ } else if (builtinDirectives.containsKey(decr.name)) {
FormatParameters params
- = new FormatParameters(rw, item, decr, tParams, cltok, this);
+ = new FormatParameters(rw, tParams.item(), decr,
+ tParams, cltok, this);
builtinDirectives.get(decr.name).format(params);
- continue;
- }
-
- if (decr.name == null)
- decr.name = "<null>";
-
- switch (decr.name) {
- case "]":
- throw new IllegalArgumentException(
- "Found conditional-end outside of conditional.");
- case ";":
- throw new IllegalArgumentException(
- "Found seperator outside of block.");
- case "}":
- throw new IllegalArgumentException(
- "Found iteration-end outside of iteration");
- case ")":
- throw new IllegalArgumentException(
- "Case-conversion end outside of case conversion");
- case "`]":
- throw new IllegalArgumentException(
- "Inflection-end outside of inflection");
- case "<":
- case ">":
- throw new IllegalArgumentException(
- "Inflection marker outside of inflection");
- case "`<":
- case "`>":
- throw new IllegalArgumentException(
- "Layout-control directives aren't implemented yet.");
- case "F":
- case "E":
- case "G":
- case "$":
- /*
- * @TODO
- *
- * implement floating point directives.
- */
- throw new IllegalArgumentException(
- "Floating-point directives aren't implemented yet.");
- case "W":
- /*
- * @TODO
- *
- * figure out if we want to implement someting for these directives
- * instead of punting.
- */
- throw new IllegalArgumentException(
- "S and W aren't implemented. Use A instead");
- case "P":
- throw new IllegalArgumentException(
- "These directives aren't implemented yet");
- case "\n":
- /*
- * Ignored newline.
- */
- break;
- default:
- String msg
- = String.format("Unknown format directive '%s'", decr.name);
- throw new IllegalArgumentException(msg);
+ } else {
+ // All of these conditions are an error in some way
+ if (decr.name == null) decr.name = "<null>";
+
+ switch (decr.name) {
+ case "]":
+ throw new IllegalArgumentException(
+ "Found conditional-end outside of conditional.");
+ case ";":
+ throw new IllegalArgumentException(
+ "Found seperator outside of block.");
+ case "}":
+ throw new IllegalArgumentException(
+ "Found iteration-end outside of iteration");
+ case ")":
+ throw new IllegalArgumentException(
+ "Case-conversion end outside of case conversion");
+ case "`]":
+ throw new IllegalArgumentException(
+ "Inflection-end outside of inflection");
+ case "<":
+ case ">":
+ throw new IllegalArgumentException(
+ "Inflection marker outside of inflection");
+ case "`<":
+ case "`>":
+ throw new IllegalArgumentException(
+ "Layout-control directives aren't implemented yet.");
+ case "F":
+ case "E":
+ case "G":
+ case "$":
+ /*
+ * @TODO
+ *
+ * implement floating point directives.
+ */
+ throw new IllegalArgumentException(
+ "Floating-point directives aren't implemented yet.");
+ case "W":
+ /*
+ * @TODO
+ *
+ * figure out if we want to implement someting for these directives
+ * instead of punting.
+ */
+ throw new IllegalArgumentException(
+ "S and W aren't implemented. Use A instead");
+ case "P":
+ throw new IllegalArgumentException(
+ "These directives aren't implemented yet");
+ case "\n":
+ /*
+ * Ignored newline.
+ */
+ break;
+ default:
+ String msg
+ = String.format("Unknown format directive '%s'", decr.name);
+ throw new IllegalArgumentException(msg);
+ }
}
}
} catch (DirectiveEscape eex) {
- if (!isToplevel)
- throw eex;
+ if (!isToplevel) throw eex;
}
}
@@ -426,8 +414,7 @@ public class CLFormatter {
*/
public List<Edict> compile(Iterable<Decree> decrees) {
// If we have no decrees, there are no edicts.
- if (decrees == null)
- return new ArrayList<>();
+ if (decrees == null) return new ArrayList<>();
CLTokenizer it = CLTokenizer.fromTokens(decrees);
return compile(it);
@@ -442,10 +429,8 @@ public class CLFormatter {
* @return The set of edicts compiled from the clause.
*/
public List<Edict> compile(ClauseDecree clause) {
- if (clause == null)
- return new ArrayList<>();
-
- return compile(clause.body);
+ if (clause == null) return new ArrayList<>();
+ else return compile(clause.body);
}
/**
@@ -467,89 +452,79 @@ public class CLFormatter {
if (decr.isLiteral) {
result.add(new StringEdict(decr.name));
-
- continue;
- }
-
- if (decr.isUserCall) {
+ } else if (decr.isUserCall) {
/*
* @TODO implement user-called functions.
*/
throw new IllegalArgumentException(
"User-called functions have not yet been implemented");
- }
-
- if (extraDirectives.containsKey(nam)) {
+ } else if (extraDirectives.containsKey(nam)) {
Edict edt = extraDirectives.get(nam).compile(compCTX);
result.add(edt);
-
- continue;
} else if (builtinDirectives.containsKey(nam)) {
Edict edt = builtinDirectives.get(nam).compile(compCTX);
result.add(edt);
-
- continue;
- }
-
- if (nam == null)
- nam = "<null>";
-
- switch (nam) {
- case "]":
- throw new IllegalArgumentException(
- "Found conditional-end outside of conditional.");
- case ";":
- throw new IllegalArgumentException("Found seperator outside of block.");
- case "}":
- throw new IllegalArgumentException(
- "Found iteration-end outside of iteration");
- case ")":
- throw new IllegalArgumentException(
- "Case-conversion end outside of case conversion");
- case "`]":
- throw new IllegalArgumentException(
- "Inflection-end outside of inflection");
- case "<":
- case ">":
- throw new IllegalArgumentException(
- "Inflection marker outside of inflection");
- case "`<":
- case "`>":
- throw new IllegalArgumentException(
- "Layout-control directives aren't implemented yet.");
- case "F":
- case "E":
- case "G":
- case "$":
- /*
- * @TODO
- *
- * implement floating point directives.
- */
- throw new IllegalArgumentException(
- "Floating-point directives aren't implemented yet.");
- case "W":
- /*
- * @TODO
- *
- * figure out if we want to implement someting for these directives
- * instead of punting.
- */
- throw new IllegalArgumentException(
- "S and W aren't implemented. Use A instead");
- case "P":
- throw new IllegalArgumentException(
- "These directives aren't implemented yet");
- case "\n":
- /*
- * Ignored newline.
- */
- break;
- default:
- String msg = String.format("Unknown format directive '%s'", nam);
- throw new IllegalArgumentException(msg);
+ } else {
+ // All of these conditions are an error in some way
+ if (nam == null) nam = "<null>";
+
+ switch (nam) {
+ case "]":
+ throw new IllegalArgumentException(
+ "Found conditional-end outside of conditional.");
+ case ";":
+ throw new IllegalArgumentException("Found seperator outside of block.");
+ case "}":
+ throw new IllegalArgumentException(
+ "Found iteration-end outside of iteration");
+ case ")":
+ throw new IllegalArgumentException(
+ "Case-conversion end outside of case conversion");
+ case "`]":
+ throw new IllegalArgumentException(
+ "Inflection-end outside of inflection");
+ case "<":
+ case ">":
+ throw new IllegalArgumentException(
+ "Inflection marker outside of inflection");
+ case "`<":
+ case "`>":
+ throw new IllegalArgumentException(
+ "Layout-control directives aren't implemented yet.");
+ case "F":
+ case "E":
+ case "G":
+ case "$":
+ /*
+ * @TODO
+ *
+ * implement floating point directives.
+ */
+ throw new IllegalArgumentException(
+ "Floating-point directives aren't implemented yet.");
+ case "W":
+ /*
+ * @TODO
+ *
+ * figure out if we want to implement someting for these directives
+ * instead of punting.
+ */
+ throw new IllegalArgumentException(
+ "S and W aren't implemented. Use A instead");
+ case "P":
+ throw new IllegalArgumentException(
+ "These directives aren't implemented yet");
+ case "\n":
+ /*
+ * Ignored newline.
+ */
+ break;
+ default:
+ String msg = String.format("Unknown format directive '%s'", nam);
+ throw new IllegalArgumentException(msg);
+ }
}
}
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLModifiers.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLModifiers.java
index e2cb8b4..c0bd75d 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLModifiers.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLModifiers.java
@@ -60,10 +60,10 @@ public class CLModifiers {
boolean starMod = false;
if (modString != null) {
- atMod = modString.contains("@");
- colonMod = modString.contains(":");
+ atMod = modString.contains("@");
+ colonMod = modString.contains(":");
dollarMod = modString.contains("$");
- starMod = modString.contains("*");
+ starMod = modString.contains("*");
}
return new CLModifiers(atMod, colonMod, dollarMod, starMod);
@@ -73,14 +73,10 @@ public class CLModifiers {
public String toString() {
StringBuilder sb = new StringBuilder();
- if (atMod)
- sb.append('@');
- if (colonMod)
- sb.append(':');
- if (dollarMod)
- sb.append('$');
- if (starMod)
- sb.append('*');
+ if (atMod) sb.append('@');
+ if (colonMod) sb.append(':');
+ if (dollarMod) sb.append('$');
+ if (starMod) sb.append('*');
return sb.toString();
}
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java
index aef8fbe..691784a 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java
@@ -13,13 +13,13 @@ import bjc.utils.parserutils.TokenUtils;
public class CLParameters {
private static String MSG_FMT = "Invalid %s (%s) \"%s\" to %s directive";
- private static String RX_TRUE = "(?i)y(?:es)?|t(?:rue)?(?i)";
+ private static String RX_TRUE = "(?i)y(?:es)?|t(?:rue)?(?i)";
private static String RX_FALSE = "(?i)no?|f(?:alse)?(?i)";
private CLValue[] params;
private Set<String> abbrevWords;
- private AbbrevMap2 nameAbbrevs;
+ private AbbrevMap2 nameAbbrevs;
private Map<String, CLValue> namedParams;
private Map<String, Integer> nameIndices;
@@ -80,19 +80,13 @@ public class CLParameters {
// with here, as these objects are fairly temporary.
//
// If it becomes an issue, I'll resolve it
- for (String key : namedParams.keySet()) {
- refreshAbbrev(key);
- }
-
- for (String key : nameIndices.keySet()) {
- refreshAbbrev(key);
- }
+ for (String key : namedParams.keySet()) refreshAbbrev(key);
+ for (String key : nameIndices.keySet()) refreshAbbrev(key);
}
// Refresh a particular abbreviation
private void refreshAbbrev(String key) {
- if (abbrevWords.contains(key))
- return;
+ if (abbrevWords.contains(key)) return;
abbrevWords.add(key);
nameAbbrevs.add(key);
@@ -110,8 +104,7 @@ public class CLParameters {
for (int i = 0; i < opts.length; i++) {
String opt = opts[i];
- if (!opt.equals(""))
- mapIndex(opt, i);
+ if (!opt.equals("")) mapIndex(opt, i);
}
refreshAbbrevs();
@@ -139,8 +132,7 @@ public class CLParameters {
nameIndices.put(opt.toUpperCase(), idx);
- if (doRefresh)
- refreshAbbrevs();
+ if (doRefresh) refreshAbbrevs();
}
/**
@@ -152,8 +144,7 @@ public class CLParameters {
* @return The value at that index.
*/
public CLValue getByIndex(int idx) {
- if (idx < 0 || idx >= params.length)
- return null;
+ if (idx < 0 || idx >= params.length) return null;
return params[idx];
}
@@ -235,8 +226,7 @@ public class CLParameters {
if (ch == ':' || ch == ';') {
// Semicolon says to add as
// indexed parameter
- if (ch == ';')
- setIndex = true;
+ if (ch == ';') setIndex = true;
nameIdx = i;
break;
@@ -251,8 +241,7 @@ public class CLParameters {
namedParams.put(paramName.toUpperCase(), actVal);
- if (setIndex)
- parameters.add(actVal);
+ if (setIndex) parameters.add(actVal);
} else {
parameters.add(parseParam(param));
}
@@ -311,10 +300,11 @@ public class CLParameters {
sb.append("\". Could've meant: ");
boolean isFirst = true;
for (String possKey : keys) {
- if (!isFirst)
- sb.append(", ");
- if (isFirst)
+ if (isFirst) {
isFirst = false;
+ } else {
+ sb.append(", ");
+ }
sb.append("\"");
sb.append(possKey);
@@ -335,10 +325,8 @@ public class CLParameters {
// @NOTE 9/22/18
//
// Consider whether we should throw an exception here.
- if (idx < 0 || idx >= params.length)
- return null;
-
- return params[idx];
+ if (idx < 0 || idx >= params.length) return null;
+ else return params[idx];
}
return null;
@@ -370,10 +358,8 @@ public class CLParameters {
String bol = resolveKey(key).getValue(parms);
if (!bol.equals("")) {
- if (bol.matches(RX_TRUE))
- return true;
- else if (bol.matches(RX_FALSE))
- return false;
+ if (bol.matches(RX_TRUE)) return true;
+ else if (bol.matches(RX_FALSE)) return false;
else {
String msg = String.format(MSG_FMT, paramName, key, bol, directive);
throw new IllegalArgumentException(msg);
@@ -412,8 +398,7 @@ public class CLParameters {
//
// This raises the question of what to do if the empty string is a valid
// value for a parameter
- if (!vl.equals(""))
- return vl;
+ if (!vl.equals("")) return vl;
return def;
}
@@ -508,25 +493,23 @@ public class CLParameters {
int idx = 0;
// First off, the named parameters
for (Map.Entry<String, CLValue> param : namedParams.entrySet()) {
- String paramName = param.getKey();
+ String paramName = param.getKey();
CLValue paramValue = param.getValue();
if (nameIndices.containsKey(paramName)) {
int paramIdx = nameIndices.get(paramName);
- String msg
- = String.format("%s(%d):'%s'", paramName, paramIdx, paramValue);
+ String msg = String.format("%s(%d):'%s'",
+ paramName, paramIdx, paramValue);
- if (idx != 0)
- sb.append(", ");
+ if (idx != 0) sb.append(", ");
sb.append(msg);
seenIndices.add(idx);
} else {
String msg = String.format("%s:'%s'", paramName, paramValue);
- if (idx != 0)
- sb.append(", ");
+ if (idx != 0) sb.append(", ");
sb.append(msg);
}
@@ -541,14 +524,12 @@ public class CLParameters {
int paramIdx = paramMap.getValue();
// We've already gotten this argument before
- if (seenIndices.contains(paramIdx))
- continue;
+ if (seenIndices.contains(paramIdx)) continue;
- String msg
- = String.format("%d(%s):'%s'", paramIdx, paramName, params[paramIdx]);
+ String msg = String.format("%d(%s):'%s'",
+ paramIdx, paramName, params[paramIdx]);
- if (idx != 0)
- sb.append(", ");
+ if (idx != 0) sb.append(", ");
sb.append(msg);
seenIndices.add(paramIdx);
@@ -559,13 +540,11 @@ public class CLParameters {
// Third, unnamed indexed parameters
for (idx = 0; idx < params.length; idx++) {
// We've already gotten this argument before
- if (seenIndices.contains(idx))
- continue;
+ if (seenIndices.contains(idx)) continue;
String msg = String.format("%d:'%s'", idx, params[idx]);
- if (idx != 0)
- sb.append(", ");
+ if (idx != 0) sb.append(", ");
sb.append(msg);
}
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLString.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLString.java
index 01e7617..6d77503 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLString.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLString.java
@@ -98,9 +98,7 @@ public class CLString {
*/
public String format(FormatContext formCTX) throws IOException {
try {
- for (Edict edt : edicts) {
- edt.format(formCTX);
- }
+ for (Edict edt : edicts) edt.format(formCTX);
} catch (DirectiveEscape eex) {
// General escape exception, so stop formatting.
}
@@ -114,10 +112,8 @@ public class CLString {
* @return If this format string is empty.
*/
public boolean isEmpty() {
- if (edicts.size() == 0)
- return true;
-
- return false;
+ if (edicts.size() == 0) return true;
+ else return false;
}
@Override
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java
index af7c935..59133b6 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java
@@ -31,16 +31,12 @@ public class CLTokenizer implements Iterator<Decree> {
@Override
public boolean hasNext() {
- boolean nxt = body.hasNext();
-
- return nxt;
+ return body.hasNext();
}
@Override
public Decree next() {
- Decree nxt = body.next();
-
- return nxt;
+ return body.next();
}
}
@@ -92,16 +88,12 @@ public class CLTokenizer implements Iterator<Decree> {
@Override
public boolean hasNext() {
- boolean nxt = !mat.hitEnd();
-
- return nxt;
+ return !mat.hitEnd();
}
@Override
public Decree next() {
- Decree tk = getNext();
-
- return tk;
+ return getNext();
}
private Decree getNext() {
@@ -124,23 +116,19 @@ public class CLTokenizer implements Iterator<Decree> {
String tmp = sb.toString();
{
- String dirName = mat.group("name");
- String dirFunc = mat.group("funcname");
- String dirMods = mat.group("modifiers");
- String dirParams = mat.group("params");
+ String directiveName = mat.group("name");
+ String directiveFunction = mat.group("funcname");
+ String directiveModifierString = mat.group("modifiers");
+ String directiveParameterString = mat.group("params");
- if (dirMods == null) {
- dirMods = "";
- }
-
- if (dirParams == null) {
- dirParams = "";
- }
+ if (directiveModifierString == null) directiveModifierString = "";
+ if (directiveParameterString == null) directiveParameterString = "";
- boolean isUser = dirName == null && dirFunc != null;
+ boolean isUser = directiveName == null && directiveFunction != null;
- dir = new Decree(dirName, isUser, CLParameters.fromDirective(dirParams),
- CLModifiers.fromString(dirMods));
+ dir = new Decree(directiveName, isUser,
+ CLParameters.fromDirective(directiveParameterString),
+ CLModifiers.fromString(directiveModifierString));
}
if (tmp.equals("")) {
@@ -195,8 +183,7 @@ public class CLTokenizer implements Iterator<Decree> {
GroupDecree newGroup = new GroupDecree();
newGroup.opening = openedWith;
- if (!hasNext())
- throw new NoSuchElementException("No decrees available");
+ if (!hasNext()) throw new NoSuchElementException("No decrees available");
ClauseDecree curClause = new ClauseDecree();
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java
index e4b4c32..a2465ba 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java
@@ -18,12 +18,7 @@ public interface CLValue {
* @return The CLValue represented by the string.
*/
public static CLValue parse(String val) {
- if (val == null)
- return new NullValue();
-
- if (val.equalsIgnoreCase("V")) {
- return new VValue();
- }
+ if (val == null) return new NullValue();
switch (val) {
case "V":
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java
index aa4efbe..9db248c 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java
@@ -13,7 +13,7 @@ import bjc.utils.ioutils.ReportWriter;
*
* @author Ben Culkin
*/
-public class ClauseDecree {
+public class ClauseDecree implements IDecree {
/**
* The decrees that make up the body of this clause.
*/
@@ -41,9 +41,7 @@ public class ClauseDecree {
public ClauseDecree(Decree... children) {
this();
- for (Decree child : children) {
- body.add(child);
- }
+ for (Decree child : children) body.add(child);
}
/**
@@ -73,26 +71,34 @@ public class ClauseDecree {
@Override
public String toString() {
- try (ReportWriter rw = new ReportWriter()) {
- String term = "<null>";
- if (terminator != null)
- term = terminator.toString();
-
- rw.write("ClauseDecree (terminator " + term.toString() + ")");
- rw.indent();
- rw.write("\n");
-
- for (Decree kid : body) {
- rw.write("Child: " + kid.toString() + "\n");
- }
+ try (ReportWriter writer = new ReportWriter()) {
+ toReportWriter(writer);
- rw.dedent();
-
- return rw.toString();
+ return writer.toString();
} catch (IOException ioex) {
return "<IOEXCEPTION>";
}
// return String.format("ClauseDecree [body=%s, terminator=%s]", body,
// terminator);
}
+
+ /**
+ * Write the string version of this decree to a report writer.
+ * @param writer The report write to write to.
+ * @throws IOException If something goes wrong
+ */
+ public void toReportWriter(ReportWriter writer) throws IOException {
+ String term = "<null>";
+ if (terminator != null) term = terminator.toString();
+
+ writer.writef("ClauseDecree (terminator %s)", term);
+ writer.indent();
+ writer.write("\n");
+
+ int idx = 0;
+ for (Decree kid : body)
+ writer.writef("Child %d: %s\n", idx, kid.toString());
+
+ writer.dedent();
+ }
}
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java b/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java
index 9a90285..115ef0d 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java
@@ -8,7 +8,7 @@ package bjc.utils.ioutils.format;
*
* @author Ben Culkin.
*/
-public class Decree {
+public class Decree implements IDecree {
/**
* The name of the directive.
*/
@@ -116,10 +116,8 @@ public class Decree {
*/
public boolean isNamed(String nam) {
// Literals don't have a meaningful name
- if (isLiteral)
- return false;
-
- return name.equals(nam);
+ if (isLiteral) return false;
+ else return name.equals(nam);
}
@Override
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java
index 736e15a..7095aa5 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java
@@ -13,7 +13,7 @@ import bjc.utils.ioutils.ReportWriter;
*
* @author Ben Culkin
*/
-public class GroupDecree implements Iterable<ClauseDecree> {
+public class GroupDecree implements Iterable<ClauseDecree>, IDecree {
/**
* The decree that opened this group.
*/
@@ -45,9 +45,7 @@ public class GroupDecree implements Iterable<ClauseDecree> {
public GroupDecree(ClauseDecree... children) {
this();
- for (ClauseDecree child : children) {
- body.add(child);
- }
+ for (ClauseDecree child : children) body.add(child);
}
/**
@@ -111,27 +109,26 @@ public class GroupDecree implements Iterable<ClauseDecree> {
@Override
public String toString() {
- try (ReportWriter rw = new ReportWriter()) {
- String open = "<null>";
+ try (ReportWriter writer = new ReportWriter()) {
+ String open = "<null>";
String close = "<null>";
- if (opening != null)
- open = opening.toString();
- if (closing != null)
- close = closing.toString();
-
- rw.write("GroupDecree (opening " + open + ") (closing " + close + ")");
- rw.indent();
- rw.write("\n");
+ if (opening != null) open = opening.toString();
+ if (closing != null) close = closing.toString();
+ writer.writef("GroupDecree (opening %s) (closing %s)\n", open, close);
+ writer.indent();
+
int idx = 0;
for (ClauseDecree clause : body) {
- rw.write("Clause " + idx++ + ": " + clause.toString() + "\n");
+ writer.writef("Clause %d:", idx++);
+
+ clause.toReportWriter(writer);
}
- rw.dedent();
+ writer.dedent();
- return rw.toString();
+ return writer.toString();
} catch (IOException ioex) {
return "<IOEXCEPTION>";
}
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java
new file mode 100644
index 0000000..17b9ecf
--- /dev/null
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java
@@ -0,0 +1,14 @@
+package bjc.utils.ioutils.format;
+
+/**
+ * Interface for all decrees.
+ *
+ * At the moment, this is just a marker interface, but there may be things added
+ * here.
+ *
+ * @author Ben Culkin
+ *
+ */
+public interface IDecree {
+ // Marker interface, for now
+}