summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2021-07-12 15:58:34 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2021-07-12 15:58:34 -0300
commita732ae9404c0b7ba446d40bffb246ec43aad603c (patch)
tree931a49908e951471e751e352c8baa3142019bb6b /base/src/main/java/bjc
parenta24c1042499f76ff2d442ae133ef165011a7af4c (diff)
parentaba8e262d0e89ebef4229ad807b67660fc9bef35 (diff)
Merge & Update
Diffstat (limited to 'base/src/main/java/bjc')
-rw-r--r--base/src/main/java/bjc/utils/funcutils/LambdaLock.java13
-rw-r--r--base/src/main/java/bjc/utils/funcutils/ListUtils.java20
-rw-r--r--base/src/main/java/bjc/utils/funcutils/StringUtils.java175
-rw-r--r--base/src/main/java/bjc/utils/funcutils/TestUtils.java2
-rw-r--r--base/src/main/java/bjc/utils/ioutils/LevelSplitter.java49
-rw-r--r--base/src/main/java/bjc/utils/ioutils/LineReader.java18
-rw-r--r--base/src/main/java/bjc/utils/ioutils/SimpleProperties.java12
-rw-r--r--base/src/main/java/bjc/utils/ioutils/blocks/package-info.java22
-rw-r--r--base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java3
-rw-r--r--base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java1
10 files changed, 124 insertions, 191 deletions
diff --git a/base/src/main/java/bjc/utils/funcutils/LambdaLock.java b/base/src/main/java/bjc/utils/funcutils/LambdaLock.java
index 46de182..c974c8c 100644
--- a/base/src/main/java/bjc/utils/funcutils/LambdaLock.java
+++ b/base/src/main/java/bjc/utils/funcutils/LambdaLock.java
@@ -30,8 +30,8 @@ public class LambdaLock {
/** Execute an action with the read lock taken.
*
- * @param <T> The type of the result.
- *
+ * @param <T> The type returned by the action.
+ *
* @param supp The action to call.
*
* @return The result of the action. */
@@ -45,10 +45,11 @@ public class LambdaLock {
}
}
- /** Execute an action with the write lock taken.
- *
- * @param <T> The type of the result.
- *
+ /**
+ * Execute an action with the write lock taken.
+ *
+ * @param <T> The type returned by the action.
+ *
* @param supp The action to call.
*
* @return The result of the action. */
diff --git a/base/src/main/java/bjc/utils/funcutils/ListUtils.java b/base/src/main/java/bjc/utils/funcutils/ListUtils.java
index 8631102..47141c2 100644
--- a/base/src/main/java/bjc/utils/funcutils/ListUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/ListUtils.java
@@ -1,9 +1,6 @@
package bjc.utils.funcutils;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
import java.util.function.*;
import bjc.funcdata.FunctionalList;
@@ -291,19 +288,8 @@ public class ListUtils {
T elm1 = list.get(0);
T elm2 = list.get(1);
- List<T> currPerm = new ArrayList<>(2);
-
- currPerm.add(elm1);
- currPerm.add(elm2);
-
- permutes.add(currPerm);
-
- currPerm = new ArrayList<>(2);
-
- currPerm.add(elm2);
- currPerm.add(elm1);
-
- permutes.add(currPerm);
+ permutes.add(Arrays.asList(elm1, elm2));
+ permutes.add(Arrays.asList(elm2, elm1));
return permutes;
}
diff --git a/base/src/main/java/bjc/utils/funcutils/StringUtils.java b/base/src/main/java/bjc/utils/funcutils/StringUtils.java
index b029e1d..0b57e18 100644
--- a/base/src/main/java/bjc/utils/funcutils/StringUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/StringUtils.java
@@ -8,21 +8,15 @@ import com.ibm.icu.text.BreakIterator;
import bjc.utils.ioutils.LevelSplitter;
-/**
- * Utility methods for operations on strings.
+/** Utility methods for operations on strings.
*
- * @author ben
- */
+ * @author ben */
public class StringUtils {
- /**
- * Check if a string consists only of one or more matches of a regular
+ /**Check if a string consists only of one or more matches of a regular
* expression.
*
- * @param input
- * The string to check.
- *
- * @param rRegex
- * The regex to see if the string only contains matches of.
+ * @param input The string to check.
+ * @param rRegex The regex to see if the string only contains matches of.
*
* @return Whether or not the string consists only of multiple matches of the
* provided regex.
@@ -31,38 +25,29 @@ public class StringUtils {
if (input == null) throw new NullPointerException("Input must not be null");
else if (rRegex == null) throw new NullPointerException("Regex must not be null");
- /*
- * This regular expression is fairly simple.
+ /* This regular expression is fairly simple.
*
* First, we match the beginning of the string. Then, we start a non-capturing
* group whose contents are the passed in regex. That group is then matched one
- * or more times and the pattern matches to the end of the string.
- */
+ * or more times and the pattern matches to the end of the string. */
return input.matches("\\A(?:" + rRegex + ")+\\Z");
}
- /**
- * Indent the string being built in a StringBuilder n levels.
- *
- * @param builder
- * The builder to indent in.
+ /** Indent the string being built in a StringBuilder n levels.
*
- * @param levels
- * The number of levels to indent.
+ * @param builder The builder to indent in.
+ * @param levels The number of levels to indent.
*/
public static void indentNLevels(final StringBuilder builder, final int levels) {
for (int i = 0; i < levels; i++) builder.append("\t");
}
- /**
- * Print out a deque with a special case for easily showing a deque is empty.
- *
- * @param <ContainedType>
- * The type in the deque.
+ /** Print out a deque with a special case for easily showing a deque is empty.
*
- * @param queue
- * The deque to print.
+ * @param <ContainedType> The type in the deque.
*
+ * @param queue The deque to print.
+ *
* @return A string version of the deque, with allowance for an empty deque.
*/
public static <ContainedType> String printDeque(final Deque<ContainedType> queue) {
@@ -72,15 +57,10 @@ public class StringUtils {
/**
* Converts a sequence to an English list.
*
- * @param objects
- * The sequence to convert to an English list.
- *
+ * @param objects The sequence to convert to an English list.
* @param join
- * The string to use for separating the last element from the
- * rest.
- *
- * @param comma
- * The string to use as a comma
+ * The string to use for separating the last element from the rest.
+ * @param comma The string to use as a comma
*
* @return The sequence as an English list.
*/
@@ -129,15 +109,11 @@ public class StringUtils {
return sb.toString();
}
- /**
- * Converts a sequence to an English list.
- *
- * @param objects
- * The sequence to convert to an English list.
+ /** Converts a sequence to an English list.
*
+ * @param objects The sequence to convert to an English list.
* @param join
- * The string to use for separating the last element from the
- * rest.
+ * The string to use for separating the last element from the rest.
*
* @return The sequence as an English list.
*/
@@ -145,14 +121,10 @@ public class StringUtils {
return toEnglishList(objects, join, ",");
}
- /**
- * Converts a sequence to an English list.
- *
- * @param objects
- * The sequence to convert to an English list.
+ /** Converts a sequence to an English list.
*
- * @param and
- * Whether to use 'and' or 'or'.
+ * @param objects The sequence to convert to an English list.
+ * @param and Whether to use 'and' or 'or'.
*
* @return The sequence as an English list.
*/
@@ -161,11 +133,9 @@ public class StringUtils {
else return toEnglishList(objects, "or");
}
- /**
- * Count the number of graphemes in a string.
+ /** Count the number of graphemes in a string.
*
- * @param value
- * The string to check.
+ * @param value The string to check.
*
* @return The number of graphemes in the string.
*/
@@ -179,14 +149,11 @@ public class StringUtils {
return count;
}
- /**
- * Count the number of times a pattern matches in a given string.
+ /** Count the number of times a pattern matches in a given string.
*
- * @param value
- * The string to count occurances in.
- *
- * @param pattern
- * The pattern to count occurances of.
+ * @param value The string to count occurrences in.
+ * @param pattern The pattern to count occurrences of.
+ *
* @return The number of times the pattern matches.
*/
public static int countMatches(final String value, final String pattern) {
@@ -198,42 +165,36 @@ public class StringUtils {
return num;
}
- /**
- * Get a substring until a specified string.
+ /** Get a substring until a specified string.
*
- * @param strang
- * The string to substring.
- * @param vx
- * The place to substring until.
+ * @param strang The string to substring.
+ * @param until The place to substring until.
*
* @return The specified substring.
*/
- public static String substringTo(String strang, String vx) {
- return substringTo(strang, vx, true);
+ public static String substringTo(String strang, String until) {
+ return substringTo(strang, until, true);
}
/**
* Get a substring until a specified string.
*
- * @param strang
- * The string to substring.
- * @param vx
- * The place to substring until.
- * @param allowFail
- * Whether or not to allow failure.
+ * @param strang The string to substring.
+ * @param until The place to substring until.
+ * @param allowFail Whether or not to allow failure.
*
* @return The specified substring, or null if the specified place to substring
* to was not found, and we were not allowed to fail.
*/
- public static String substringTo(String strang, String vx, boolean allowFail) {
- int idx = strang.indexOf(vx);
+ public static String substringTo(String strang, String until, boolean allowFail) {
+ int idx = strang.indexOf(until);
if (idx == -1) {
if (allowFail) return strang;
else return null;
}
- return strang.substring(0, strang.indexOf(vx));
+ return strang.substring(0, strang.indexOf(until));
}
private static class LineIterator implements Iterator<String> {
@@ -282,11 +243,9 @@ public class StringUtils {
}
}
- /**
- * Read a series of lines from an input source.
+ /** Read a series of lines from an input source.
*
- * @param scn
- * The source to read the lines from.
+ * @param scn The source to read the lines from.
*
* @return An iterator over the lines from the input source.
*/
@@ -297,17 +256,10 @@ public class StringUtils {
/**
* Read a series of lines from an input source.
*
- * @param scn
- * The source to read the lines from.
- *
- * @param processComments
- * Whether or not to skip comment lines.
- *
- * @param commentInd
- * Indicator for starting comment lines.
- *
- * @param skipBlanks
- * Whether or not to skip blank lines.
+ * @param scn The source to read the lines from.
+ * @param processComments Whether or not to skip comment lines.
+ * @param commentInd Indicator for starting comment lines.
+ * @param skipBlanks Whether or not to skip blank lines.
*
* @return An iterator over the lines from the input source.
*/
@@ -323,27 +275,23 @@ public class StringUtils {
return itr;
}
- /**
- * Check if a string contains any one of a specified number of things,
+ /** Check if a string contains any one of a specified number of things,
* respecting groups.
*
- * @param haystack
- * The string to look in.
- * @param needles
- * The strings to look for.
+ * @param haystack The string to look in.
+ * @param needles The strings to look for.
+ *
* @return Whether or not any of the strings were contained outside of groups.
*/
public static boolean levelContains(String haystack, String... needles) {
return LevelSplitter.def.levelContains(haystack, needles);
}
- /**
- * Split a string, respecting groups.
+ /** Split a string, respecting groups.
*
- * @param phrase
- * The string to split.
- * @param splits
- * The strings to split on.
+ * @param phrase The string to split.
+ * @param splits The strings to split on.
+ *
* @return A list of split strings. If keepDelims is true, it also includes the
* delimiters in between the split strings.
*/
@@ -351,15 +299,12 @@ public class StringUtils {
return LevelSplitter.def.levelSplit(phrase, false, splits);
}
- /**
- * Split a string, respecting groups.
+ /** Split a string, respecting groups.
*
- * @param phrase
- * The string to split.
- * @param keepDelims
- * Whether or not to include the delimiters in the results.
- * @param splits
- * The strings to split on.
+ * @param phrase The string to split.
+ * @param keepDelims Whether or not to include the delimiters in the results.
+ * @param splits The strings to split on.
+ *
* @return A list of split strings. If keepDelims is true, it also includes the
* delimiters in between the split strings.
*/
@@ -367,4 +312,4 @@ public class StringUtils {
String... splits) {
return LevelSplitter.def.levelSplit(phrase, keepDelims, splits);
}
-}
+} \ No newline at end of file
diff --git a/base/src/main/java/bjc/utils/funcutils/TestUtils.java b/base/src/main/java/bjc/utils/funcutils/TestUtils.java
index 681a8e6..860a565 100644
--- a/base/src/main/java/bjc/utils/funcutils/TestUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/TestUtils.java
@@ -36,6 +36,8 @@ public class TestUtils {
* Even though it's awkward, the boolean has to come first. Otherwise, there are
* cases where the compiler will get confused as to what the right value for T
* is, and be unable to pick an overload.
+ *
+ * This is a case where named parameter would be rather useful.
*/
assertIteratorEquals(src, vals);
diff --git a/base/src/main/java/bjc/utils/ioutils/LevelSplitter.java b/base/src/main/java/bjc/utils/ioutils/LevelSplitter.java
index 22cf2c5..e808bec 100644
--- a/base/src/main/java/bjc/utils/ioutils/LevelSplitter.java
+++ b/base/src/main/java/bjc/utils/ioutils/LevelSplitter.java
@@ -5,29 +5,24 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-/**
- * Splits a string on a delimiter, respecting grouping delimiters.
+/** Splits a string on a delimiter, respecting grouping delimiters.
*
* By default, grouping delimiters are (), [], {}, and &lt;&gt;, as well as single and
* double quoted strings.
*
- * @author bjculkin
- *
- */
+ * @author bjculkin */
public class LevelSplitter {
- /**
- * Defaultly configured level splitter.
- */
+ /** Default configured level splitter. */
public final static LevelSplitter def = new LevelSplitter();
- /**
- * Check if a string contains any one of a specified number of things,
+ /** Should empty strings be ignored? */
+ public boolean ignoreEmpty = false;
+
+ /** Check if a string contains any one of a specified number of things,
* respecting groups.
*
- * @param haystack
- * The string to look in.
- * @param needles
- * The strings to look for.
+ * @param haystack The string to look in.
+ * @param needles The strings to look for.
* @return Whether or not any of the strings were contained outside of groups.
*/
public boolean levelContains(String haystack, String... needles) {
@@ -88,13 +83,11 @@ public class LevelSplitter {
return false;
}
- /**
- * Split a string, respecting groups.
+ /** Split a string, respecting groups.
*
- * @param phrase
- * The string to split.
- * @param splits
- * The strings to split on.
+ * @param phrase The string to split.
+ * @param splits The strings to split on.
+ *
* @return A list of split strings. If keepDelims is true, it also includes the
* delimiters in between the split strings.
*/
@@ -102,15 +95,12 @@ public class LevelSplitter {
return levelSplit(phrase, false, splits);
}
- /**
- * Split a string, respecting groups.
+ /** Split a string, respecting groups.
*
- * @param phrase
- * The string to split.
- * @param keepDelims
- * Whether or not to include the delimiters in the results.
- * @param splits
- * The strings to split on.
+ * @param phrase The string to split.
+ * @param keepDelims Whether or not to include the delimiters in the results.
+ * @param splits The strings to split on.
+ *
* @return A list of split strings. If keepDelims is true, it also includes the
* delimiters in between the split strings.
*/
@@ -140,8 +130,7 @@ public class LevelSplitter {
if (work.regionMatches(i, split, 0, split.length())) {
strangs.add(work.substring(0, i));
- if (keepDelims)
- strangs.add(split);
+ if (keepDelims) strangs.add(split);
work = work.substring(i + split.length());
i = 0;
diff --git a/base/src/main/java/bjc/utils/ioutils/LineReader.java b/base/src/main/java/bjc/utils/ioutils/LineReader.java
deleted file mode 100644
index 2ac2797..0000000
--- a/base/src/main/java/bjc/utils/ioutils/LineReader.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package bjc.utils.ioutils;
-
-/**
- * A line reader
- *
- * @author bjculkin
- *
- */
-public class LineReader implements AutoCloseable {
- //private Scanner scn;
-
- @Override
- public void close() {
- //scn.close();
- }
-
- // @TODO Implement me - ben, 1/6/20
-}
diff --git a/base/src/main/java/bjc/utils/ioutils/SimpleProperties.java b/base/src/main/java/bjc/utils/ioutils/SimpleProperties.java
index 754ed45..d380866 100644
--- a/base/src/main/java/bjc/utils/ioutils/SimpleProperties.java
+++ b/base/src/main/java/bjc/utils/ioutils/SimpleProperties.java
@@ -170,17 +170,20 @@ public class SimpleProperties implements Map<String, String> {
return props.isEmpty();
}
- @Override
+ @SuppressWarnings("unlikely-arg-type")
+ @Override
public boolean containsKey(final Object key) {
return props.containsKey(key);
}
- @Override
+ @SuppressWarnings("unlikely-arg-type")
+ @Override
public boolean containsValue(final Object value) {
return props.containsValue(value);
}
- @Override
+ @SuppressWarnings("unlikely-arg-type")
+ @Override
public String get(final Object key) {
return props.get(key);
}
@@ -190,7 +193,8 @@ public class SimpleProperties implements Map<String, String> {
return props.put(key, value);
}
- @Override
+ @SuppressWarnings("unlikely-arg-type")
+ @Override
public String remove(final Object key) {
return props.remove(key);
}
diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/package-info.java b/base/src/main/java/bjc/utils/ioutils/blocks/package-info.java
new file mode 100644
index 0000000..3d05ed4
--- /dev/null
+++ b/base/src/main/java/bjc/utils/ioutils/blocks/package-info.java
@@ -0,0 +1,22 @@
+/** This package contains a number of classes useful for processing input that
+ * is structured as a series of 'blocks' or records.
+ * <p>
+ *
+ * The most fundamental unit here is that of {@link Block}. Each {@link
+ * BlockReader} will yield a sequence of these, which contain a piece of text
+ * as its contents, as well as the beginning/ending line for that block.
+ *
+ * There are a number of different types of {@link BlockReader}, which are
+ * summarized here.
+ * </p>
+ *
+ * <dl>
+ * <dt>{@link SimpleBlockReader}</dt>
+ * <dd>
+ * The most basic form of BlockReader. This uses a regular expression to
+ * delimit input reader from a {@link Reader} into a series of blocks.
+ * Listed first, because this is
+ * </dd>
+ * </dl>
+ * @author Ben Culkin */
+package bjc.utils.ioutils.blocks;
diff --git a/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java b/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java
index 28e9cd7..176f588 100644
--- a/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java
+++ b/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java
@@ -79,7 +79,8 @@ public class MutablePatternMatcher<ReturnType, InputType>
*
* @return Whether or not the pattern was removed.
*/
- public boolean removePattern(ComplexPattern<ReturnType, ?, InputType> pattern) {
+ @SuppressWarnings("unlikely-arg-type")
+ public boolean removePattern(ComplexPattern<ReturnType, ?, InputType> pattern) {
return patterns.remove(pattern);
}
}
diff --git a/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java b/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java
index fea947a..9fae976 100644
--- a/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java
+++ b/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java
@@ -7,6 +7,7 @@ import bjc.data.*;
*
* @author Ben Culkin
*
+ * @param <InputType> The type input to the pattern matcher.
* @param <ReturnType> The type returned by the pattern.
*/
public class SimplePatternMatcher<ReturnType, InputType>