From a2b0364035a52625fc043dc62618112599013744 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:42:14 -0400 Subject: Cleanup pass II Part II of the cleanup pass --- .../java/bjc/utils/ioutils/format/CLFormatter.java | 223 ++++++++++++--------- .../java/bjc/utils/ioutils/format/CLModifiers.java | 58 +++--- .../bjc/utils/ioutils/format/CLParameters.java | 192 ++++++++++-------- .../java/bjc/utils/ioutils/format/CLPattern.java | 7 +- .../java/bjc/utils/ioutils/format/CLString.java | 61 +++--- .../java/bjc/utils/ioutils/format/CLTokenizer.java | 63 +++--- .../java/bjc/utils/ioutils/format/CLValue.java | 81 ++++---- .../bjc/utils/ioutils/format/ClauseDecree.java | 20 +- .../main/java/bjc/utils/ioutils/format/Decree.java | 35 ++-- .../bjc/utils/ioutils/format/DirectiveEscape.java | 6 +- .../java/bjc/utils/ioutils/format/GroupDecree.java | 34 ++-- .../format/directives/AestheticDirective.java | 15 +- .../ioutils/format/directives/CaseDirective.java | 9 +- .../format/directives/CharacterDirective.java | 5 +- .../ioutils/format/directives/CompileContext.java | 14 +- .../format/directives/ConditionalDirective.java | 148 +++++++------- .../utils/ioutils/format/directives/Directive.java | 25 +-- .../bjc/utils/ioutils/format/directives/Edict.java | 2 +- .../ioutils/format/directives/EscapeDirective.java | 99 +++++---- .../ioutils/format/directives/FormatContext.java | 7 +- .../format/directives/FormatParameters.java | 42 ++-- .../format/directives/FreshlineDirective.java | 5 +- .../format/directives/GeneralNumberDirective.java | 4 +- .../ioutils/format/directives/GotoDirective.java | 8 +- .../ioutils/format/directives/IndentDirective.java | 3 +- .../format/directives/InflectDirective.java | 4 +- .../format/directives/IterationDirective.java | 46 +++-- .../format/directives/LiteralDirective.java | 8 +- .../ioutils/format/directives/NumberDirective.java | 29 +-- .../ioutils/format/directives/RadixDirective.java | 27 +-- .../format/directives/RecursiveDirective.java | 19 +- .../ioutils/format/directives/StringEdict.java | 2 +- .../format/directives/TabulateDirective.java | 13 +- .../format/exceptions/MismatchedFormatArgType.java | 11 +- .../bjc/utils/test/ioutils/CLFormatterTest.java | 57 +++--- .../bjc/utils/test/ioutils/CLParametersTest.java | 4 +- .../bjc/utils/test/ioutils/CLTokenizerTest.java | 2 +- 37 files changed, 750 insertions(+), 638 deletions(-) (limited to 'clformat/src') 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 8b00769..9263beb 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java @@ -18,7 +18,7 @@ import static bjc.utils.funcutils.IteratorUtils.I; * I say 'strongly inspired' instead of 'an implementation' because there are * differences and extensions between this version of FORMAT, and the one * defined by the CLHS. - * + * * @author Ben Culkin */ public class CLFormatter { @@ -80,28 +80,29 @@ public class CLFormatter { } /* - * @TODO Ben Culkin 9/24/2019 :checkItem Convert this to return a - * boolean, not throw an exception. + * @TODO Ben Culkin 9/24/2019 :checkItem Convert this to return a boolean, not + * throw an exception. * - * In general, I want to cut down on exceptions, except for where it - * would be very inconvenient to do so (namely, the EscapeException we - * use for the ~^ directive; that would be a pain to implement by hand) + * In general, I want to cut down on exceptions, except for where it would be + * very inconvenient to do so (namely, the EscapeException we use for the ~^ + * directive; that would be a pain to implement by hand) */ /** * Check that an item is valid for a directive. - * + * * @param itm - * The item to check. + * The item to check. * * @param directive - * The directive to check for. + * The directive to check for. * * @throws IllegalArgumentException - * if itm is null. + * if itm is null. */ public static void checkItem(Object itm, char directive) { if (itm == null) { - String msg = String.format("No argument provided for %c directive", directive); + String msg + = String.format("No argument provided for %c directive", directive); throw new IllegalArgumentException(msg); } @@ -109,17 +110,17 @@ public class CLFormatter { /** * Format a string in the style of CL's FORMAT. - * + * * @param format - * The format string to use. + * The format string to use. * * @param params - * The parameters for the string. + * The parameters for the string. * * @return The formatted string. * * @throws IOException - * if something goes wrong during formatting the string. + * if something goes wrong during formatting the string. */ public String formatString(String format, Object... params) throws IOException { return formatString(format, I(AI(params))); @@ -127,19 +128,20 @@ public class CLFormatter { /** * Format a string in the style of CL's FORMAT. - * + * * @param format - * The format string to use. + * The format string to use. * * @param params - * The parameters for the string. + * The parameters for the string. * * @return The formatted string. * * @throws IOException - * if something goes wrong during formatting the string. + * if something goes wrong during formatting the string. */ - public String formatString(String format, Iterable params) throws IOException { + public String formatString(String format, Iterable params) + throws IOException { ReportWriter rw = new ReportWriter(new StringWriter()); /* Put the parameters where we can easily handle them. */ @@ -152,20 +154,21 @@ public class CLFormatter { /** * Format a string in the style of CL's FORMAT. - * + * * @param target - * The writer to send output to. + * The writer to send output to. * * @param format - * The format string to use. + * The format string to use. * * @param params - * The parameters for the string. - * + * The parameters for the string. + * * @throws IOException - * If something I/O related goes wrong. + * If something I/O related goes wrong. */ - public void formatString(Writer target, String format, Object... params) throws IOException { + public void formatString(Writer target, String format, Object... params) + throws IOException { try (ReportWriter rw = new ReportWriter(target)) { /* * Put the parameters where we can easily handle them. @@ -178,20 +181,21 @@ public class CLFormatter { /** * Format a string in the style of CL's FORMAT. - * + * * @param target - * The writer with configured format options to use. + * The writer with configured format options to use. * * @param format - * The format string to use. + * The format string to use. * * @param params - * The parameters for the string. - * + * The parameters for the string. + * * @throws IOException - * If something I/O related goes wrong. + * If something I/O related goes wrong. */ - public void formatString(ReportWriter target, String format, Object... params) throws IOException { + public void formatString(ReportWriter target, String format, Object... params) + throws IOException { /* Put the parameters where we can easily handle them. */ Tape tParams = new SingleTape<>(params); @@ -200,19 +204,21 @@ public class CLFormatter { /** * Format a string in the style of CL's FORMAT. - * + * * @param target - * The writer to send output to. + * The writer to send output to. * * @param format - * The format string to use. + * The format string to use. * * @param params - * The parameters for the string. - * - * @throws IOException If something I/O related goes wrong. + * The parameters for the string. + * + * @throws IOException + * If something I/O related goes wrong. */ - public void formatString(Writer target, String format, Iterable params) throws IOException { + public void formatString(Writer target, String format, Iterable params) + throws IOException { ReportWriter rw = new ReportWriter(target); /* Put the parameters where we can easily handle them. */ @@ -223,27 +229,27 @@ public class CLFormatter { /** * Fill in a partially started format string. - * - * Used mostly for directives that require formatting again with a - * different string. - * + * + * Used mostly for directives that require formatting again with a different + * string. + * * @param format - * The format to use. + * The format to use. * * @param rw - * The buffer to file output into. + * The buffer to file output into. * * @param tParams - * The parameters to use. + * The parameters to use. * * @param isToplevel - * Whether or not this is a top-level format + * Whether or not this is a top-level format * * @throws IOException - * If something goes wrong + * If something goes wrong */ - public void doFormatString(String format, ReportWriter rw, Tape tParams, boolean isToplevel) - throws IOException { + public void doFormatString(String format, ReportWriter rw, Tape tParams, + boolean isToplevel) throws IOException { CLTokenizer cltok = new CLTokenizer(format); doFormatString(cltok, rw, tParams, isToplevel); @@ -251,27 +257,27 @@ public class CLFormatter { /** * Fill in a partially started format string. - * - * Used mostly for directives that require formatting again with a - * different string. - * + * + * Used mostly for directives that require formatting again with a different + * string. + * * @param cltok - * The place to get tokens from. + * The place to get tokens from. * * @param rw - * The buffer to file output into. + * The buffer to file output into. * * @param tParams - * The parameters to use. + * The parameters to use. * * @param isToplevel - * Whether or not this is a top-level format + * Whether or not this is a top-level format * * @throws IOException - * If something goes wrong + * If something goes wrong */ - public void doFormatString(CLTokenizer cltok, ReportWriter rw, Tape tParams, boolean isToplevel) - throws IOException { + public void doFormatString(CLTokenizer cltok, ReportWriter rw, Tape tParams, + boolean isToplevel) throws IOException { try { while (cltok.hasNext()) { Decree decr = cltok.next(); @@ -285,15 +291,14 @@ public class CLFormatter { if (decr.isUserCall) { /* - * @TODO implement user-called - * functions. + * @TODO implement user-called functions. */ continue; } if (extraDirectives.containsKey(decr.name)) { - FormatParameters params = new FormatParameters(rw, item, decr, tParams, cltok, - this); + FormatParameters params + = new FormatParameters(rw, item, decr, tParams, cltok, this); extraDirectives.get(decr.name).format(params); @@ -301,31 +306,36 @@ public class CLFormatter { } if (builtinDirectives.containsKey(decr.name)) { - FormatParameters params = new FormatParameters(rw, item, decr, tParams, cltok, - this); + FormatParameters params + = new FormatParameters(rw, item, decr, tParams, cltok, this); builtinDirectives.get(decr.name).format(params); continue; } - if (decr.name == null) decr.name = ""; + if (decr.name == null) + decr.name = ""; switch (decr.name) { case "]": throw new IllegalArgumentException( "Found conditional-end outside of conditional."); case ";": - throw new IllegalArgumentException("Found seperator outside of block."); + throw new IllegalArgumentException( + "Found seperator outside of block."); case "}": - throw new IllegalArgumentException("Found iteration-end outside of iteration"); + 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"); + throw new IllegalArgumentException( + "Inflection-end outside of inflection"); case "<": case ">": - throw new IllegalArgumentException("Inflection marker outside of inflection"); + throw new IllegalArgumentException( + "Inflection marker outside of inflection"); case "`<": case "`>": throw new IllegalArgumentException( @@ -345,25 +355,28 @@ public class CLFormatter { /* * @TODO * - * figure out if we want to implement - * someting for these directives instead - * of punting. + * 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"); + throw new IllegalArgumentException( + "S and W aren't implemented. Use A instead"); case "P": - throw new IllegalArgumentException("These directives aren't implemented yet"); + 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); + 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; } } @@ -371,7 +384,7 @@ public class CLFormatter { * Compile a CLString from a string. * * @param inp - * The string to compile. + * The string to compile. * * @return A CLString compiled from the input. */ @@ -387,13 +400,14 @@ public class CLFormatter { * Compile a set of edicts from a list of decrees. * * @param decrees - * The decrees to compile. + * The decrees to compile. * * @return A set of edicts compiled from the decrees. */ public List compile(Iterable 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); @@ -403,12 +417,13 @@ public class CLFormatter { * Compile a set of edicts from a clause. * * @param clause - * The clause to compile. + * The clause to compile. * * @return The set of edicts compiled from the clause. */ public List compile(ClauseDecree clause) { - if (clause == null) return new ArrayList<>(); + if (clause == null) + return new ArrayList<>(); return compile(clause.body); } @@ -417,7 +432,7 @@ public class CLFormatter { * Compile a set of edicts from a set of tokens. * * @param cltok - * The tokenizer providing us with our tokens. + * The tokenizer providing us with our tokens. * * @return The edicts compiled from those tokens. */ @@ -458,25 +473,32 @@ public class CLFormatter { continue; } - if (nam == null) nam = ""; + if (nam == null) + nam = ""; switch (nam) { case "]": - throw new IllegalArgumentException("Found conditional-end outside of conditional."); + 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"); + throw new IllegalArgumentException( + "Found iteration-end outside of iteration"); case ")": - throw new IllegalArgumentException("Case-conversion end outside of case conversion"); + throw new IllegalArgumentException( + "Case-conversion end outside of case conversion"); case "`]": - throw new IllegalArgumentException("Inflection-end outside of inflection"); + throw new IllegalArgumentException( + "Inflection-end outside of inflection"); case "<": case ">": - throw new IllegalArgumentException("Inflection marker outside of inflection"); + throw new IllegalArgumentException( + "Inflection marker outside of inflection"); case "`<": case "`>": - throw new IllegalArgumentException("Layout-control directives aren't implemented yet."); + throw new IllegalArgumentException( + "Layout-control directives aren't implemented yet."); case "F": case "E": case "G": @@ -486,17 +508,20 @@ public class CLFormatter { * * implement floating point directives. */ - throw new IllegalArgumentException("Floating-point directives aren't implemented yet."); + 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. + * 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"); + throw new IllegalArgumentException( + "S and W aren't implemented. Use A instead"); case "P": - throw new IllegalArgumentException("These directives aren't implemented yet"); + throw new IllegalArgumentException( + "These directives aren't implemented yet"); case "\n": /* * Ignored newline. 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 db62539..bcd3096 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLModifiers.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLModifiers.java @@ -2,7 +2,7 @@ package bjc.utils.ioutils.format; /** * A collection of the modifiers attached to a CL format directive. - * + * * @author EVE * */ @@ -11,17 +11,17 @@ public class CLModifiers { * Whether the at mod is on. */ public final boolean atMod; - + /** * Whether the colon mod is on. */ public final boolean colonMod; - + /** * Whether the dollar mod is on. */ public final boolean dollarMod; - + /** * Whether the star mod is on. */ @@ -29,53 +29,57 @@ public class CLModifiers { /** * Create a new set of CL modifiers. - * + * * @param at - * The state of the at mod. + * The state of the at mod. * @param colon - * The state of the colon mod. + * The state of the colon mod. * @param dollar - * The state of the dollar mod. + * The state of the dollar mod. */ public CLModifiers(boolean at, boolean colon, boolean dollar, boolean star) { - atMod = at; - colonMod = colon; + atMod = at; + colonMod = colon; dollarMod = dollar; - starMod = star; + starMod = star; } /** * Create a set of modifiers from a modifier string. - * + * * @param modString - * The string to parse modifiers from. + * The string to parse modifiers from. * @return A set of modifiers matching the string. */ public static CLModifiers fromString(String modString) { - boolean atMod = false; - boolean colonMod = false; + boolean atMod = false; + boolean colonMod = false; boolean dollarMod = false; - boolean starMod = false; + boolean starMod = false; - if(modString != null) { - atMod = modString.contains("@"); - colonMod = modString.contains(":"); + if (modString != null) { + atMod = modString.contains("@"); + colonMod = modString.contains(":"); dollarMod = modString.contains("$"); - starMod = modString.contains("*"); + starMod = modString.contains("*"); } return new CLModifiers(atMod, colonMod, dollarMod, starMod); } - + @Override 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 ed89497..1ac025b 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLParameters.java @@ -13,15 +13,15 @@ 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 abbrevWords; - private AbbrevMap2 nameAbbrevs; + private AbbrevMap2 nameAbbrevs; - private Map namedParams; + private Map namedParams; private Map nameIndices; /** @@ -33,9 +33,9 @@ public class CLParameters { /** * Create a new set of CL format parameters with unnamed values. - * + * * @param params - * The CL format parameters to use. + * The CL format parameters to use. */ public CLParameters(CLValue[] params) { this(params, new HashMap<>()); @@ -45,7 +45,7 @@ public class CLParameters { * Create a new set of CL format parameters with named values. * * @param namedParams - * The named parameters to use. + * The named parameters to use. */ public CLParameters(Map namedParams) { this(new CLValue[0], namedParams); @@ -55,15 +55,15 @@ public class CLParameters { * Create a new set of CL format parameters with both types of values. * * @param params - * The unnamed parameters to use. + * The unnamed parameters to use. * * @param namedParams - * The named parameters to use. + * The named parameters to use. */ public CLParameters(CLValue[] params, Map namedParams) { this.params = params; - this.namedParams = namedParams; + this.namedParams = namedParams; this.nameIndices = new HashMap<>(); abbrevWords = new HashSet<>(); @@ -91,7 +91,8 @@ public class CLParameters { // 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); @@ -101,14 +102,16 @@ public class CLParameters { * Map a set of names to indices. * * @param opts - * The names to bind to the parameter indices. The first one will be bound to index 0, and so - * forth. Pass an empty string to not bind a name to a particular index. + * The names to bind to the parameter indices. The first one will be + * bound to index 0, and so forth. Pass an empty string to not bind + * a name to a particular index. */ public void mapIndices(String... opts) { 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(); @@ -118,10 +121,10 @@ public class CLParameters { * Map a singular name to an index. * * @param opt - * The name to map. + * The name to map. * * @param idx - * The index to map it to. + * The index to map it to. */ public void mapIndex(String opt, int idx) { mapIndex(opt, idx, true); @@ -130,32 +133,34 @@ public class CLParameters { // Actually do the work of mapping an index private void mapIndex(String opt, int idx, boolean doRefresh) { if (params.length <= idx) { - System.err.printf("WARN: Mapping invalid index %d (max %d) to \"%s\"\n", - idx, params.length, opt.toUpperCase()); + System.err.printf("WARN: Mapping invalid index %d (max %d) to \"%s\"\n", idx, + params.length, opt.toUpperCase()); } nameIndices.put(opt.toUpperCase(), idx); - if (doRefresh) refreshAbbrevs(); + if (doRefresh) + refreshAbbrevs(); } /** * Get a parameter by an index. * * @param idx - * The index to grab. + * The index to grab. * * @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]; } /** * Get the length of the parameter list. - * + * * @return The length of the parameters. */ public int length() { @@ -165,11 +170,11 @@ public class CLParameters { /** * Creates a set of parameters from a parameter string. * - * This handles things like quoted strings, named parameters and the - * other special parameter features. + * This handles things like quoted strings, named parameters and the other + * special parameter features. * * @param unsplit - * The string to parse parameters from. + * The string to parse parameters from. * * @return A set of CL parameters. */ @@ -188,11 +193,11 @@ public class CLParameters { if (c == ',' && prevChar != '\'' && !inStr) { lParams.add(currParm.toString()); - + currParm = new StringBuilder(); } else if (c == '"' && prevChar != '\'') { inStr = true; - + currParm.append(c); } else if (inStr && c == '"' && prevChar != '\'') { inStr = false; @@ -215,10 +220,10 @@ public class CLParameters { return new CLParameters(parameters.toArray(new CLValue[0])); } - Map namedParams = new HashMap<>(); + Map namedParams = new HashMap<>(); // Set up parameter names - for(String param : lParams) { + for (String param : lParams) { if (param.startsWith("#") && !param.equals("#")) { // Named parameter boolean setIndex = false; @@ -230,7 +235,8 @@ public class CLParameters { if (ch == ':' || ch == ';') { // Semicolon says to add as // indexed parameter - if (ch == ';') setIndex = true; + if (ch == ';') + setIndex = true; nameIdx = i; break; @@ -239,13 +245,14 @@ public class CLParameters { // Trim off the 'hash' indicator String paramName = param.substring(1, nameIdx); - String paramVal = param.substring(nameIdx + 1); + String paramVal = param.substring(nameIdx + 1); CLValue actVal = parseParam(paramVal); namedParams.put(paramName.toUpperCase(), actVal); - if (setIndex) parameters.add(actVal); + if (setIndex) + parameters.add(actVal); } else { parameters.add(parseParam(param)); } @@ -272,7 +279,7 @@ public class CLParameters { * Get the corresponding value for a key. * * @param key - * The name of the parameter to look up. + * The name of the parameter to look up. * * @return The value for that key, or null if none exists. */ @@ -284,7 +291,7 @@ public class CLParameters { * Get the corresponding value for a key. * * @param key - * The name of the parameter to look up. + * The name of the parameter to look up. * * @return The value for that key, or null if none exists. */ @@ -293,7 +300,8 @@ public class CLParameters { Set keys = nameAbbrevs.deabbrevAll(ucKey); - // We didn't find a parameter that could have been that. Create an appropriate and useful + // We didn't find a parameter that could have been that. Create an appropriate + // and useful // error message. if (keys.size() > 1) { StringBuilder sb = new StringBuilder(); @@ -303,8 +311,10 @@ public class CLParameters { sb.append("\". Could've meant: "); boolean isFirst = true; for (String possKey : keys) { - if (!isFirst) sb.append(", "); - if (isFirst) isFirst = false; + if (!isFirst) + sb.append(", "); + if (isFirst) + isFirst = false; sb.append("\""); sb.append(possKey); @@ -325,10 +335,11 @@ public class CLParameters { // @NOTE 9/22/18 // // Consider whether we should throw an exception here. - if (idx < 0 || idx >= params.length) return null; + if (idx < 0 || idx >= params.length) + return null; return params[idx]; - } + } return null; } @@ -337,29 +348,32 @@ public class CLParameters { * Get a boolean-valued parameter. * * @param params - * The format parameters to use. + * The format parameters to use. * * @param key - * The name of the parameter to use for a key. + * The name of the parameter to use for a key. * * @param paramName - * The name of the parameter, as a user-intelligble string. + * The name of the parameter, as a user-intelligble string. * * @param directive - * The directive this parameter belongs to. + * The directive this parameter belongs to. * * @param def - * The default value for this parameter. + * The default value for this parameter. * - * @return The boolean value for that parameter, or the default value if that parameter didn't - * exist. + * @return The boolean value for that parameter, or the default value if that + * parameter didn't exist. */ - public boolean getBoolean(Tape params, String key, String paramName, String directive, boolean def) { + public boolean getBoolean(Tape params, String key, String paramName, + String directive, boolean def) { String bol = resolveKey(key).getValue(params); - if(!bol.equals("")) { - if (bol.matches(RX_TRUE)) return true; - else if (bol.matches(RX_FALSE)) return false; + if (!bol.equals("")) { + 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); @@ -373,31 +387,33 @@ public class CLParameters { * Get the string value for a parameter. * * @param params - * The format parameters we're using. + * The format parameters we're using. * * @param key - * The key for the parameter. + * The key for the parameter. * * @param paramName - * The user-intelligble name for the parameter. + * The user-intelligble name for the parameter. * * @param directive - * The directive this parameter is for. + * The directive this parameter is for. * * @param def - * The default value for the parameter. + * The default value for the parameter. * - * @return The string value of the parameter, or the default value if there is no parameter by - * that name. + * @return The string value of the parameter, or the default value if there is + * no parameter by that name. */ - public String getString(Tape params, String key, String paramName, String directive, String def) { + public String getString(Tape params, String key, String paramName, + String directive, String def) { String vl = resolveKey(key).getValue(params); // @NOTE 9/19/17 // // 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; } @@ -406,21 +422,22 @@ public class CLParameters { * Get the character value of a parameter. * * @param params - * The format parameters to use. + * The format parameters to use. * * @param key - * The key for the parameter. + * The key for the parameter. * * @param paramName - * The user-intelligble name for the parameter. + * The user-intelligble name for the parameter. * * @param directive - * The directive the parameter is for. + * The directive the parameter is for. * - * @return The character value of the parameter, or the default value if the parameter isn't - * specified. + * @return The character value of the parameter, or the default value if the + * parameter isn't specified. */ - public char getChar(Tape params, String key, String paramName, String directive, char def) { + public char getChar(Tape params, String key, String paramName, + String directive, char def) { String param = resolveKey(key).getValue(params); if (!param.equals("")) { @@ -430,7 +447,7 @@ public class CLParameters { return param.charAt(0); } - if(!param.startsWith("'")) { + if (!param.startsWith("'")) { throw new IllegalArgumentException( String.format(MSG_FMT, paramName, key, param, directive)); } @@ -445,30 +462,31 @@ public class CLParameters { * Get the integer value for a parameter. * * @param params - * The format parameters we are using. + * The format parameters we are using. * * @param key - * The key for the parameter. + * The key for the parameter. * * @param paramName - * The user-intelligble name for the parameter. + * The user-intelligble name for the parameter. * * @param directive - * The directive the parameter is for. + * The directive the parameter is for. * * @param def - * The default value for the parameter. + * The default value for the parameter. * - * @return The integer value of the parameter, or the default value if there is no parameter by - * that name. + * @return The integer value of the parameter, or the default value if there is + * no parameter by that name. */ - public int getInt(Tape params, String key, String paramName, String directive, int def) { + public int getInt(Tape params, String key, String paramName, String directive, + int def) { String param = resolveKey(key).getValue(params); if (!param.equals("")) { try { return Integer.parseInt(param); - } catch(NumberFormatException nfex) { + } catch (NumberFormatException nfex) { String msg = String.format(MSG_FMT, paramName, key, param, directive); IllegalArgumentException iaex = new IllegalArgumentException(msg); @@ -495,16 +513,19 @@ public class CLParameters { 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); } @@ -519,11 +540,14 @@ 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); @@ -534,11 +558,13 @@ 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/CLPattern.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLPattern.java index 86fbc30..b3d7762 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLPattern.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLPattern.java @@ -9,7 +9,7 @@ import bjc.utils.ioutils.SimpleProperties; /** * Utility class for reading in the pattern for parsing format directives. - * + * * @author bjculkin * */ @@ -40,7 +40,8 @@ public class CLPattern { directiveName = props.get("clFormatName"); prefixList = String.format(props.get("delimSeparatedList"), prefixParam, ","); - formatDirective = String.format(props.get("clFormatDirective"), prefixList, formatMod, directiveName); + formatDirective = String.format(props.get("clFormatDirective"), prefixList, + formatMod, directiveName); pFormatDirective = Pattern.compile(formatDirective); } @@ -49,7 +50,7 @@ public class CLPattern { * Get a matcher for FORMAT directives. * * @param inp - * The string to parse directives from. + * The string to parse directives from. */ public static Matcher getDirectiveMatcher(String inp) { return pFormatDirective.matcher(inp); 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 7fe5884..01e7617 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLString.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLString.java @@ -19,7 +19,7 @@ public class CLString { * Create a new compiled format string. * * @param edts - * The compiled directives that make up the format. + * The compiled directives that make up the format. */ public CLString(List edts) { edicts = edts; @@ -27,13 +27,14 @@ public class CLString { /** * Execute this string with the given parameters. - * - * @param parms - * The format parameters for the string. - * + * + * @param parms + * The format parameters for the string. + * * @return The result from executing the format string. - * - * @throws IOException If something I/O related has gone wrong. + * + * @throws IOException + * If something I/O related has gone wrong. */ public String format(Object... parms) throws IOException { StringWriter sw = new StringWriter(); @@ -44,16 +45,17 @@ public class CLString { /** * Execute this string with the given parameters. - * + * * @param rw - * The writer to write the string to. - * + * The writer to write the string to. + * * @param itms - * The format parameters to use. - * + * The format parameters to use. + * * @return The result of executing the string. - * - * @throws IOException If something I/O related goes wrong. + * + * @throws IOException + * If something I/O related goes wrong. */ public String format(ReportWriter rw, Tape itms) throws IOException { FormatContext formCTX = new FormatContext(rw, itms); @@ -63,16 +65,17 @@ public class CLString { /** * Execute this string with the given parameters. - * + * * @param rw - * The writer to write the string to. - * + * The writer to write the string to. + * * @param parms - * The format parameters to use. - * + * The format parameters to use. + * * @return The result of executing the string. - * - * @throws IOException If something I/O related goes wrong. + * + * @throws IOException + * If something I/O related goes wrong. */ public String format(ReportWriter rw, Object... parms) throws IOException { Tape itms = new SingleTape<>(parms); @@ -84,13 +87,14 @@ public class CLString { /** * Execute a format string in a given context. + * + * @param formCTX + * The context to use for formatting. * - * @param formCTX - * The context to use for formatting. - * * @return The result of executing the format string. - * - * @throws IOException If something I/O related goes wrong. + * + * @throws IOException + * If something I/O related goes wrong. */ public String format(FormatContext formCTX) throws IOException { try { @@ -106,11 +110,12 @@ public class CLString { /** * Is this format string empty? (does it have 0 edicts?) - * + * * @return If this format string is empty. */ public boolean isEmpty() { - if (edicts.size() == 0) return true; + if (edicts.size() == 0) + return true; return false; } 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 a3e718a..af7c935 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java @@ -5,7 +5,7 @@ import java.util.regex.*; /** * Tokenizer for creating @{link Decree}s from strings. - * + * * @author bjculkin * */ @@ -39,7 +39,7 @@ public class CLTokenizer implements Iterator { @Override public Decree next() { Decree nxt = body.next(); - + return nxt; } } @@ -49,8 +49,8 @@ public class CLTokenizer implements Iterator { private Decree dir; /** - * Empty constructor that should only be invoked if you are a subclass who overrides - * hasNext()/next(). + * Empty constructor that should only be invoked if you are a subclass who + * overrides hasNext()/next(). */ protected CLTokenizer() { @@ -60,7 +60,7 @@ public class CLTokenizer implements Iterator { * Create a new tokenizer, tokenizing from a given string. * * @param strang - * The string to tokenize from. + * The string to tokenize from. */ public CLTokenizer(String strang) { this.mat = CLPattern.getDirectiveMatcher(strang); @@ -70,7 +70,7 @@ public class CLTokenizer implements Iterator { * Create a CLTokenizer yielding a given set of decrees. * * @param bod - * The decrees to yield. + * The decrees to yield. * * @return A tokenizer yielding the given set of decrees. */ @@ -82,7 +82,7 @@ public class CLTokenizer implements Iterator { * Create a CLTokenizer yielding a given set of decrees. * * @param bod - * The decrees to yield. + * The decrees to yield. * * @return A tokenizer yielding the given set of decrees. */ @@ -105,7 +105,8 @@ public class CLTokenizer implements Iterator { } private Decree getNext() { - if (!hasNext()) throw new NoSuchElementException("No possible decrees remaining"); + if (!hasNext()) + throw new NoSuchElementException("No possible decrees remaining"); if (dir != null) { Decree tmp = dir; @@ -119,27 +120,26 @@ public class CLTokenizer implements Iterator { while (mat.find()) { mat.appendReplacement(sb, ""); - + String tmp = sb.toString(); { - String dirName = mat.group("name"); - String dirFunc = mat.group("funcname"); - String dirMods = mat.group("modifiers"); + String dirName = mat.group("name"); + String dirFunc = mat.group("funcname"); + String dirMods = mat.group("modifiers"); String dirParams = mat.group("params"); - if(dirMods == null) { + if (dirMods == null) { dirMods = ""; } - if(dirParams == null) { + if (dirParams == null) { dirParams = ""; } boolean isUser = dirName == null && dirFunc != null; - dir = new Decree(dirName, isUser, - CLParameters.fromDirective(dirParams), + dir = new Decree(dirName, isUser, CLParameters.fromDirective(dirParams), CLModifiers.fromString(dirMods)); } @@ -163,10 +163,10 @@ public class CLTokenizer implements Iterator { * Read in a group decree. * * @param openedWith - * The decree that started the group. + * The decree that started the group. * * @param desiredClosing - * The name of the decree that will close the group. + * The name of the decree that will close the group. * * @return A group decree with the given properties. */ @@ -178,28 +178,31 @@ public class CLTokenizer implements Iterator { * Read in a group decree. * * @param openedWith - * The decree that started the group. + * The decree that started the group. * * @param desiredClosing - * The name of the decree that will close the group. + * The name of the decree that will close the group. * * @param clauseSep - * The name of the decree that will separate clauses in the group. Pass 'null' if this group - * doesn't have separate clauses. + * The name of the decree that will separate clauses in + * the group. Pass 'null' if this group doesn't have + * separate clauses. * * @return A group decree with the given properties. */ - public GroupDecree nextGroup(Decree openedWith, String desiredClosing, String clauseSep) { + public GroupDecree nextGroup(Decree openedWith, String desiredClosing, + String clauseSep) { 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(); int nestingLevel = 1; - Decree curDecree; + Decree curDecree; do { curDecree = next(); @@ -218,7 +221,8 @@ public class CLTokenizer implements Iterator { break; } else if (clauseSep != null && curDecree.isNamed(clauseSep)) { - if (DEBUG) System.err.printf("[TRACE] Clause separator %s\n", curDecree); + if (DEBUG) + System.err.printf("[TRACE] Clause separator %s\n", curDecree); curClause.terminator = curDecree; newGroup.addChild(curClause); @@ -242,7 +246,8 @@ public class CLTokenizer implements Iterator { } while (hasNext()); if (newGroup.closing == null) { - String msg = String.format("Did not find closing directive for group (wanted \"%s\", last decree was \"%s\")", + String msg = String.format( + "Did not find closing directive for group (wanted \"%s\", last decree was \"%s\")", desiredClosing, curDecree.name); throw new NoSuchElementException(msg); 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 5f2f726..e4b4c32 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLValue.java @@ -13,12 +13,13 @@ public interface CLValue { * Create a CLValue from a string. * * @param val - * The string to create the value from. - * + * The string to create the value from. + * * @return The CLValue represented by the string. */ public static CLValue parse(String val) { - if (val == null) return new NullValue(); + if (val == null) + return new NullValue(); if (val.equalsIgnoreCase("V")) { return new VValue(); @@ -41,12 +42,12 @@ public interface CLValue { * Get the value of the parameter. * * @param params - * The parameters passed to the directive. + * The parameters passed to the directive. * * @return The string value of the parameter. */ public String getValue(Tape params); - + /** * The format string to use for an invalid usage of a directive. */ @@ -54,28 +55,30 @@ public interface CLValue { /** * Get the value as an integer. - * + * * @param params - * The format parameters to use. - * + * The format parameters to use. + * * @param paramName - * The user-intelligble name for the value. - * + * The user-intelligble name for the value. + * * @param directive - * The directive this value is for. - * + * The directive this value is for. + * * @param def - * The default value for this value. - * - * @return The value as an integer, or the default value if the value has no value. + * The default value for this value. + * + * @return The value as an integer, or the default value if the value has no + * value. */ - public default int asInt(Tape params, String paramName, String directive, int def) { + public default int asInt(Tape params, String paramName, String directive, + int def) { String param = getValue(params); if (param != null && !param.equals("")) { try { return Integer.parseInt(param); - } catch(NumberFormatException nfex) { + } catch (NumberFormatException nfex) { String msg = String.format(MSG_FMT, paramName, param, directive); IllegalArgumentException iaex = new IllegalArgumentException(msg); @@ -90,7 +93,7 @@ public interface CLValue { /** * Get a CLValue that represent 'nothing'. - * + * * @return A CLValue that represents nothing. */ public static CLValue nil() { @@ -99,22 +102,24 @@ public interface CLValue { /** * Get the value as a character. - * + * * @param params - * The format parameters to use. - * + * The format parameters to use. + * * @param paramName - * The user-intelligble name for the value. - * + * The user-intelligble name for the value. + * * @param directive - * The directive the value is for. - * + * The directive the value is for. + * * @param def - * The default value for the value. - * - * @return The value as an character, or the default value if the value has no value. + * The default value for the value. + * + * @return The value as an character, or the default value if the value has no + * value. */ - public default char asChar(Tape params, String paramName, String directive, char def) { + public default char asChar(Tape params, String paramName, String directive, + char def) { String param = getValue(params); if (param != null && !param.equals("")) { @@ -124,7 +129,7 @@ public interface CLValue { return param.charAt(0); } - if(!param.startsWith("'")) { + if (!param.startsWith("'")) { throw new IllegalArgumentException( String.format(MSG_FMT, paramName, param, directive)); } @@ -182,18 +187,18 @@ class VValue implements CLValue { Object par = params.item(); boolean succ = params.right(); - if(!succ) { + if (!succ) { throw new IllegalStateException("Couldn't advance tape for parameter"); - } else if(par == null) { + } else if (par == null) { throw new IllegalArgumentException( "Expected a format parameter for V inline parameter"); - } + } - if(par instanceof Number) { + if (par instanceof Number) { int val = ((Number) par).intValue(); return Integer.toString(val); - } else if(par instanceof Character) { + } else if (par instanceof Character) { char ch = ((Character) par); return Character.toString(ch); @@ -219,7 +224,7 @@ class LiteralValue implements CLValue { * Create a new CLValue. * * @param vul - * The value of the parameter. + * The value of the parameter. */ public LiteralValue(String vul) { val = vul; @@ -229,11 +234,11 @@ class LiteralValue implements CLValue { * Get the value of the parameter. * * @param params - * The parameters passed to the directive. + * The parameters passed to the directive. */ @Override public String getValue(Tape params) { - return val; + return val; } @Override 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 2fd7eda..aa4efbe 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java @@ -8,8 +8,8 @@ import bjc.utils.ioutils.ReportWriter; /** * A decree that represents a single clause in a {@link GroupDecree}. * - * Has a list of decrees for a body, and then a single decree as the 'terminator' if this was a - * terminated clause. + * Has a list of decrees for a body, and then a single decree as the + * 'terminator' if this was a terminated clause. * * @author Ben Culkin */ @@ -36,7 +36,7 @@ public class ClauseDecree { * Create a new clause decree with specific contents. * * @param children - * The decrees to form the body of the clause. + * The decrees to form the body of the clause. */ public ClauseDecree(Decree... children) { this(); @@ -50,10 +50,10 @@ public class ClauseDecree { * Create a new clause with both a body and a terminator. * * @param term - * The decree that terminates the clause. - * + * The decree that terminates the clause. + * * @param children - * The decrees that form the body of the clause. + * The decrees that form the body of the clause. */ public ClauseDecree(Decree term, Decree... children) { this(children); @@ -65,7 +65,7 @@ public class ClauseDecree { * Add a decree to this clause. * * @param child - * The decree to add to this clause. + * The decree to add to this clause. */ public void addChild(Decree child) { body.add(child); @@ -75,7 +75,8 @@ public class ClauseDecree { public String toString() { try (ReportWriter rw = new ReportWriter()) { String term = ""; - if (terminator != null) term = terminator.toString(); + if (terminator != null) + term = terminator.toString(); rw.write("ClauseDecree (terminator " + term.toString() + ")"); rw.indent(); @@ -91,6 +92,7 @@ public class ClauseDecree { } catch (IOException ioex) { return ""; } - // return String.format("ClauseDecree [body=%s, terminator=%s]", body, terminator); + // return String.format("ClauseDecree [body=%s, terminator=%s]", body, + // terminator); } } 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 7900f2c..9a90285 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java @@ -45,7 +45,7 @@ public class Decree { * Create a new literal text directive. * * @param txt - * The text of the directive. + * The text of the directive. */ public Decree(String txt) { this.name = txt; @@ -57,15 +57,15 @@ public class Decree { * Create a new directive. * * @param name - * The name of the directive. Whether or not it is an - * actual directive will be auto-determined (if it starts - * with a ~, it's a directive.) + * The name of the directive. Whether or not it is an actual + * directive will be auto-determined (if it starts with a ~, it's + * a directive.) * * @param params - * The prefix parameters to the directive. + * The prefix parameters to the directive. * * @param mods - * The modifiers to the directive. + * The modifiers to the directive. */ public Decree(String name, CLParameters params, CLModifiers mods) { this.name = name; @@ -81,19 +81,18 @@ public class Decree { * Create a new directive that may be a user function. * * @param name - * The name of the directive. Whether or not it is an - * actual directive will be auto-determined (if it starts - * with a ~ and is not a user function, it's a - * directive.) + * The name of the directive. Whether or not it is an actual + * directive will be auto-determined (if it starts with a ~ and is + * not a user function, it's a directive.) * * @param isUser - * Is this directive a user function? + * Is this directive a user function? * * @param params - * The prefix parameters to the directive. + * The prefix parameters to the directive. * * @param mods - * The modifiers to the directive. + * The modifiers to the directive. */ public Decree(String name, boolean isUser, CLParameters params, CLModifiers mods) { this.name = name; @@ -111,20 +110,22 @@ public class Decree { * Check if this decree is a non-literal, with a particular name. * * @param nam - * The name to see if we have. + * The name to see if we have. * * @return Whether or not the provided name equals our name. */ public boolean isNamed(String nam) { // Literals don't have a meaningful name - if (isLiteral) return false; + if (isLiteral) + return false; return name.equals(nam); } @Override public String toString() { - return String.format("Decree [name='%s', isLiteral=%s, isUserCall=%s, parameters=%s, modifiers='%s']", name, - isLiteral, isUserCall, parameters, modifiers); + return String.format( + "Decree [name='%s', isLiteral=%s, isUserCall=%s, parameters=%s, modifiers='%s']", + name, isLiteral, isUserCall, parameters, modifiers); } } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/DirectiveEscape.java b/clformat/src/main/java/bjc/utils/ioutils/format/DirectiveEscape.java index c0908f0..da57318 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/DirectiveEscape.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/DirectiveEscape.java @@ -2,7 +2,7 @@ package bjc.utils.ioutils.format; /** * An exception thrown to escape CL iteration directives. - * + * * @author EVE * */ @@ -23,9 +23,9 @@ public class DirectiveEscape extends RuntimeException { /** * Create a new directive escape. - * + * * @param end - * Whether or not to end the iteration. + * Whether or not to end the iteration. */ public DirectiveEscape(boolean end) { endIteration = end; 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 47401a9..736e15a 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java @@ -8,7 +8,8 @@ import bjc.utils.ioutils.ReportWriter; /** * Represents an enclosed group of decrees. * - * This is used for all of the decrees that take another format string as part of their body. + * This is used for all of the decrees that take another format string as part + * of their body. * * @author Ben Culkin */ @@ -17,7 +18,7 @@ public class GroupDecree implements Iterable { * The decree that opened this group. */ public Decree opening; - + /** * The decree that closed this group. */ @@ -39,7 +40,7 @@ public class GroupDecree implements Iterable { * Create a new group decree with a given body. * * @param children - * The decrees that form the body of the group. + * The decrees that form the body of the group. */ public GroupDecree(ClauseDecree... children) { this(); @@ -53,13 +54,13 @@ public class GroupDecree implements Iterable { * Create a new group decree with all of the fields filled out. * * @param opening - * The decree opening the group. + * The decree opening the group. * * @param closing - * The decree closing the group. + * The decree closing the group. * * @param children - * The decree making up the body of the group. + * The decree making up the body of the group. */ public GroupDecree(Decree opening, Decree closing, ClauseDecree... children) { this(children); @@ -72,7 +73,7 @@ public class GroupDecree implements Iterable { * Add a decree to this group. * * @param child - * The decree to add to the group. + * The decree to add to the group. */ public void addChild(ClauseDecree child) { body.add(child); @@ -91,8 +92,8 @@ public class GroupDecree implements Iterable { * Get a specific clause from the group. * * @param idx - * The index of the clause to get. - * + * The index of the clause to get. + * * @return The clause at that index. */ public ClauseDecree clause(int idx) { @@ -100,8 +101,8 @@ public class GroupDecree implements Iterable { } /** - * Get the body of the first clause. - * + * Get the body of the first clause. + * * @return The decrees that make up the body of the first clause. */ public List unwrap() { @@ -114,8 +115,10 @@ public class GroupDecree implements Iterable { String open = ""; String close = ""; - if (opening != null) open = opening.toString(); - if (closing != null) close = closing.toString(); + if (opening != null) + open = opening.toString(); + if (closing != null) + close = closing.toString(); rw.write("GroupDecree (opening " + open + ") (closing " + close + ")"); rw.indent(); @@ -132,9 +135,10 @@ public class GroupDecree implements Iterable { } catch (IOException ioex) { return ""; } - // return String.format("GroupDecree [opening=%s, closing=%s, body=%s]", opening, closing, body); + // return String.format("GroupDecree [opening=%s, closing=%s, body=%s]", + // opening, closing, body); } - + @Override public Iterator iterator() { return body.iterator(); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java index 42d5c68..4fec0e0 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/AestheticDirective.java @@ -7,9 +7,9 @@ import bjc.utils.ioutils.format.*; /** * Implementation of the A directive. - * - * This is the directive that does general printing of things, and serves the same general purpose - * as the '%s' directive for printf etc. + * + * This is the directive that does general printing of things, and serves the + * same general purpose as the '%s' directive for printf etc. * * @author Ben Culkin */ @@ -28,7 +28,7 @@ public class AestheticDirective implements Directive { // We take 0, 1 or 4 parameters switch (params.length()) { - case 0: + case 0: // Zero parameters, use all defaults break; case 1: @@ -46,7 +46,8 @@ public class AestheticDirective implements Directive { padchar = params.resolveKey("padchar"); break; default: - throw new IllegalArgumentException("Must provide either zero, one or four arguments to A directive"); + throw new IllegalArgumentException( + "Must provide either zero, one or four arguments to A directive"); } return new AestheticEdict(mods.atMod, padchar, mincol, colinc, minpad); @@ -64,7 +65,7 @@ class AestheticEdict implements Edict { public AestheticEdict(boolean padBefore, CLValue padPar, CLValue minPar, CLValue colPar, CLValue mpadPar) { this.padBefore = padBefore; - + this.padcharPar = padPar; this.mincolPar = minPar; this.colincPar = colPar; @@ -82,7 +83,7 @@ class AestheticEdict implements Edict { StringBuilder work = new StringBuilder(); - char padchar = padcharPar.asChar(itemTape, "padding character", "A", ' '); + char padchar = padcharPar.asChar(itemTape, "padding character", "A", ' '); int mincol = mincolPar.asInt(itemTape, "minimum column count", "A", 0); int colinc = colincPar.asInt(itemTape, "padding increment", "A", 1); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java index d1ab4ab..7e1ca87 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CaseDirective.java @@ -16,10 +16,11 @@ import bjc.utils.ioutils.format.*; public class CaseDirective implements Directive { /** * Compile a case directive. - * + * * @param compCTX - * The context to use for compilation. + * The context to use for compilation. */ + @Override public Edict compile(CompileContext compCTX) { CLModifiers mods = compCTX.decr.modifiers; @@ -115,8 +116,8 @@ class CaseEdict implements Edict { strang = strang.toLowerCase(); break; default: - throw new IllegalArgumentException("INTERNAL ERROR: CaseEdict mode " + caseMode - + " is not supported. This is a bug."); + throw new IllegalArgumentException("INTERNAL ERROR: CaseEdict mode " + + caseMode + " is not supported. This is a bug."); } formCTX.writer.write(strang); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CharacterDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CharacterDirective.java index f8cc039..ca0432c 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CharacterDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CharacterDirective.java @@ -8,8 +8,9 @@ import bjc.utils.ioutils.format.*; /** * Implements the C directive. - * - * This serves to print out a single character, in the way that the '%c' printf directive does. + * + * This serves to print out a single character, in the way that the '%c' printf + * directive does. * * @author Ben Culkin */ diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java index 4bbae6b..3c5f692 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java @@ -25,20 +25,20 @@ public class CompileContext { /** * Create a new compilation context. - * + * * @param dirs - * The directives to compile from. - * + * The directives to compile from. + * * @param fmt - * The formatter being used to compile. - * + * The formatter being used to compile. + * * @param dcr - * The decree currently being compiled. + * The decree currently being compiled. */ public CompileContext(CLTokenizer dirs, CLFormatter fmt, Decree dcr) { directives = dirs; formatter = fmt; - + decr = dcr; } } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/ConditionalDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/ConditionalDirective.java index bd2e6f7..c26a936 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/ConditionalDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/ConditionalDirective.java @@ -8,7 +8,7 @@ import bjc.utils.ioutils.format.*; /** * Implements the [ directive. - * + * * This does varying sorts of conditional dispatches on which string to use for * formatting, allowing it to be based off of general conditions in varying * ways. @@ -23,18 +23,20 @@ public class ConditionalDirective implements Directive { GroupDecree clauses = compCTX.directives.nextGroup(compCTX.decr, "]", ";"); - ClauseDecree defClause = null; + ClauseDecree defClause = null; boolean isDefault = false; for (ClauseDecree clause : clauses) { - if (isDefault) defClause = clause; + if (isDefault) + defClause = clause; if (clause.terminator != null && clause.terminator.modifiers.colonMod) { isDefault = true; } } - if (mods.starMod && clauses.size() > 0) defClause = clauses.clause(); + if (mods.starMod && clauses.size() > 0) + defClause = clauses.clause(); CLValue index = null; @@ -54,16 +56,14 @@ public class ConditionalDirective implements Directive { mode = ConditionalEdict.Mode.INDEX_CLAUSE; } - return new ConditionalEdict(mode, mods.dollarMod, index, clauses, - defClause, compCTX.formatter); + return new ConditionalEdict(mode, mods.dollarMod, index, clauses, defClause, + compCTX.formatter); } } class ConditionalEdict implements Edict { public static enum Mode { - FIRST_SECOND, - OUTPUT_TRUE, - INDEX_CLAUSE + FIRST_SECOND, OUTPUT_TRUE, INDEX_CLAUSE } private Mode condMode; @@ -78,9 +78,8 @@ class ConditionalEdict implements Edict { @SuppressWarnings("unused") private CLFormatter formatter; - public ConditionalEdict(Mode condMode, boolean decrementIndex, - CLValue index, GroupDecree clauses, ClauseDecree defClause, - CLFormatter fmt) { + public ConditionalEdict(Mode condMode, boolean decrementIndex, CLValue index, + GroupDecree clauses, ClauseDecree defClause, CLFormatter fmt) { this.condMode = condMode; this.decrementIndex = decrementIndex; @@ -101,86 +100,87 @@ class ConditionalEdict implements Edict { try { switch (condMode) { - case FIRST_SECOND: - { - Object o = items.item(); - items.right(); + case FIRST_SECOND: { + Object o = items.item(); + items.right(); + + boolean res = false; + if (o == null) { + // throw new IllegalArgumentException("No parameter provided for [ + // directive."); + } else if (!(o instanceof Boolean)) { + throw new IllegalFormatConversionException('[', o.getClass()); + } else { + res = (Boolean) o; + } - boolean res = false; - if (o == null) { - //throw new IllegalArgumentException("No parameter provided for [ directive."); - } else if (!(o instanceof Boolean)) { - throw new IllegalFormatConversionException('[', o.getClass()); - } else { - res = (Boolean) o; - } + CLString frmt; + if (res) { + frmt = clauses.get(1); + } else { + frmt = clauses.get(0); + } - CLString frmt; - if (res) { - frmt = clauses.get(1); - } else { - frmt = clauses.get(0); + frmt.format(formCTX); + } + break; + case OUTPUT_TRUE: { + boolean res = false; + Object o = items.item(); + + if (o == null) { + // throw new IllegalArgumentException("No parameter provided for [ + // directive."); + } else if (o instanceof Integer) { + if ((Integer) o != 0) { + res = true; } + } else if (o instanceof Boolean) { + res = (Boolean) o; + } else { + throw new IllegalFormatConversionException('[', o.getClass()); + } - frmt.format(formCTX); + if (res) { + clauses.get(0).format(formCTX); + } else { + items.right(); } + } break; - case OUTPUT_TRUE: - { - boolean res = false; + case INDEX_CLAUSE: { + int res; + + if (index != null) { + res = index.asInt(items, "conditional choice", "[", 0); + } else { Object o = items.item(); if (o == null) { - // throw new IllegalArgumentException("No parameter provided for [ directive."); - } else if (o instanceof Integer) { - if ((Integer)o != 0) { - res = true; - } - } else if (o instanceof Boolean) { - res = (Boolean) o; - } else { + throw new IllegalArgumentException( + "No parameter provided for [ directive."); + } else if (!(o instanceof Number)) { throw new IllegalFormatConversionException('[', o.getClass()); } - if (res) { - clauses.get(0).format(formCTX); - } else { - items.right(); - } - } - break; - case INDEX_CLAUSE: - { - int res; - - if (index != null) { - res = index.asInt(items, "conditional choice", "[", 0); - } else { - Object o = items.item(); + res = ((Number) o).intValue(); - if (o == null) { - throw new IllegalArgumentException("No parameter provided for [ directive."); - } else if (!(o instanceof Number)) { - throw new IllegalFormatConversionException('[', o.getClass()); - } + items.right(); + } - res = ((Number) o).intValue(); + if (decrementIndex) + res -= 1; - items.right(); + if (clauses.size() == 0 || res < 0 || res >= clauses.size()) { + if (defClause != null) { + defClause.format(formCTX.writer, items); } + } else { + CLString frmt = clauses.get(res); - if (decrementIndex) res -= 1; - - if (clauses.size() == 0 || res < 0 || res >= clauses.size()) { - if (defClause != null) { - defClause.format(formCTX.writer, items); - } - } else { - CLString frmt = clauses.get(res); - - frmt.format(formCTX.writer, items); - } + frmt.format(formCTX.writer, items); } + } break; } } catch (DirectiveEscape dex) { diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/Directive.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/Directive.java index d6617de..90df6c7 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/Directive.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/Directive.java @@ -4,7 +4,7 @@ import java.io.IOException; /** * A CL format directive. - * + * * @author Ben Culkin */ public interface Directive { @@ -12,8 +12,9 @@ public interface Directive { * Execute this format directive. * * @param dirParams - * The parameters for the directive. - * @throws IOException If something goes wrong. + * The parameters for the directive. + * @throws IOException + * If something goes wrong. */ public default void format(FormatParameters dirParams) throws IOException { Edict edt = compile(dirParams.toCompileCTX()); @@ -25,24 +26,25 @@ public interface Directive { * Compile this directive. * * @param compCTX - * The state necessary to compile this directive. + * The state necessary to compile this directive. * * @return A compiled form of this directive. */ public default Edict compile(CompileContext compCTX) { - throw new IllegalArgumentException("This directive does not support compilation yet"); + throw new IllegalArgumentException( + "This directive does not support compilation yet"); } /** * Check if a particular directive is an opening directive. * * @param str - * The directive to check. + * The directive to check. * * @return Whether or not the directive is opening. */ public static boolean isOpening(String str) { - switch(str) { + switch (str) { case "(": case "<": case "[": @@ -58,13 +60,12 @@ public interface Directive { * Check if a particular directive is an opening directive. * * @param str - * The directive to check. + * The directive to check. * - * @return - * Whether or not the directive is opening. + * @return Whether or not the directive is opening. */ public static boolean isClosing(String str) { - switch(str) { + switch (str) { case ")": case ">": case "]": @@ -81,5 +82,5 @@ public interface Directive { // Implement something for parsing contained bodies, abstracting the // stuff that Iteration/Conditional/CaseDirective do. // - // The main issue is thinking of a good interface to it. + // The main issue is thinking of a good interface to it. } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/Edict.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/Edict.java index e037f06..6cb0192 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/Edict.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/Edict.java @@ -14,7 +14,7 @@ public interface Edict { * Invoke this format directive. * * @param formCTX - * The state needed for this invocation. + * The state needed for this invocation. */ public void format(FormatContext formCTX) throws IOException; } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/EscapeDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/EscapeDirective.java index e426f97..343a54d 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/EscapeDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/EscapeDirective.java @@ -22,42 +22,39 @@ public class EscapeDirective implements Directive { EscapeEdict.Mode mode; switch (params.length()) { - case 0: - mode = EscapeEdict.Mode.END; - break; - case 1: - mode = EscapeEdict.Mode.COUNT; - params.mapIndices("count"); - param1 = params.resolveKey("count"); - break; - case 2: - params.mapIndices("lhand", "rhand"); - param1 = params.resolveKey("lhand"); - param2 = params.resolveKey("rhand"); - mode = EscapeEdict.Mode.EQUALITY; - break; - case 3: - params.mapIndices("lower", "ival", "upper"); - param1 = params.resolveKey("lower"); - param2 = params.resolveKey("ival"); - param3 = params.resolveKey("upper"); - mode = EscapeEdict.Mode.RANGE; - break; - default: - throw new IllegalArgumentException("Too many parameters to ^ directive"); + case 0: + mode = EscapeEdict.Mode.END; + break; + case 1: + mode = EscapeEdict.Mode.COUNT; + params.mapIndices("count"); + param1 = params.resolveKey("count"); + break; + case 2: + params.mapIndices("lhand", "rhand"); + param1 = params.resolveKey("lhand"); + param2 = params.resolveKey("rhand"); + mode = EscapeEdict.Mode.EQUALITY; + break; + case 3: + params.mapIndices("lower", "ival", "upper"); + param1 = params.resolveKey("lower"); + param2 = params.resolveKey("ival"); + param3 = params.resolveKey("upper"); + mode = EscapeEdict.Mode.RANGE; + break; + default: + throw new IllegalArgumentException("Too many parameters to ^ directive"); } - return new EscapeEdict(mods.atMod, mode, mods.colonMod, param1, param2, - param3, mods.dollarMod); + return new EscapeEdict(mods.atMod, mode, mods.colonMod, param1, param2, param3, + mods.dollarMod); } } class EscapeEdict implements Edict { public static enum Mode { - END, - COUNT, - EQUALITY, - RANGE + END, COUNT, EQUALITY, RANGE } private Mode mode; @@ -91,41 +88,41 @@ class EscapeEdict implements Edict { Tape items = formCTX.items; - if (advance) items.right(); + if (advance) + items.right(); switch (mode) { case END: shouldExit = items.atEnd(); break; - case COUNT: - { - int num = param1.asInt(items, "condition count", "^", 0); + case COUNT: { + int num = param1.asInt(items, "condition count", "^", 0); - shouldExit = (num == 0); - } + shouldExit = (num == 0); + } break; - case EQUALITY: - { - int left = param1.asInt(items, "left-hand condition", "^", 0); - int right = param2.asInt(items, "right-hand condition", "^", 0); + case EQUALITY: { + int left = param1.asInt(items, "left-hand condition", "^", 0); + int right = param2.asInt(items, "right-hand condition", "^", 0); - shouldExit = (left == right); - } + shouldExit = (left == right); + } break; - case RANGE: - { - int low = param1.asInt(items, "lower-bound condition", "^", 0); - int mid = param2.asInt(items, "interval condition", "^", 0); - int high = param3.asInt(items, "upper-bound condition", "^", 0); - - shouldExit = (low <= mid) && (mid <= high); - } + case RANGE: { + int low = param1.asInt(items, "lower-bound condition", "^", 0); + int mid = param2.asInt(items, "interval condition", "^", 0); + int high = param3.asInt(items, "upper-bound condition", "^", 0); + + shouldExit = (low <= mid) && (mid <= high); + } break; default: - throw new IllegalArgumentException("Escape condition mode " + mode + " isn't supported"); + throw new IllegalArgumentException( + "Escape condition mode " + mode + " isn't supported"); } - if (advance) items.left(); + if (advance) + items.left(); if (isNegated) { shouldExit = !shouldExit; diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatContext.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatContext.java index f2e0ee9..1bc475a 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatContext.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatContext.java @@ -26,9 +26,9 @@ public class FormatContext { * Create a new format context. * * @param rw - * The writer to store output into. + * The writer to store output into. * @param itms - * The items that shall serve as format parameters. + * The items that shall serve as format parameters. */ public FormatContext(ReportWriter rw, Tape itms) { writer = rw; @@ -37,7 +37,8 @@ public class FormatContext { } /** - * Get a new scratch writer, with the same format settings as the current writer. + * Get a new scratch writer, with the same format settings as the current + * writer. * * @return A new writer, as described above. */ diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java index f74f22f..3ffa4ed 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java @@ -6,11 +6,11 @@ import bjc.utils.ioutils.format.*; /** * The set of parameters used during formatting. - * + * * Since the refactor to use compilation (e.g {@link CLString} and it's ilk), * this is now mostly used as a way of creating the {@link FormatContext} and * {@link CompileContext} objects. - * + * * @author bjculkin * */ @@ -47,27 +47,27 @@ public class FormatParameters { /** * Create a new set of format parameters. - * + * * @param rw - * The writer we are sending output to. - * + * The writer we are sending output to. + * * @param item - * The current format parameter. - * + * The current format parameter. + * * @param decr - * The decree being formatted. - * + * The decree being formatted. + * * @param tParams - * The list of all the format parameters. - * + * The list of all the format parameters. + * * @param dirIter - * The set of format decrees. - * + * The set of format decrees. + * * @param fmt - * The formatter we are using + * The formatter we are using */ - public FormatParameters(ReportWriter rw, Object item, Decree decr, Tape tParams, - CLTokenizer dirIter, CLFormatter fmt) { + public FormatParameters(ReportWriter rw, Object item, Decree decr, + Tape tParams, CLTokenizer dirIter, CLFormatter fmt) { this.rw = rw; this.item = item; @@ -83,7 +83,7 @@ public class FormatParameters { /** * Get the parameters for the current decree. - * + * * @return The parameters to the current decree. */ public CLParameters getParams() { @@ -92,7 +92,7 @@ public class FormatParameters { /** * Get the modifiers for the current decree. - * + * * @return The modifiers for the current decree. */ public CLModifiers getMods() { @@ -101,16 +101,16 @@ public class FormatParameters { /** * Convert this set of parameters into a compilation context. - * + * * @return The compilation context from these parameters. */ public CompileContext toCompileCTX() { return new CompileContext(dirIter, fmt, decr); } - + /** * Convert this set of parameters into a format context. - * + * * @return The format context from these parameters. */ public FormatContext toFormatCTX() { diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FreshlineDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FreshlineDirective.java index 5609086..7402c98 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FreshlineDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FreshlineDirective.java @@ -38,9 +38,10 @@ class FreshlineEdict implements Edict { public void format(FormatContext formCTX) throws IOException { int nTimes = times.asInt(formCTX.items, "occurance count", "&", 1); - if (formCTX.writer.isLastCharNL()) nTimes -= 1; + if (formCTX.writer.isLastCharNL()) + nTimes -= 1; - for(int i = 0; i < nTimes; i++) { + for (int i = 0; i < nTimes; i++) { formCTX.writer.write("\n"); } } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/GeneralNumberDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/GeneralNumberDirective.java index fdb78cc..cd6c70c 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/GeneralNumberDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/GeneralNumberDirective.java @@ -4,14 +4,14 @@ import bjc.utils.ioutils.format.*; /** * Implementation skeleton for number directives. - * + * * @author student * */ public abstract class GeneralNumberDirective implements Directive { /** * Parameters for doing number formatting. - * + * * @author bjculkin * */ diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/GotoDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/GotoDirective.java index e2fc74b..aea107f 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/GotoDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/GotoDirective.java @@ -5,7 +5,7 @@ import bjc.utils.ioutils.format.*; /** * Implement the * directive. - * + * * @author student * */ @@ -47,9 +47,7 @@ public class GotoDirective implements Directive { class GotoEdict implements Edict { public static enum Mode { - FORWARD, - BACKWARD, - INDEX + FORWARD, BACKWARD, INDEX } private Mode mode; @@ -67,7 +65,7 @@ class GotoEdict implements Edict { Tape items = formCTX.items; int num; - switch(mode) { + switch (mode) { case FORWARD: num = numVal.asInt(items, "number of arguments forward", "*", 1); items.right(num); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java index b7dce36..a19866f 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java @@ -4,6 +4,7 @@ import bjc.utils.ioutils.format.*; /** * Implement the I directive. + * * @author student * */ @@ -18,7 +19,7 @@ public class IndentDirective implements Directive { } CLValue indentCount = CLValue.nil(); - if(params.length() >= 1) { + if (params.length() >= 1) { params.mapIndices("count"); indentCount = params.resolveKey("count"); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java index b9de4af..8ed39fb 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java @@ -8,6 +8,7 @@ import bjc.utils.ioutils.format.*; /** * Inflection directive. + * * @author bjculkin * */ @@ -44,7 +45,8 @@ public class InflectDirective implements Directive { nestLevel = Math.max(0, nestLevel - 1); /* End the iteration. */ - if (nestLevel == 0) break; + if (nestLevel == 0) + break; } else if (Directive.isClosing(dirName)) { nestLevel = Math.max(0, nestLevel - 1); } else { diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java index 438b3e0..b8cdf36 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java @@ -7,7 +7,7 @@ import bjc.utils.ioutils.format.*; /** * Implements the { directive. - * + * * @author student * */ @@ -66,10 +66,7 @@ class IterationEdict implements Edict { private static final char DIR_NAME = '{'; public static enum Mode { - ALL_SUBLISTS, - ALL, - SUBLIST, - NORMAL + ALL_SUBLISTS, ALL, SUBLIST, NORMAL } private Mode mode; @@ -91,7 +88,8 @@ class IterationEdict implements Edict { @Override public void format(FormatContext formCTX) throws IOException { - int maxIterations = maxItrVal.asInt(formCTX.items, "maximum iterations", "{", Integer.MAX_VALUE); + int maxIterations = maxItrVal.asInt(formCTX.items, "maximum iterations", "{", + Integer.MAX_VALUE); int numIterations = 0; @@ -110,7 +108,8 @@ class IterationEdict implements Edict { strang = (String) iter; if (!formCTX.items.right()) { - throw new IllegalArgumentException("Not enough parameters to '{' directive"); + throw new IllegalArgumentException( + "Not enough parameters to '{' directive"); } iter = formCTX.items.item(); @@ -120,11 +119,13 @@ class IterationEdict implements Edict { case ALL_SUBLISTS: try { do { - if (numIterations > maxIterations) break; + if (numIterations > maxIterations) + break; numIterations += 1; if (!(iter instanceof Iterable)) { - throw new IllegalFormatConversionException(DIR_NAME, iter.getClass()); + throw new IllegalFormatConversionException(DIR_NAME, + iter.getClass()); } @SuppressWarnings("unchecked") @@ -134,8 +135,10 @@ class IterationEdict implements Edict { try { if (usingString) { // @Speed @Memory :DynamicFormatString - // For a speed/memory tradeoff here, we could be compiling strang into a - // CLString and then caching those compiled string. However, we aren't + // For a speed/memory tradeoff here, we could be compiling + // strang into a + // CLString and then caching those compiled string. However, + // we aren't // doing that now. -- ben, 12/17/19 fmt.doFormatString(strang, formCTX.writer, nParams, false); } else { @@ -159,7 +162,8 @@ class IterationEdict implements Edict { case ALL: try { while (!formCTX.items.atEnd()) { - if (numIterations > maxIterations) break; + if (numIterations > maxIterations) + break; numIterations += 1; @@ -172,7 +176,8 @@ class IterationEdict implements Edict { } } catch (DirectiveEscape eex) { if (eex.endIteration) - throw new UnsupportedOperationException("Colon mod not allowed on escape marker without colon mod on iteration"); + throw new UnsupportedOperationException( + "Colon mod not allowed on escape marker without colon mod on iteration"); } break; case SUBLIST: @@ -187,11 +192,13 @@ class IterationEdict implements Edict { while (itr.hasNext()) { Object obj = itr.next(); - if (numIterations > maxIterations) break; + if (numIterations > maxIterations) + break; numIterations += 1; if (!(obj instanceof Iterable)) { - throw new IllegalFormatConversionException(DIR_NAME, obj.getClass()); + throw new IllegalFormatConversionException(DIR_NAME, + obj.getClass()); } @SuppressWarnings("unchecked") @@ -206,7 +213,8 @@ class IterationEdict implements Edict { body.format(formCTX.writer, nParams); } } catch (DirectiveEscape eex) { - if(eex.endIteration && !itr.hasNext()) throw eex; + if (eex.endIteration && !itr.hasNext()) + throw eex; } } } catch (DirectiveEscape eex) { @@ -224,7 +232,8 @@ class IterationEdict implements Edict { Tape nParams = new SingleTape<>(itr); while (!nParams.atEnd()) { - if (numIterations > maxIterations) break; + if (numIterations > maxIterations) + break; numIterations += 1; if (usingString) { @@ -236,7 +245,8 @@ class IterationEdict implements Edict { } } catch (DirectiveEscape eex) { if (eex.endIteration) - throw new UnsupportedOperationException("Colon mod not allowed on escape marker without colon mod on iteration"); + throw new UnsupportedOperationException( + "Colon mod not allowed on escape marker without colon mod on iteration"); } break; default: diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java index d783e97..c63bf4e 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/LiteralDirective.java @@ -6,7 +6,7 @@ import bjc.utils.ioutils.format.*; /** * Implements directives that create a literal string. - * + * * @author student * */ @@ -15,11 +15,11 @@ public class LiteralDirective implements Directive { /** * Create a new literal directive. - * + * * @param lit - * The string for the directive. + * The string for the directive. * @param directive - * The character for the directive. + * The character for the directive. */ public LiteralDirective(String lit, char directive) { Character.toString(directive); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java index c0e8c72..9208b0e 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/NumberDirective.java @@ -10,18 +10,18 @@ import static bjc.utils.ioutils.format.directives.GeneralNumberDirective.NumberP /** * Implements radix based numbers. - * + * * @author student * */ public class NumberDirective extends GeneralNumberDirective { /** * Create a new radix based number directive. - * + * * @param argidx - * The argument offset to use. + * The argument offset to use. * @param radix - * The radix of the number to use. + * The radix of the number to use. */ public NumberDirective(int argidx, int radix, char directive) { this.argidx = argidx; @@ -50,9 +50,9 @@ class NumberEdict implements Edict { private NumberParams np; public NumberEdict(int radix, char directive, int argidx, NumberParams np) { - this.radix = radix; + this.radix = radix; this.directive = Character.toString(directive); - + this.np = np; } @@ -63,23 +63,28 @@ class NumberEdict implements Edict { CLFormatter.checkItem(item, directive.charAt(0)); if (!(item instanceof Number)) { - throw new IllegalFormatConversionException(directive.charAt(0), item.getClass()); + throw new IllegalFormatConversionException(directive.charAt(0), + item.getClass()); } long val = ((Number) item).longValue(); - int mincol = np.mincol.asInt(formCTX.items, "minimum column count", directive, 0); - char padchar = np.padchar.asChar(formCTX.items, "padding character", directive, ' '); + int mincol = np.mincol.asInt(formCTX.items, "minimum column count", directive, 0); + char padchar + = np.padchar.asChar(formCTX.items, "padding character", directive, ' '); boolean signed = np.signed; String res; if (np.commaMode) { - char commaChar = np.commaChar.asChar(formCTX.items, "comma character", directive, ','); - int commaInterval = np.commaInterval.asInt(formCTX.items, "comma interval", directive, 0); + char commaChar = np.commaChar.asChar(formCTX.items, "comma character", + directive, ','); + int commaInterval = np.commaInterval.asInt(formCTX.items, "comma interval", + directive, 0); - res = NumberUtils.toCommaString(val, mincol, padchar, commaInterval, commaChar, signed, radix); + res = NumberUtils.toCommaString(val, mincol, padchar, commaInterval, + commaChar, signed, radix); } else { res = NumberUtils.toNormalString(val, mincol, padchar, signed, radix); } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/RadixDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/RadixDirective.java index 4a3f1e8..e3ccfb4 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/RadixDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/RadixDirective.java @@ -10,7 +10,7 @@ import static bjc.utils.ioutils.format.directives.GeneralNumberDirective.NumberP /** * Generalized radix directive. - * + * * @author student * */ @@ -38,7 +38,8 @@ public class RadixDirective extends GeneralNumberDirective { mode = RadixEdict.Mode.NORMAL; if (params.length() < 1) - throw new IllegalArgumentException("R directive requires at least one parameter, the radix"); + throw new IllegalArgumentException( + "R directive requires at least one parameter, the radix"); params.mapIndex("radix", 0); radixVal = params.resolveKey("radix"); @@ -52,10 +53,7 @@ public class RadixDirective extends GeneralNumberDirective { class RadixEdict implements Edict { public static enum Mode { - NORMAL, - ROMAN, - ORDINAL, - CARDINAL + NORMAL, ROMAN, ORDINAL, CARDINAL } private Mode mode; @@ -97,20 +95,23 @@ class RadixEdict implements Edict { case CARDINAL: res = NumberUtils.toCardinal(val); break; - case NORMAL: - { + case NORMAL: { int radix = radixVal.asInt(formCTX.items, "radix", "R", 10); - int mincol = np.mincol.asInt(formCTX.items, "minimum column count", "R", 0); - char padchar = np.padchar.asChar(formCTX.items, "padding character", "R", ' '); + int mincol = np.mincol.asInt(formCTX.items, "minimum column count", "R", 0); + char padchar + = np.padchar.asChar(formCTX.items, "padding character", "R", ' '); boolean signed = np.signed; if (np.commaMode) { - char commaChar = np.commaChar.asChar(formCTX.items, "comma character", "R", ','); - int commaInterval = np.commaInterval.asInt(formCTX.items, "comma interval", "R", 0); + char commaChar + = np.commaChar.asChar(formCTX.items, "comma character", "R", ','); + int commaInterval + = np.commaInterval.asInt(formCTX.items, "comma interval", "R", 0); - res = NumberUtils.toCommaString(val, mincol, padchar, commaInterval, commaChar, signed, radix); + res = NumberUtils.toCommaString(val, mincol, padchar, commaInterval, + commaChar, signed, radix); } else { res = NumberUtils.toNormalString(val, mincol, padchar, signed, radix); } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/RecursiveDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/RecursiveDirective.java index 2cbd7ab..41c7adb 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/RecursiveDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/RecursiveDirective.java @@ -6,9 +6,10 @@ import bjc.utils.ioutils.format.*; import bjc.utils.ioutils.format.exceptions.*; /** - * Implementation of the ? directive, which does recursive execution of a format string. - * - * @author bjculkin + * Implementation of the ? directive, which does recursive execution of a format + * string. + * + * @author bjculkin * */ public class RecursiveDirective implements Directive { @@ -31,7 +32,8 @@ class RecursiveEdict implements Edict { @Override public void format(FormatContext formCTX) throws IOException { - // System.err.printf("[TRACE] Processing ? directive with params: " + formCTX.items.toString()); + // System.err.printf("[TRACE] Processing ? directive with params: " + + // formCTX.items.toString()); Object body = formCTX.items.item(); formCTX.items.right(); @@ -42,7 +44,7 @@ class RecursiveEdict implements Edict { } try { - String bod = (String)body; + String bod = (String) body; fmt.doFormatString(bod, formCTX.writer, formCTX.items, true); } catch (DirectiveEscape eex) { @@ -52,7 +54,8 @@ class RecursiveEdict implements Edict { } } else { if (formCTX.items.atEnd()) { - throw new IllegalArgumentException("? directive requires two format parameters"); + throw new IllegalArgumentException( + "? directive requires two format parameters"); } Object o = formCTX.items.item(); @@ -67,11 +70,11 @@ class RecursiveEdict implements Edict { } @SuppressWarnings("unchecked") - Iterable itb = (Iterable)o; + Iterable itb = (Iterable) o; Tape newParams = new SingleTape<>(itb); try { - String bod = (String)body; + String bod = (String) body; // :DynamicString fmt.doFormatString(bod, formCTX.writer, newParams, true); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/StringEdict.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/StringEdict.java index 8267145..ff7c215 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/StringEdict.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/StringEdict.java @@ -14,7 +14,7 @@ public class StringEdict implements Edict { * Create a new string edict for a given string. * * @param vl - * The string to print. + * The string to print. */ public StringEdict(String vl) { this.val = vl; diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java index d4aa9d0..91b40c3 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java @@ -7,8 +7,9 @@ import bjc.utils.ioutils.ReportWriter; import bjc.utils.ioutils.format.*; /** - * Implementation of the T directive, which is used for some formatting based controls. - * + * Implementation of the T directive, which is used for some formatting based + * controls. + * * @author bjculkin * */ @@ -55,13 +56,14 @@ class TabulateEdict implements Edict { private CLValue colincVal; private CLValue colidVal; - public TabulateEdict(boolean isRelative, CLValue colinc, boolean fromIndent, CLValue colid) { + public TabulateEdict(boolean isRelative, CLValue colinc, boolean fromIndent, + CLValue colid) { this.isRelative = isRelative; this.fromIndent = fromIndent; this.colincVal = colinc; - this.colidVal = colid; + this.colidVal = colid; } @Override @@ -104,7 +106,8 @@ class TabulateEdict implements Edict { rw.write(padchar); } } else { - if (colinc == 0) return; + if (colinc == 0) + return; int k = 0; diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/exceptions/MismatchedFormatArgType.java b/clformat/src/main/java/bjc/utils/ioutils/format/exceptions/MismatchedFormatArgType.java index 32a62d8..fca6c44 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/exceptions/MismatchedFormatArgType.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/exceptions/MismatchedFormatArgType.java @@ -12,7 +12,7 @@ public class MismatchedFormatArgType extends RuntimeException { * Create a new format arg mismatch with a given message. * * @param msg - * The message for the exception. + * The message for the exception. */ public MismatchedFormatArgType(String msg) { super(msg); @@ -22,15 +22,16 @@ public class MismatchedFormatArgType extends RuntimeException { * Create a new standard format arg mismatch. * * @param dir - * The directive this argument was for. + * The directive this argument was for. * * @param expected - * The class we expected to get. + * The class we expected to get. * * @param got - * The class we actually got. + * The class we actually got. */ public MismatchedFormatArgType(String dir, Class expected, Class got) { - this(String.format("Bad format argument to %s directive: got %s, expected %s", dir, got.getName(), expected.getName())); + this(String.format("Bad format argument to %s directive: got %s, expected %s", + dir, got.getName(), expected.getName())); } } diff --git a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java index 8f9010c..96723f4 100644 --- a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java +++ b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java @@ -10,7 +10,7 @@ import static org.junit.Assert.*; /** * Tests for CL format strings. - * + * * @author EVE * */ @@ -21,7 +21,8 @@ public class CLFormatterTest { @Test public void testLiteralString() { // @TODO :assertFormat Ben Culkin 1/3/20 - // Convert all of these 'assertEquals(..., format(...))' to use assertFormat instead + // Convert all of these 'assertEquals(..., format(...))' to use assertFormat + // instead // Print literal strings exactly assertEquals("foo", format("foo")); } @@ -29,7 +30,7 @@ public class CLFormatterTest { @Test public void testDecimalPrinting() { // Test decimal printing - assertEquals("5", format("~D", 5)); + assertEquals("5", format("~D", 5)); assertEquals(" 5", format("~3D", 5)); assertEquals("005", format("~3,'0D", 5)); assertEquals("6|55|35", format("~,,'|,2:D", 0xFFFF)); @@ -57,24 +58,25 @@ public class CLFormatterTest { @Test public void testConditionalPrinting() { // Test conditional printing - assertEquals("print length = 5", format("~@[print level = ~D~]~@[print length = ~D~]", null, 5)); + assertEquals("print length = 5", + format("~@[print level = ~D~]~@[print length = ~D~]", null, 5)); } @Test public void testIterationPrinting() { - assertEquals("The winners are: fred harry jill.", format("The winners are:~{ ~S~}.", - asList("fred", "harry", "jill"))); - assertEquals("Pairs: (1, 1) (2, 2) (3, 3).", format("Pairs:~{ (~S, ~S)~}.", - asList(1, 1, 2, 2, 3, 3))); + assertEquals("The winners are: fred harry jill.", + format("The winners are:~{ ~S~}.", asList("fred", "harry", "jill"))); + assertEquals("Pairs: (1, 1) (2, 2) (3, 3).", + format("Pairs:~{ (~S, ~S)~}.", asList(1, 1, 2, 2, 3, 3))); assertEquals("Pairs: (1, 1) (2, 2) (3, 3).", format("Pairs:~:{ (~S, ~S)~}.", - asList(asList(1, 1), asList(2, 2), asList(3, 3)))); + asList(asList(1, 1), asList(2, 2), asList(3, 3)))); - assertEquals("Pairs: (1, 1) (2, 2) (3, 3).", format("Pairs:~@{ (~S, ~S)~}.", - 1, 1, 2, 2, 3, 3)); + assertEquals("Pairs: (1, 1) (2, 2) (3, 3).", + format("Pairs:~@{ (~S, ~S)~}.", 1, 1, 2, 2, 3, 3)); assertEquals("Pairs: (1, 1) (2, 2) (3, 3).", format("Pairs:~:@{ (~S, ~S)~}.", - asList(1, 1), asList(2, 2), asList(3, 3))); + asList(1, 1), asList(2, 2), asList(3, 3))); } @Test @@ -82,15 +84,16 @@ public class CLFormatterTest { assertEquals(" 7", format("~? ~D", "<~A ~D>", asList("Foo", 5), 7)); assertEquals(" 7", format("~? ~D", "<~A ~D>", asList("Foo", 5, 14), 7)); - assertEquals(" 7", format("~@? ~D", "<~A ~D>", "Foo", 5, 7)); + assertEquals(" 7", format("~@? ~D", "<~A ~D>", "Foo", 5, 7)); assertEquals(" 14", format("~@? ~D", "<~A ~D>", "Foo", 5, 14, 7)); } @Test public void testEscapePrinting() { - assertEquals("Done.", format("Done.~^ ~D warning.~^ ~D error.")); - assertEquals("Done. 3 warning.", format("Done.~^ ~D warning.~^ ~D error.", 3)); - assertEquals("Done. 1 warning. 5 error.", format("Done.~^ ~D warning.~^ ~D error.", 1, 5)); + assertEquals("Done.", format("Done.~^ ~D warning.~^ ~D error.")); + assertEquals("Done. 3 warning.", format("Done.~^ ~D warning.~^ ~D error.", 3)); + assertEquals("Done. 1 warning. 5 error.", + format("Done.~^ ~D warning.~^ ~D error.", 1, 5)); } @Test @@ -98,20 +101,23 @@ public class CLFormatterTest { assertEquals("XIV xiv", format("~@R ~(~@R~)", 14, 14)); } - //@Test + // @Test public void testListPrinting() { // Test printing a list - // String fmtStr = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#[~; and~] ~A~^,~}~]."; - String fmtStr = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#*[ ~A,~; and ~A~; ~A~]~}~]."; + // String fmtStr = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#[~; and~] + // ~A~^,~}~]."; + String fmtStr + = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#*[ ~A,~; and ~A~; ~A~]~}~]."; fmt.DEBUG = true; - assertEquals("Items: none.", format(fmtStr)); + assertEquals("Items: none.", format(fmtStr)); fmt.DEBUG = false; - assertEquals("Items: foo.", format(fmtStr, "foo")); - assertEquals("Items: foo and bar.", format(fmtStr, "foo", "bar")); - assertEquals("Items: foo, bar and baz.", format(fmtStr, "foo", "bar", "baz")); - assertEquals("Items: foo, bar, baz and quux.", format(fmtStr, "foo", "bar", "baz", "quux")); + assertEquals("Items: foo.", format(fmtStr, "foo")); + assertEquals("Items: foo and bar.", format(fmtStr, "foo", "bar")); + assertEquals("Items: foo, bar and baz.", format(fmtStr, "foo", "bar", "baz")); + assertEquals("Items: foo, bar, baz and quux.", + format(fmtStr, "foo", "bar", "baz", "quux")); } @Test @@ -119,7 +125,8 @@ public class CLFormatterTest { assertFormat("foo", "~A", "foo"); assertFormat("foobar ", "~7A", "foobar"); assertFormat(" foobar", "~7@A", "foobar"); - assertFormat(" foobar", "~#mincol;8,#colinc;2,#minpad;1,#padchar;' @A", "foobar"); + assertFormat(" foobar", "~#mincol;8,#colinc;2,#minpad;1,#padchar;' @A", + "foobar"); } @Test diff --git a/clformat/src/test/java/bjc/utils/test/ioutils/CLParametersTest.java b/clformat/src/test/java/bjc/utils/test/ioutils/CLParametersTest.java index ffe94ef..304bdc2 100644 --- a/clformat/src/test/java/bjc/utils/test/ioutils/CLParametersTest.java +++ b/clformat/src/test/java/bjc/utils/test/ioutils/CLParametersTest.java @@ -35,7 +35,7 @@ public class CLParametersTest { assertEquals("First integer reads correctly", "1", val1.getValue(scratch)); assertEquals("Second integer reads correctly", "2", val2.getValue(scratch)); - } + } { CLParameters params = fromDirective("'a,\"abc\""); @@ -50,7 +50,7 @@ public class CLParametersTest { { CLParameters params = fromDirective("1,2,3"); - params.mapIndices("arg1","arrg2","arg3"); + params.mapIndices("arg1", "arrg2", "arg3"); CLValue val1 = params.resolveKey("arg1"); CLValue val2 = params.resolveKey("arr"); diff --git a/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java b/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java index c5b63a4..429c089 100644 --- a/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java +++ b/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java @@ -20,7 +20,7 @@ public class CLTokenizerTest { assertTrue("Empty tokenizer has a decree", tokenzer.hasNext()); Decree dec = tokenzer.next(); assertFalse("Empty tokenizer has only one decree", tokenzer.hasNext()); - + assertTrue("Decree from empty tokenizer is a literal", dec.isLiteral); assertEquals("Decree from empty tokenizer is empty", "", dec.name); } -- cgit v1.2.3