From 5f7597c878c90bf13dea73d8dd8aed6f0f693702 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Fri, 1 Sep 2017 11:48:01 -0300 Subject: Commenting --- .../java/bjc/utils/ioutils/RegexStringEditor.java | 48 ++++++++++++++++++---- .../java/bjc/utils/ioutils/SimpleProperties.java | 8 +++- .../java/bjc/utils/parserutils/TokenUtils.java | 4 +- 3 files changed, 49 insertions(+), 11 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc') diff --git a/BJC-Utils2/src/main/java/bjc/utils/ioutils/RegexStringEditor.java b/BJC-Utils2/src/main/java/bjc/utils/ioutils/RegexStringEditor.java index ee1e2ea..71f6782 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/ioutils/RegexStringEditor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/ioutils/RegexStringEditor.java @@ -79,13 +79,22 @@ public class RegexStringEditor { */ public static String reduceOccurances(final String input, final Pattern rPatt, final UnaryOperator betweenAction, final UnaryOperator onAction) { + /* + * Get all of the occurances. + */ final IList occurances = listOccurances(input, rPatt); + /* + * Execute the correct action on every occurance. + */ final Toggle> actions = new ValueToggle<>(onAction, betweenAction); final BiFunction reducer = (strang, state) -> { return state.append(actions.get().apply(strang)); }; + /* + * Convert the list back to a string. + */ return occurances.reduceAux(new StringBuilder(), reducer, StringBuilder::toString); } @@ -108,9 +117,15 @@ public class RegexStringEditor { */ public static IList mapOccurances(final String input, final Pattern rPatt, final UnaryOperator betweenAction, final UnaryOperator onAction) { + /* + * Get all of the occurances. + */ final IList occurances = listOccurances(input, rPatt); - final Toggle> actions = new ValueToggle<>(onAction, betweenAction); + /* + * Execute the correct action on every occurance. + */ + final Toggle> actions = new ValueToggle<>(onAction, betweenAction); return occurances.map(strang -> actions.get().apply(strang)); } @@ -129,23 +144,36 @@ public class RegexStringEditor { public static IList listOccurances(final String input, final Pattern rPatt) { final IList res = new FunctionalList<>(); + /* + * Create the matcher and work buffer. + */ final Matcher matcher = rPatt.matcher(input); - StringBuffer work = new StringBuffer(); + /* + * For every match. + */ while (matcher.find()) { final String match = matcher.group(); + /* + * Append the text until the match to the buffer. + */ matcher.appendReplacement(work, ""); res.add(work.toString()); res.add(match); + /* + * Clear the buffer. + */ work = new StringBuffer(); } + /* + * Add the text after the last match to the buffer. + */ matcher.appendTail(work); - res.add(work.toString()); return res; @@ -168,9 +196,11 @@ public class RegexStringEditor { public static String ifMatches(final String input, final Pattern patt, final UnaryOperator action) { final Matcher matcher = patt.matcher(input); - if (matcher.matches()) + if (matcher.matches()) { return action.apply(input); - else return input; + } else { + return input; + } } /** @@ -191,8 +221,10 @@ public class RegexStringEditor { public static String ifNotMatches(final String input, final Pattern patt, final UnaryOperator action) { final Matcher matcher = patt.matcher(input); - if (matcher.matches()) + if (matcher.matches()) { return input; - else return action.apply(input); + } else { + return action.apply(input); + } } -} \ No newline at end of file +} diff --git a/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java b/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java index e142ea3..e6279c4 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java +++ b/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java @@ -54,6 +54,9 @@ public class SimpleProperties implements Map { final int sepIdx = ln.indexOf(' '); + /* + * Complain about improperly formatted lines. + */ if (sepIdx == -1) { final String fmt = "Properties must be a name, a space, then the body.\n\tOffending line is '%s'"; final String msg = String.format(fmt, ln); @@ -64,6 +67,9 @@ public class SimpleProperties implements Map { final String name = ln.substring(0, sepIdx).trim(); final String body = ln.substring(sepIdx).trim(); + /* + * Complain about duplicates, if that is wanted. + */ if (!allowDuplicates && containsKey(name)) { final String msg = String.format("Duplicate key '%s'", name); @@ -161,4 +167,4 @@ public class SimpleProperties implements Map { public int hashCode() { return props.hashCode(); } -} \ No newline at end of file +} diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java index f825488..a8f3db2 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenUtils.java @@ -276,9 +276,9 @@ public class TokenUtils { * * @param inp * The input to check. - * @return Whether the string is a valid double or not. + * @return Whether the string is a valid integer or not. */ public static boolean isInt(final String inp) { return intLitPattern.matcher(inp).matches(); } -} \ No newline at end of file +} -- cgit v1.2.3