diff options
Diffstat (limited to 'src/main/java/tlIItools/ReplPair.java')
| -rw-r--r-- | src/main/java/tlIItools/ReplPair.java | 173 |
1 files changed, 56 insertions, 117 deletions
diff --git a/src/main/java/tlIItools/ReplPair.java b/src/main/java/tlIItools/ReplPair.java index 74012716..90717a0a 100644 --- a/src/main/java/tlIItools/ReplPair.java +++ b/src/main/java/tlIItools/ReplPair.java @@ -1,51 +1,31 @@ package tlIItools; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; +import java.util.*; -/** - * String pairs for replacements. +/** String pairs for replacements. * - * @author Ben Culkin - */ + * @author Ben Culkin */ public class ReplPair implements Comparable<ReplPair> { - /** - * Represents an error encountered parsing ReplPairs + /** Represents an error encountered parsing ReplPairs * - * @author Ben Culkin - */ + * @author Ben Culkin */ public static class ReplError { - /** - * The line the error occured on. - */ + /** The line the error occured on. */ public int line; - /** - * The number of pairs we have processed so far. - */ + /** The number of pairs we have processed so far. */ public int numPairs; - /** - * The text of the line we errored on. - */ + /** The text of the line we errored on. */ public String txt; - /** - * The message of the error. - */ + /** The message of the error. */ public String msg; - /** - * Create a new ReplPair parse error. + /** Create a new ReplPair parse error. * - * @param lne - * The line the error occured on. - * @param nPairs - * The number of pairs processed up to this point. - * @param msg - * The message detailing the error. - * @param txt - * The text that caused the error. - */ + * @param lne The line the error occured on. + * @param nPairs The number of pairs processed up to this point. + * @param msg The message detailing the error. + * @param txt The text that caused the error. */ public ReplError(int lne, int nPairs, String msg, String txt) { line = lne; numPairs = nPairs; @@ -65,86 +45,56 @@ public class ReplPair implements Comparable<ReplPair> { } } - /** - * The priority for this replacement. - */ + /** The priority for this replacement. */ public int priority; - - /** - * The name of this replacement. + /** The name of this replacement. * - * Defaults to the 'find' string. - */ + * Defaults to the 'find' string. */ public String name; - /** - * The string to look for. - */ + /** The string to look for. */ public String find; - - /** - * The string to replace it with. - */ + /** The string to replace it with. */ public String replace; - /** - * Create a new blank replacement pair. - */ + /** Create a new blank replacement pair. */ public ReplPair() { this("", "", 1, null); } - /** - * Create a new replacement pair with a priority of 1. + /** Create a new replacement pair with a priority of 1. * - * @param f - * The string to find. - * @param r - * The string to replace. + * @param f The string to find. + * @param r The string to replace. */ public ReplPair(String f, String r) { this(f, r, 1); } - /** - * Create a new named replacement pair with a priority of 1. + /** Create a new named replacement pair with a priority of 1. * - * @param f - * The string to find. - * @param r - * The string to replace. - * @param n - * The name of the replacement pair. + * @param f The string to find. + * @param r The string to replace. + * @param n The name of the replacement pair. */ public ReplPair(String f, String r, String n) { this(f, r, 1, n); } - /** - * Create a new replacement pair with a set priority. + /** Create a new replacement pair with a set priority. * - * @param f - * The string to find. - * @param r - * The string to replace. - * @param p - * The priority for the replacement. - */ + * @param f The string to find. + * @param r The string to replace. + * @param p The priority for the replacement. */ public ReplPair(String f, String r, int p) { this(f, r, p, f); } - /** - * Create a new replacement pair with a set priority and name. + /** Create a new replacement pair with a set priority and name. * - * @param f - * The string to find. - * @param r - * The string to replace. - * @param n - * The name of the replacement pair. - * @param p - * The priority for the replacement. - */ + * @param f The string to find. + * @param r The string to replace. + * @param n The name of the replacement pair. + * @param p The priority for the replacement. */ public ReplPair(String f, String r, int p, String n) { find = f; replace = r; @@ -153,29 +103,23 @@ public class ReplPair implements Comparable<ReplPair> { priority = p; } - /** - * Read a list of replacement pairs from an input source. + + /** Read a list of replacement pairs from an input source. * - * @param scn - * The source to read the replacements from. - * @return - * The list of replacements. - */ + * @param scn The source to read the replacements from. + * + * @return The list of replacements. */ public static List<ReplPair> readList(Scanner scn) { return ReplPair.readList(new ArrayList<>(), scn); } - /** - * Read a list of replacement pairs from an input source, adding them to + /** Read a list of replacement pairs from an input source, adding them to * an existing list. * - * @param detals - * The list to add the replacements to. - * @param scn - * The source to read the replacements from. - * @return - * The list of replacements. - */ + * @param detals The list to add the replacements to. + * @param scn The source to read the replacements from. + * + * @return The list of replacements. */ public static List<ReplPair> readList(List<ReplPair> detals, Scanner scn) { List<ReplError> errList = new ArrayList<>(); @@ -186,25 +130,22 @@ public class ReplPair implements Comparable<ReplPair> { if (errList.size() == 0) errString = "An error"; else errString = "Errors"; - throw new IllegalArgumentException(String.format("%s occured parsing replacement pairs:\n%s", errString, errList)); + throw new IllegalArgumentException(String.format( + "%s occured parsing replacement pairs:\n%s", + errString, errList)); } return rplPar; } - /** - * Read a list of replacement pairs from an input source, adding them to + /** Read a list of replacement pairs from an input source, adding them to * an existing list. * - * @param detals - * The list to add the replacements to. - * @param scn - * The source to read the replacements from. - * @param errs - * The list to stick errors in. - * @return - * The list of replacements. - */ + * @param detals The list to add the replacements to. + * @param scn The source to read the replacements from. + * @param errs The list to stick errors in. + * + * @return The list of replacements. */ public static List<ReplPair> readList(List<ReplPair> detals, Scanner scn, List<ReplError> errs) { int lno = 0; int pno = 0; @@ -236,8 +177,7 @@ public class ReplPair implements Comparable<ReplPair> { // Read in the next uncommented line do { if (!scn.hasNextLine()) { - String msg = - "Ran out of input looking for replacement body for raw name " + name; + String msg = "Ran out of input looking for replacement body for raw name " + name; errs.add(new ReplError(lno, pno, msg, null)); break; @@ -247,7 +187,6 @@ public class ReplPair implements Comparable<ReplPair> { lno += 1; } while (body.startsWith("#")); - rp.replace = body; resList.add(rp); |
