summaryrefslogtreecommitdiff
path: root/BJC-Utils2
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2')
-rw-r--r--BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/ShuntTester.java4
-rw-r--r--BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java14
-rw-r--r--BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java4
-rw-r--r--BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java46
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java15
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java15
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java81
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java13
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/ICommand.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java5
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java13
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java60
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java127
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java19
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java69
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Pair.java26
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java18
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java42
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java (renamed from BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java)22
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java (renamed from BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java)10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/PushdownMap.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java48
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java52
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java81
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java6
50 files changed, 616 insertions, 404 deletions
diff --git a/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/ShuntTester.java b/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/ShuntTester.java
index 9744653..5148be4 100644
--- a/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/ShuntTester.java
+++ b/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/ShuntTester.java
@@ -3,7 +3,7 @@ package bjc.utils.examples.parsing;
import java.util.Scanner;
import bjc.utils.funcdata.FunctionalStringTokenizer;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
import bjc.utils.parserutils.ShuntingYard;
/**
@@ -27,7 +27,7 @@ public class ShuntTester {
ShuntingYard<String> yard = new ShuntingYard<>(true);
- IFunctionalList<String> shuntedTokens = yard
+ IList<String> shuntedTokens = yard
.postfix(new FunctionalStringTokenizer(line)
.toList((strang) -> strang), (strang) -> strang);
diff --git a/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java b/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java
index faeb3a6..e737b4d 100644
--- a/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java
+++ b/BJC-Utils2/src/examples/java/bjc/utils/examples/parsing/TreeConstructTest.java
@@ -10,8 +10,8 @@ import bjc.utils.data.IPair;
import bjc.utils.data.Pair;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.FunctionalStringTokenizer;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
import bjc.utils.funcdata.ITree;
import bjc.utils.funcdata.Tree;
import bjc.utils.funcutils.ListUtils;
@@ -61,7 +61,7 @@ public class TreeConstructTest {
System.out.print("Enter a expression to parse: ");
String line = inputSource.nextLine();
- IFunctionalList<String> tokens = new FunctionalStringTokenizer(
+ IList<String> tokens = new FunctionalStringTokenizer(
line).toList();
ShuntingYard<String> yard = new ShuntingYard<>(true);
@@ -75,7 +75,7 @@ public class TreeConstructTest {
ops.add(new Pair<>(":=", ":="));
ops.add(new Pair<>("=>", "=>"));
- IFunctionalList<String> semiExpandedTokens = ListUtils
+ IList<String> semiExpandedTokens = ListUtils
.splitTokens(tokens, ops);
ops = new LinkedList<>();
@@ -85,12 +85,12 @@ public class TreeConstructTest {
ops.add(new Pair<>("[", "\\["));
ops.add(new Pair<>("]", "\\]"));
- IFunctionalList<String> fullyExpandedTokens = ListUtils
+ IList<String> fullyExpandedTokens = ListUtils
.deAffixTokens(semiExpandedTokens, ops);
fullyExpandedTokens.removeIf((strang) -> strang.equals(""));
- IFunctionalList<String> shuntedTokens = yard
+ IList<String> shuntedTokens = yard
.postfix(fullyExpandedTokens, (token) -> token);
System.out.println("Shunted: " + shuntedTokens.toString());
@@ -105,7 +105,7 @@ public class TreeConstructTest {
return false;
};
- IFunctionalMap<String, Function<Deque<ITree<String>>, ITree<String>>> operators = new FunctionalMap<>();
+ IMap<String, Function<Deque<ITree<String>>, ITree<String>>> operators = new FunctionalMap<>();
operators.put("[", (queuedTrees) -> {
return null;
diff --git a/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java b/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java
index 09530ba..4686643 100644
--- a/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java
+++ b/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java
@@ -1,7 +1,7 @@
package bjc.utils.examples.rangen;
import bjc.utils.funcdata.FunctionalStringTokenizer;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
import bjc.utils.gen.WeightedGrammar;
/**
@@ -83,7 +83,7 @@ public class DiabloItemGen {
addInfixRules();
for (int i = 0; i < 100; i++) {
- IFunctionalList<String> ls = rules.generateListValues("<item>",
+ IList<String> ls = rules.generateListValues("<item>",
" ");
StringBuilder sb = new StringBuilder();
diff --git a/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java b/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java
index 4eaeadb..fc1724e 100644
--- a/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java
+++ b/BJC-Utils2/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java
@@ -2,7 +2,7 @@ package bjc.utils.examples.rangen;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalStringTokenizer;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
import bjc.utils.gen.RandomGrammar;
/**
@@ -15,7 +15,7 @@ public class RandomStringExamples {
private static RandomGrammar<String> rg;
private static void addRule(String rule, String... cases) {
- IFunctionalList<IFunctionalList<String>> cses = new FunctionalList<>();
+ IList<IList<String>> cses = new FunctionalList<>();
for (String strang : cases) {
cses.add(FunctionalStringTokenizer.fromString(strang)
@@ -56,7 +56,7 @@ public class RandomStringExamples {
"<object>");
for (int i = 0; i < 10; i++) {
- IFunctionalList<String> ls = rg
+ IList<String> ls = rg
.generateListValues("<sentance>", " ");
StringBuilder sb = new StringBuilder();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java b/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java
index e1a57c2..5a7f95b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java
@@ -7,27 +7,33 @@ import java.util.Arrays;
import java.util.Scanner;
/**
- * Runs a CLI interface from the provided set of streams
+ * Runs a CLI interface from the provided set of streams.
*
* @author ben
*
*/
public class CLICommander {
+ /*
+ * The streams used for input and normal/error output
+ */
private InputStream input;
private OutputStream output;
private OutputStream error;
+ /*
+ * The command mode to start execution in
+ */
private ICommandMode initialMode;
/**
- * Create a new CLI interface powered by streams
+ * Create a new CLI interface powered by streams.
*
* @param input
- * The stream to get user input from
+ * The stream to get user input from.
* @param output
- * The stream to send user output to
+ * The stream to send normal output to.
* @param error
- * The stream to send error messages to
+ * The stream to send error output to.
*/
public CLICommander(InputStream input, OutputStream output,
OutputStream error) {
@@ -48,32 +54,51 @@ public class CLICommander {
}
/**
- * Run a set of commands through this commander
+ * Start handling commands from the given input stream.
*/
public void runCommands() {
+ // Setup output streams
PrintStream normalOutput = new PrintStream(output);
PrintStream errorOutput = new PrintStream(error);
+ /*
+ * Set up input streams.
+ *
+ * We're suppressing the warning because we might use the input
+ * stream multiple times
+ */
@SuppressWarnings("resource")
- // We might use this stream multiple times. Don't close it
Scanner inputSource = new Scanner(input);
+ /*
+ * The mode currently being used to handle commands.
+ *
+ * Used to preserve the initial mode
+ */
ICommandMode currentMode = initialMode;
+ // Process commands until we're told to stop
while (currentMode != null) {
- if (currentMode.useCustomPrompt()) {
+ /*
+ * Print out the command prompt, using a custom prompt if one
+ * is specified
+ */
+ if (currentMode.isCustomPromptEnabled()) {
normalOutput.print(currentMode.getCustomPrompt());
} else {
normalOutput.print(currentMode.getName() + ">> ");
}
+ // Read in a command
String currentLine = inputSource.nextLine();
- if (currentMode.canHandleCommand(currentLine)) {
+ // Handle handleable commands
+ if (currentMode.canHandle(currentLine)) {
String[] commandTokens = currentLine.split(" ");
String[] commandArgs;
+ // Parse args if they are present
if (commandTokens.length > 1) {
commandArgs = Arrays.copyOfRange(commandTokens, 1,
commandTokens.length);
@@ -81,7 +106,8 @@ public class CLICommander {
commandArgs = null;
}
- currentMode = currentMode.processCommand(commandTokens[0],
+ // Process command
+ currentMode = currentMode.process(commandTokens[0],
commandArgs);
} else {
errorOutput.print(
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java b/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java
index 28e0347..ad115d7 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java
@@ -1,14 +1,27 @@
package bjc.utils.cli;
+/**
+ * A class for a command that delegates to another command
+ *
+ * @author ben
+ *
+ */
class DelegatingCommand implements ICommand {
+ // The command to delegate to
private ICommand delegate;
+ /**
+ * Create a new command that delegates to another command
+ *
+ * @param delegate
+ * The command to delegate to
+ */
public DelegatingCommand(ICommand delegate) {
this.delegate = delegate;
}
@Override
- public ICommand createAlias() {
+ public ICommand aliased() {
return new DelegatingCommand(delegate);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
index 529635d..1a95018 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
@@ -7,7 +7,9 @@ package bjc.utils.cli;
*
*/
public class GenericCommand implements ICommand {
+ // The behavior for invoking the command
private ICommandHandler handler;
+ // The help for the command
private ICommandHelp help;
/**
@@ -22,17 +24,16 @@ public class GenericCommand implements ICommand {
*/
public GenericCommand(ICommandHandler handler, String description,
String help) {
+ if(handler == null) {
+ throw new NullPointerException("Command handler must not be null");
+ }
+
this.handler = handler;
this.help = new GenericHelp(description, help);
}
-
- /**
- * Create a command that is an alias to this one
- *
- * @return A command that is an alias to this one
- */
+
@Override
- public ICommand createAlias() {
+ public ICommand aliased() {
return new DelegatingCommand(this);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
index 0007616..59d3dc3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
@@ -5,7 +5,7 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IMap;
/**
* A general command mode, with a customizable set of commands
@@ -18,18 +18,26 @@ import bjc.utils.funcdata.IFunctionalMap;
*
*/
public class GenericCommandMode implements ICommandMode {
- private IFunctionalMap<String, ICommand> commandHandlers;
- private IFunctionalMap<String, ICommand> defaultHandlers;
+ /*
+ * Contains the commands this mode handles
+ */
+ private IMap<String, ICommand> commandHandlers;
+ private IMap<String, ICommand> defaultHandlers;
- private IFunctionalMap<String, ICommandHelp> helpTopics;
+ // Contains help topics without an associated command
+ private IMap<String, ICommandHelp> helpTopics;
+ // The action to execute upon encountering an unknown command
private BiConsumer<String, String[]> unknownCommandHandler;
+ // The functions to use for input/output
private Consumer<String> errorOutput;
private Consumer<String> normalOutput;
+ // The name of this command mode, or null if it is unnamed
private String modeName;
+ // The custom prompt to use, or null if none is specified
private String customPrompt;
/**
@@ -45,6 +53,7 @@ public class GenericCommandMode implements ICommandMode {
this.normalOutput = normalOutput;
this.errorOutput = errorOutput;
+ // Initialize handler maps so that they sort in alphabetical order
commandHandlers = new FunctionalMap<>(new TreeMap<>());
defaultHandlers = new FunctionalMap<>(new TreeMap<>());
helpTopics = new FunctionalMap<>(new TreeMap<>());
@@ -81,12 +90,13 @@ public class GenericCommandMode implements ICommandMode {
+ aliasName + "' to a command with a bound handler");
} else {
ICommand aliasedCommand;
+
if (defaultHandlers.containsKey(commandName)) {
aliasedCommand = defaultHandlers.get(commandName)
- .createAlias();
+ .aliased();
} else {
aliasedCommand = commandHandlers.get(commandName)
- .createAlias();
+ .aliased();
}
commandHandlers.put(aliasName, aliasedCommand);
@@ -97,7 +107,7 @@ public class GenericCommandMode implements ICommandMode {
* Add a command to this command mode
*
* @param command
- * The command to add
+ * The name of the command to add
* @param handler
* The handler to use for the specified command
*
@@ -110,7 +120,7 @@ public class GenericCommandMode implements ICommandMode {
throw new NullPointerException("Command must not be null");
} else if (handler == null) {
throw new NullPointerException("Handler must not be null");
- } else if (canHandleCommand(command)) {
+ } else if (canHandle(command)) {
throw new IllegalArgumentException("Command " + command
+ " already has a handler registered");
} else {
@@ -123,22 +133,28 @@ public class GenericCommandMode implements ICommandMode {
*
* @param topicName
* The name of the topic
- * @param help
+ * @param topic
* The contents of the topic
*/
- public void addHelpTopic(String topicName, ICommandHelp help) {
- helpTopics.put(topicName, help);
+ public void addHelpTopic(String topicName, ICommandHelp topic) {
+ helpTopics.put(topicName, topic);
}
+ // -------------------------------------------------------------------------
+ /*
+ * Default command builders
+ */
+ // -------------------------------------------------------------------------
+
private GenericCommand buildAliasCommand() {
return new GenericCommand((args) -> {
doAliasCommands(args);
return this;
}, "alias\tAlias one command to another",
- "alias gives a command another name it can be invoked by. It is invoked"
- + " with two arguments, the name of the command to alias"
- + ", and the alias to give that command.");
+ "Gives a command another name it can be invoked by. Invoke"
+ + " with two arguments: the name of the command to alias"
+ + "followed by the name of the alias to give that command.");
}
private GenericCommand buildClearCommands() {
@@ -148,8 +164,8 @@ public class GenericCommandMode implements ICommandMode {
return this;
}, "clear\tClear the screen",
- "clear clears the screen of all the text on it,"
- + " and prepares a fresh prompt.");
+ "Clears the screen of all the text on it,"
+ + " and prints a new prompt.");
}
private GenericCommand buildExitCommand() {
@@ -158,9 +174,9 @@ public class GenericCommandMode implements ICommandMode {
"ERROR: This console doesn't support auto-exiting");
return this;
- }, "exit\tExit the game",
- "exit first prompts the user to make sure they want to exit,"
- + " and if they affirm it, it quits");
+ }, "exit\tExit the console",
+ "First prompts the user to make sure they want to exit,"
+ + " and if they affirm it, it immediately exits");
}
private GenericCommand buildHelpCommand() {
@@ -175,10 +191,10 @@ public class GenericCommandMode implements ICommandMode {
return this;
}, "help\tConsult the help system",
- "help consults the internal help system."
- + " It can be invoked in two ways. Invoking it with no arguments"
- + " causes it to print out all the topics you can ask for details on,"
- + " while invoking it with the name of a topic will print the entry"
+ "Consults the internal help system."
+ + " Invoked in two different ways. Invoking with no arguments"
+ + " causes all the topics you can ask for details on to be list,"
+ + " while invoking with the name of a topic will print the entry"
+ " for that topic");
}
@@ -193,11 +209,17 @@ public class GenericCommandMode implements ICommandMode {
}
@Override
- public boolean canHandleCommand(String command) {
+ public boolean canHandle(String command) {
return commandHandlers.containsKey(command)
|| defaultHandlers.containsKey(command);
}
+ // -------------------------------------------------------------------------
+ /*
+ * Implement default commands
+ */
+ // -------------------------------------------------------------------------
+
private void doAliasCommands(String[] args) {
if (args.length != 2) {
errorOutput.accept("ERROR: Alias requires two arguments. "
@@ -206,10 +228,10 @@ public class GenericCommandMode implements ICommandMode {
String commandName = args[0];
String aliasName = args[1];
- if (!canHandleCommand(commandName)) {
+ if (!canHandle(commandName)) {
errorOutput.accept("ERROR: '" + commandName
+ "' is not a valid command.");
- } else if (canHandleCommand(aliasName)) {
+ } else if (canHandle(aliasName)) {
errorOutput.accept("ERROR: Cannot overwrite command '"
+ aliasName + "'");
} else {
@@ -310,7 +332,7 @@ public class GenericCommandMode implements ICommandMode {
}
@Override
- public ICommandMode processCommand(String command, String[] args) {
+ public ICommandMode process(String command, String[] args) {
normalOutput.accept("\n");
if (defaultHandlers.containsKey(command)) {
@@ -363,7 +385,8 @@ public class GenericCommandMode implements ICommandMode {
* Set the handler to use for unknown commands
*
* @param handler
- * The handler to use for unknown commands
+ * The handler to use for unknown commands, or null to throw
+ * on unknown commands
*/
public void setUnknownCommandHandler(
BiConsumer<String, String[]> handler) {
@@ -393,7 +416,7 @@ public class GenericCommandMode implements ICommandMode {
}
@Override
- public boolean useCustomPrompt() {
+ public boolean isCustomPromptEnabled() {
return customPrompt != null;
}
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
index f2fb146..8742b5d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
@@ -7,6 +7,7 @@ package bjc.utils.cli;
*
*/
public class GenericHelp implements ICommandHelp {
+ // The strings for this help topic
private String summary;
private String description;
@@ -16,15 +17,25 @@ public class GenericHelp implements ICommandHelp {
* @param summary
* The summary of this help topic
* @param description
- * The description of this help topic
+ * The description of this help topic, or null if this help
+ * topic doesn't have a more detailed description
*/
public GenericHelp(String summary, String description) {
+ if (summary == null) {
+ throw new NullPointerException(
+ "Help summary must be non-null");
+ }
+
this.summary = summary;
this.description = description;
}
@Override
public String getDescription() {
+ if (description == null) {
+ return summary;
+ }
+
return description;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommand.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommand.java
index ff15a37..a72ecdf 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommand.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommand.java
@@ -12,7 +12,7 @@ public interface ICommand {
*
* @return A command that serves as an alias to this one
*/
- public ICommand createAlias();
+ public ICommand aliased();
/**
* Get the handler that executes this command
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java
index f806676..3d451a7 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java
@@ -10,11 +10,12 @@ import java.util.function.Function;
*/
public interface ICommandHandler extends Function<String[], ICommandMode> {
/**
- * Handle the command this handler handles
+ * Execute this command
*
* @param args
* The arguments for this command
- * @return The command mode to go to after this command
+ * @return The command mode to switch to after this command, or null to
+ * stop executing commands
*/
public default ICommandMode handle(String[] args) {
return this.apply(args);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java
index d475335..bd81537 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHelp.java
@@ -8,18 +8,18 @@ package bjc.utils.cli;
*/
public interface ICommandHelp {
/**
- * Get the description of a command
+ * Get the description of a command.
*
* @return The description of a command
*/
public String getDescription();
/**
- * Get the summary line for a command
- *
- * Used for 'help commands' which gives the user a brief idea what all
- * the commands do
+ * Get the summary line for a command.
*
+ * A summary line should consist of a string of the following format
+ * "<command-name>\t<command-summary>"
+ * where anything in angle brackets should be filled in.
* @return The summary line line for a command
*/
public String getSummary();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java
index 48a741c..f60e571 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandMode.java
@@ -16,7 +16,7 @@ public interface ICommandMode {
* @return Whether or not this mode can handle the command. It is
* assumed not by default
*/
- public default boolean canHandleCommand(String command) {
+ public default boolean canHandle(String command) {
return false;
};
@@ -53,7 +53,7 @@ public interface ICommandMode {
* @return The command mode to use for the next command. Defaults to
* returning this, and doing nothing else
*/
- public default ICommandMode processCommand(String command,
+ public default ICommandMode process(String command,
String[] args) {
return this;
}
@@ -63,7 +63,7 @@ public interface ICommandMode {
*
* @return Whether or not this mode uses a custom prompt
*/
- public default boolean useCustomPrompt() {
+ public default boolean isCustomPromptEnabled() {
return false;
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java
index 9429dde..ab48c9b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java
@@ -10,19 +10,19 @@ public class ComponentDescription implements IDescribedComponent {
private static void sanityCheckArgs(String name, String author,
String description, int version) {
if (name == null) {
- throw new IllegalArgumentException(
- "Component name can't be null");
+ throw new NullPointerException("Component name can't be null");
} else if (author == null) {
- throw new IllegalArgumentException(
+ throw new NullPointerException(
"Component author can't be null");
} else if (description == null) {
- throw new IllegalArgumentException(
+ throw new NullPointerException(
"Component description can't be null");
- } else if (version < 0) {
+ } else if (version <= 0) {
throw new IllegalArgumentException(
"Component version must be greater than 0");
}
}
+
/**
* The author of the component
*/
@@ -53,8 +53,7 @@ public class ComponentDescription implements IDescribedComponent {
* @param version
* The version of the component
* @throws IllegalArgumentException
- * thrown if name, author or description is null, or if
- * version is less than 1
+ * thrown if version is less than 1
*/
public ComponentDescription(String name, String author,
String description, int version) {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
index be0a65b..b35c77b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
@@ -1,13 +1,11 @@
package bjc.utils.components;
import java.io.InputStream;
-import java.util.function.BiConsumer;
-import bjc.utils.exceptions.PragmaFormatException;
-import bjc.utils.funcdata.FunctionalStringTokenizer;
-import bjc.utils.funcutils.ListUtils;
import bjc.utils.parserutils.RuleBasedConfigReader;
+import static bjc.utils.parserutils.RuleBasedReaderPragmas.*;
+
/**
* Read a component description from a file
*
@@ -15,8 +13,10 @@ import bjc.utils.parserutils.RuleBasedConfigReader;
*
*/
public class ComponentDescriptionFileParser {
+ // The reader used to read in component descriptions
private static RuleBasedConfigReader<ComponentDescriptionState> reader;
+ // Initialize the reader and its pragmas
static {
// This reader works entirely off of pragmas, so no need to handle
// rules
@@ -31,19 +31,6 @@ public class ComponentDescriptionFileParser {
setupReaderPragmas();
}
- private static BiConsumer<FunctionalStringTokenizer, ComponentDescriptionState> buildStringCollapserPragma(
- String pragmaName) {
- return (tokenizer, state) -> {
- if (!tokenizer.hasMoreTokens()) {
- throw new PragmaFormatException("Pragma " + pragmaName
- + " requires one string argument");
- }
-
- state.setName(ListUtils
- .collapseTokens(tokenizer.toList((strang) -> strang)));
- };
- }
-
/**
* Parse a component description from a stream
*
@@ -51,42 +38,29 @@ public class ComponentDescriptionFileParser {
* The stream to parse from
* @return The description parsed from the stream
*/
- public static ComponentDescription fromStream(
- InputStream inputSource) {
+ public static ComponentDescription
+ fromStream(InputStream inputSource) {
ComponentDescriptionState readState = reader
.fromStream(inputSource, new ComponentDescriptionState());
return readState.toDescription();
}
+ /*
+ * Create all the pragmas the reader needs to function
+ */
private static void setupReaderPragmas() {
- reader.addPragma("name", buildStringCollapserPragma("name"));
+ reader.addPragma("name", buildStringCollapser("name",
+ (name, state) -> state.setName(name)));
- reader.addPragma("author", buildStringCollapserPragma("author"));
+ reader.addPragma("author", buildStringCollapser("author",
+ (author, state) -> state.setAuthor(author)));
reader.addPragma("description",
- buildStringCollapserPragma("description"));
+ buildStringCollapser("description", (description,
+ state) -> state.setDescription(description)));
- reader.addPragma("version", (tokenizer, state) -> {
- if (!tokenizer.hasMoreTokens()) {
- throw new PragmaFormatException(
- "Pragma version requires one integer argument");
- }
-
- String token = tokenizer.nextToken();
-
- try {
- state.setVersion(Integer.parseInt(token));
- } catch (NumberFormatException nfex) {
- PragmaFormatException pfex = new PragmaFormatException(
- "Argument " + token
- + " to version pragma isn't a valid integer. "
- + "This pragma requires a integer argument");
-
- pfex.initCause(nfex);
-
- throw pfex;
- }
- });
+ reader.addPragma("version", buildInteger("version",
+ (version, state) -> state.setVersion(version)));
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java
index 199009c..a17a70b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java
@@ -7,12 +7,16 @@ package bjc.utils.components;
*
*/
public class ComponentDescriptionState {
+ // Tentative name of this component
private String name;
+ // Tentative description of this componet
private String description;
+ // Tentative author of this component
private String author;
+ // Tentative version of this component
private int version;
/**
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
index e05afc0..182549c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java
@@ -6,42 +6,36 @@ import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.function.BiPredicate;
import java.util.function.Function;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import bjc.utils.data.IHolder;
import bjc.utils.data.Identity;
-import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
import bjc.utils.funcutils.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* A component repository that loads its components from files in a
* directory
*
* @author ben
*
- * @param <E>
+ * @param <ComponentType>
* The type of component being read in
*/
-public class FileComponentRepository<E extends IDescribedComponent>
- implements IComponentRepository<E> {
+public class FileComponentRepository<ComponentType extends IDescribedComponent>
+ implements IComponentRepository<ComponentType> {
+ // The logger to use for storing data about this class
+ private static final Logger CLASS_LOGGER =
+ Logger.getLogger("FileComponentRepository");
- private static final Logger CLASS_LOGGER = LoggerFactory
- .getLogger(FileComponentRepository.class);
+ // The internal storage of components
+ private IMap<String, ComponentType> components;
- /**
- * The internal storage of components
- */
- private IFunctionalMap<String, E> components;
-
- /**
- * The path that all the components came from
- */
- private Path sourceDirectory;
+ // The path that all the components came from
+ private Path sourceDirectory;
/**
* Create a new component repository sourcing components from files in
@@ -57,33 +51,47 @@ public class FileComponentRepository<E extends IDescribedComponent>
* The function to use to convert files to components
*/
public FileComponentRepository(File directory,
- Function<File, ? extends E> componentReader) {
+ Function<File, ? extends ComponentType> componentReader) {
+ // Make sure we have valid arguments
if (!directory.isDirectory()) {
throw new IllegalArgumentException("File " + directory
+ " is not a directory.\n"
+ "Components can only be read from a directory");
+ } else if (componentReader == null) {
+ throw new NullPointerException(
+ "Component reader must not be null");
}
+ // Initialize our fields
components = new FunctionalMap<>();
-
sourceDirectory = directory.toPath().toAbsolutePath();
+ // Marker for making sure we don't skip the parent
IHolder<Boolean> isFirstDir = new Identity<>(true);
- BiPredicate<Path, BasicFileAttributes> firstLevelTraverser = (pth,
- attr) -> {
- if (attr.isDirectory() && !isFirstDir.getValue()) {
- // Don't skip the first directory, that's the
- // parent
- isFirstDir.replace(false);
- // Skip directories, they probably have
- // component
- return false;
- }
-
- return true;
- };
-
+ // Predicate to use to traverse all the files in a directory, but
+ // not recurse into sub-directories
+ BiPredicate<Path, BasicFileAttributes> firstLevelTraverser =
+ (pth, attr) -> {
+ if (attr.isDirectory() && !isFirstDir.getValue()) {
+
+ /*
+ * Skip directories, they probably have component
+ * support files.
+ */
+ return false;
+ }
+
+ /*
+ * Don't skip the first directory, that's the parent
+ * directory
+ */
+ isFirstDir.replace(false);
+
+ return true;
+ };
+
+ // Try reading components
try {
FileUtils.traverseDirectory(sourceDirectory,
firstLevelTraverser, (pth, attr) -> {
@@ -93,28 +101,23 @@ public class FileComponentRepository<E extends IDescribedComponent>
return true;
});
} catch (IOException ioex) {
- CLASS_LOGGER.warn("Error found reading component from file.",
- ioex);
+ CLASS_LOGGER.log(Level.WARNING, ioex,
+ () -> "Error found reading component from file.");
}
}
@Override
- public E getComponentByName(String name) {
+ public ComponentType getByName(String name) {
return components.get(name);
}
@Override
- public IFunctionalList<E> getComponentList() {
- IFunctionalList<E> returnedList = new FunctionalList<>();
-
- components
- .forEach((name, component) -> returnedList.add(component));
-
- return returnedList;
+ public IList<ComponentType> getList() {
+ return components.valueList();
}
@Override
- public IFunctionalMap<String, E> getComponents() {
+ public IMap<String, ComponentType> getAll() {
return components;
}
@@ -123,26 +126,38 @@ public class FileComponentRepository<E extends IDescribedComponent>
return "Components read from directory " + sourceDirectory + ".";
}
- private void loadComponent(Function<File, ? extends E> componentReader,
+ /*
+ * Load a component from a file
+ */
+ private void loadComponent(
+ Function<File, ? extends ComponentType> componentReader,
Path pth) {
try {
- E component = componentReader.apply(pth.toFile());
+ // Try to load the component
+ ComponentType component = componentReader.apply(pth.toFile());
if (component == null) {
throw new NullPointerException(
"Component reader read null component");
} else if (!components.containsKey(component.getName())) {
- components.put(component.getName(), component);
+ // We only care about the latest version of a component
+ ComponentType oldComponent =
+ components.put(component.getName(), component);
+
+ if (oldComponent.getVersion() > component.getVersion()) {
+ components.put(oldComponent.getName(), oldComponent);
+ }
} else {
- CLASS_LOGGER.warn("Found a duplicate component.\n"
+ CLASS_LOGGER.warning("Found a duplicate component.\n"
+ "Multiple versions of the same component are not currently supported.\n"
- + "The component" + component
- + " will not be registered .");
+ + "Only the latest version of the component"
+ + component + " will be registered .");
}
} catch (Exception ex) {
- CLASS_LOGGER.warn("Error found reading component from file "
- + pth.toString()
- + ". This component will not be loaded", ex);
+ CLASS_LOGGER.log(Level.WARNING, ex,
+ () -> "Error found reading component from file "
+ + pth.toString()
+ + ". This component will not be loaded");
}
}
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java
index 6780f2e..2644276 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java
@@ -1,17 +1,18 @@
package bjc.utils.components;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
/**
- * A collection of implementations of {@link IDescribedComponent}
+ * A collection of implementations of a particular type of
+ * {@link IDescribedComponent}
*
* @author ben
*
- * @param <E>
+ * @param <ComponentType>
* The type of components contained in this repository
*/
-public interface IComponentRepository<E extends IDescribedComponent> {
+public interface IComponentRepository<ComponentType extends IDescribedComponent> {
/**
* Get a component with a specific name
*
@@ -20,15 +21,15 @@ public interface IComponentRepository<E extends IDescribedComponent> {
* @return The named component, or null if no component with that name
* exists
*/
- public E getComponentByName(String name);
+ public ComponentType getByName(String name);
/**
* Get a list of all the registered componets
*
* @return A list of all the registered components
*/
- public default IFunctionalList<E> getComponentList() {
- return getComponents().valueList();
+ public default IList<ComponentType> getList() {
+ return getAll().valueList();
}
/**
@@ -37,7 +38,7 @@ public interface IComponentRepository<E extends IDescribedComponent> {
* @return A map from component name to component, containing all of
* the components in the repositories
*/
- public IFunctionalMap<String, E> getComponents();
+ public IMap<String, ComponentType> getAll();
/**
* Get the source from which these components came
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java
index 9ab3c05..1256e31 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazy.java
@@ -5,20 +5,42 @@ import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
+/*
+ * Implements a lazy holder that has been bound
+ */
class BoundLazy<OldType, BoundContainedType>
implements IHolder<BoundContainedType> {
+ /*
+ * The old value
+ */
private Supplier<IHolder<OldType>> oldSupplier;
+ /*
+ * The function to use to transform the old value into a new value
+ */
private Function<OldType, IHolder<BoundContainedType>> binder;
+ /*
+ * The bound value being held
+ */
private IHolder<BoundContainedType> boundHolder;
+ /*
+ * Whether the bound value has been actualized or not
+ */
private boolean holderBound;
- private IFunctionalList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>();
+ /*
+ * Transformations currently pending on the bound value
+ */
+ private IList<UnaryOperator<BoundContainedType>> actions =
+ new FunctionalList<>();
+ /*
+ * Create a new bound lazy value
+ */
public BoundLazy(Supplier<IHolder<OldType>> supp,
Function<OldType, IHolder<BoundContainedType>> binder) {
oldSupplier = supp;
@@ -26,19 +48,31 @@ class BoundLazy<OldType, BoundContainedType>
}
@Override
- public <BoundType> IHolder<BoundType> bind(
- Function<BoundContainedType, IHolder<BoundType>> bindr) {
- IFunctionalList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
-
+ public <BoundType> IHolder<BoundType>
+ bind(Function<BoundContainedType, IHolder<BoundType>> bindr) {
+ /*
+ * Prepare a list of pending actions
+ */
+ IList<UnaryOperator<BoundContainedType>> pendingActions =
+ new FunctionalList<>();
actions.forEach(pendingActions::add);
+ /*
+ * Create the new supplier of a value
+ */
Supplier<IHolder<BoundContainedType>> typeSupplier = () -> {
IHolder<BoundContainedType> oldHolder = boundHolder;
+ /*
+ * Bind the value if it hasn't been bound before
+ */
if (!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
+ /*
+ * Apply all the pending actions
+ */
return pendingActions.reduceAux(oldHolder, (action, state) -> {
return state.transform(action);
}, (value) -> value);
@@ -48,15 +82,18 @@ class BoundLazy<OldType, BoundContainedType>
}
@Override
- public <MappedType> IHolder<MappedType> map(
- Function<BoundContainedType, MappedType> mapper) {
- IFunctionalList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
-
+ public <MappedType> IHolder<MappedType>
+ map(Function<BoundContainedType, MappedType> mapper) {
+ // Prepare a list of pending actions
+ IList<UnaryOperator<BoundContainedType>> pendingActions =
+ new FunctionalList<>();
actions.forEach(pendingActions::add);
+ // Prepare the new supplier
Supplier<MappedType> typeSupplier = () -> {
IHolder<BoundContainedType> oldHolder = boundHolder;
+ // Bound the value if it hasn't been bound
if (!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
@@ -80,16 +117,16 @@ class BoundLazy<OldType, BoundContainedType>
}
@Override
- public IHolder<BoundContainedType> transform(
- UnaryOperator<BoundContainedType> transformer) {
+ public IHolder<BoundContainedType>
+ transform(UnaryOperator<BoundContainedType> transformer) {
actions.add(transformer);
return this;
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(
- Function<BoundContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType
+ unwrap(Function<BoundContainedType, UnwrappedType> unwrapper) {
if (!holderBound) {
boundHolder = oldSupplier.get().unwrap(binder::apply);
}
@@ -98,8 +135,8 @@ class BoundLazy<OldType, BoundContainedType>
}
@Override
- public <NewType> Function<BoundContainedType, IHolder<NewType>> lift(
- Function<BoundContainedType, NewType> func) {
+ public <NewType> Function<BoundContainedType, IHolder<NewType>>
+ lift(Function<BoundContainedType, NewType> func) {
return (val) -> {
return new Lazy<>(func.apply(val));
};
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java
index fcb62f6..85ec8f6 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundListHolder.java
@@ -3,20 +3,20 @@ package bjc.utils.data;
import java.util.function.Function;
import java.util.function.UnaryOperator;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
- private IFunctionalList<IHolder<ContainedType>> heldHolders;
+ private IList<IHolder<ContainedType>> heldHolders;
public BoundListHolder(
- IFunctionalList<IHolder<ContainedType>> toHold) {
+ IList<IHolder<ContainedType>> toHold) {
heldHolders = toHold;
}
@Override
public <BoundType> IHolder<BoundType> bind(
Function<ContainedType, IHolder<BoundType>> binder) {
- IFunctionalList<IHolder<BoundType>> boundHolders = heldHolders
+ IList<IHolder<BoundType>> boundHolders = heldHolders
.map((containedHolder) -> {
return containedHolder.bind(binder);
});
@@ -27,7 +27,7 @@ class BoundListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <MappedType> IHolder<MappedType> map(
Function<ContainedType, MappedType> mapper) {
- IFunctionalList<IHolder<MappedType>> mappedHolders = heldHolders
+ IList<IHolder<MappedType>> mappedHolders = heldHolders
.map((containedHolder) -> {
return containedHolder.map(mapper);
});
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
index 62b0bb0..fb1a517 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
@@ -5,7 +5,7 @@ import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* A holder that holds a means to create a value, but doesn't actually
@@ -18,7 +18,7 @@ import bjc.utils.funcdata.IFunctionalList;
public class Lazy<ContainedType> implements IHolder<ContainedType> {
private Supplier<ContainedType> valueSupplier;
- private IFunctionalList<UnaryOperator<ContainedType>> actions = new FunctionalList<>();
+ private IList<UnaryOperator<ContainedType>> actions = new FunctionalList<>();
private boolean valueMaterialized;
@@ -49,7 +49,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
}
private Lazy(Supplier<ContainedType> supp,
- IFunctionalList<UnaryOperator<ContainedType>> pendingActions) {
+ IList<UnaryOperator<ContainedType>> pendingActions) {
valueSupplier = supp;
actions = pendingActions;
@@ -58,7 +58,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
@Override
public <BoundType> IHolder<BoundType> bind(
Function<ContainedType, IHolder<BoundType>> binder) {
- IFunctionalList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
+ IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
@@ -78,7 +78,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
@Override
public <MappedType> IHolder<MappedType> map(
Function<ContainedType, MappedType> mapper) {
- IFunctionalList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
+ IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
index 8dc33d3..03765ed 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
@@ -4,7 +4,7 @@ import java.util.function.Function;
import java.util.function.UnaryOperator;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* A holder that represents a set of non-deterministic computations
@@ -15,9 +15,9 @@ import bjc.utils.funcdata.IFunctionalList;
* The type of contained value
*/
public class ListHolder<ContainedType> implements IHolder<ContainedType> {
- private IFunctionalList<ContainedType> heldValues;
+ private IList<ContainedType> heldValues;
- private ListHolder(IFunctionalList<ContainedType> toHold) {
+ private ListHolder(IList<ContainedType> toHold) {
heldValues = toHold;
}
@@ -41,7 +41,7 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <BoundType> IHolder<BoundType> bind(
Function<ContainedType, IHolder<BoundType>> binder) {
- IFunctionalList<IHolder<BoundType>> boundValues = heldValues
+ IList<IHolder<BoundType>> boundValues = heldValues
.map(binder);
return new BoundListHolder<>(boundValues);
@@ -50,7 +50,7 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public <MappedType> IHolder<MappedType> map(
Function<ContainedType, MappedType> mapper) {
- IFunctionalList<MappedType> mappedValues = heldValues.map(mapper);
+ IList<MappedType> mappedValues = heldValues.map(mapper);
return new ListHolder<>(mappedValues);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
index 0d2c1b0..eb421bc 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Pair.java
@@ -15,7 +15,9 @@ import java.util.function.Function;
*/
public class Pair<LeftType, RightType>
implements IPair<LeftType, RightType> {
+ // The left value
private LeftType leftValue;
+ // The right value
private RightType rightValue;
/**
@@ -40,24 +42,40 @@ public class Pair<LeftType, RightType>
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
+ if (binder == null) {
+ throw new NullPointerException("Binder must not be null.");
+ }
+
return binder.apply(leftValue, rightValue);
}
@Override
public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(
Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
+ if (leftBinder == null) {
+ throw new NullPointerException("Binder must not be null");
+ }
+
return leftBinder.apply(leftValue);
}
@Override
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
+ if (rightBinder == null) {
+ throw new NullPointerException("Binder must not be null");
+ }
+
return rightBinder.apply(rightValue);
}
@Override
public <MergedType> MergedType
merge(BiFunction<LeftType, RightType, MergedType> merger) {
+ if (merger == null) {
+ throw new NullPointerException("Merger must not be null");
+ }
+
return merger.apply(leftValue, rightValue);
}
@@ -70,12 +88,20 @@ public class Pair<LeftType, RightType>
@Override
public <NewLeft> IPair<NewLeft, RightType>
mapLeft(Function<LeftType, NewLeft> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
return new Pair<>(mapper.apply(leftValue), rightValue);
}
@Override
public <NewRight> IPair<LeftType, NewRight>
mapRight(Function<RightType, NewRight> mapper) {
+ if (mapper == null) {
+ throw new NullPointerException("Mapper must not be null");
+ }
+
return new Pair<>(leftValue, mapper.apply(rightValue));
}
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java
index 9776961..378a4a0 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java
@@ -7,13 +7,13 @@ import java.util.function.Function;
import bjc.utils.funcutils.ListUtils;
class ExtendedMap<KeyType, ValueType>
- implements IFunctionalMap<KeyType, ValueType> {
- private IFunctionalMap<KeyType, ValueType> delegate;
+ implements IMap<KeyType, ValueType> {
+ private IMap<KeyType, ValueType> delegate;
- private IFunctionalMap<KeyType, ValueType> store;
+ private IMap<KeyType, ValueType> store;
- public ExtendedMap(IFunctionalMap<KeyType, ValueType> delegate,
- IFunctionalMap<KeyType, ValueType> store) {
+ public ExtendedMap(IMap<KeyType, ValueType> delegate,
+ IMap<KeyType, ValueType> store) {
this.delegate = delegate;
this.store = store;
}
@@ -28,7 +28,7 @@ class ExtendedMap<KeyType, ValueType>
}
@Override
- public IFunctionalMap<KeyType, ValueType> extend() {
+ public IMap<KeyType, ValueType> extend() {
return new ExtendedMap<>(this, new FunctionalMap<>());
}
@@ -68,12 +68,12 @@ class ExtendedMap<KeyType, ValueType>
}
@Override
- public IFunctionalList<KeyType> keyList() {
+ public IList<KeyType> keyList() {
return ListUtils.mergeLists(store.keyList(), delegate.keyList());
}
@Override
- public <MappedValue> IFunctionalMap<KeyType, MappedValue> mapValues(
+ public <MappedValue> IMap<KeyType, MappedValue> mapValues(
Function<ValueType, MappedValue> transformer) {
return new TransformedValueMap<>(this, transformer);
}
@@ -89,7 +89,7 @@ class ExtendedMap<KeyType, ValueType>
}
@Override
- public IFunctionalList<ValueType> valueList() {
+ public IList<ValueType> valueList() {
return ListUtils.mergeLists(store.valueList(),
delegate.valueList());
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java
index 8579693..638ad7e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java
@@ -27,7 +27,7 @@ import bjc.utils.data.Pair;
* @param <E>
* The type in this list
*/
-public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
+public class FunctionalList<E> implements Cloneable, IList<E> {
/**
* The list used as a backing store
*/
@@ -148,8 +148,8 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* @return A list
*/
@Override
- public IFunctionalList<E> clone() {
- IFunctionalList<E> clonedList = new FunctionalList<>();
+ public IList<E> clone() {
+ IList<E> clonedList = new FunctionalList<>();
for (E element : wrappedList) {
clonedList.add(element);
@@ -166,8 +166,8 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* IFunctionalList, java.util.function.BiFunction)
*/
@Override
- public <T, F> IFunctionalList<F> combineWith(
- IFunctionalList<T> rightList,
+ public <T, F> IList<F> combineWith(
+ IList<T> rightList,
BiFunction<E, T, F> itemCombiner) {
if (rightList == null) {
throw new NullPointerException(
@@ -176,7 +176,7 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
throw new NullPointerException("Combiner must not be null");
}
- IFunctionalList<F> returnedList = new FunctionalList<>();
+ IList<F> returnedList = new FunctionalList<>();
// Get the iterator for the other list
Iterator<T> rightIterator = rightList.toIterable().iterator();
@@ -227,17 +227,17 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* Function)
*/
@Override
- public <T> IFunctionalList<T> flatMap(
- Function<E, IFunctionalList<T>> elementExpander) {
+ public <T> IList<T> flatMap(
+ Function<E, IList<T>> elementExpander) {
if (elementExpander == null) {
throw new NullPointerException("Expander must not be null");
}
- IFunctionalList<T> returnedList = new FunctionalList<>(
+ IList<T> returnedList = new FunctionalList<>(
this.wrappedList.size());
forEach(element -> {
- IFunctionalList<T> expandedElement = elementExpander
+ IList<T> expandedElement = elementExpander
.apply(element);
if (expandedElement == null) {
@@ -320,12 +320,12 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* Predicate)
*/
@Override
- public IFunctionalList<E> getMatching(Predicate<E> matchPredicate) {
+ public IList<E> getMatching(Predicate<E> matchPredicate) {
if (matchPredicate == null) {
throw new NullPointerException("Predicate must not be null");
}
- IFunctionalList<E> returnedList = new FunctionalList<>();
+ IList<E> returnedList = new FunctionalList<>();
wrappedList.forEach((element) -> {
if (matchPredicate.test(element)) {
@@ -361,7 +361,7 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* Check if a partition has room for another item
*/
private Boolean isPartitionFull(int numberPerPartition,
- IHolder<IFunctionalList<E>> currentPartition) {
+ IHolder<IList<E>> currentPartition) {
return currentPartition.unwrap(
(partition) -> partition.getSize() >= numberPerPartition);
}
@@ -373,12 +373,12 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* bjc.utils.funcdata.IFunctionalList#map(java.util.function.Function)
*/
@Override
- public <T> IFunctionalList<T> map(Function<E, T> elementTransformer) {
+ public <T> IList<T> map(Function<E, T> elementTransformer) {
if (elementTransformer == null) {
throw new NullPointerException("Transformer must be not null");
}
- IFunctionalList<T> returnedList = new FunctionalList<>(
+ IList<T> returnedList = new FunctionalList<>(
this.wrappedList.size());
forEach(element -> {
@@ -396,8 +396,8 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* IFunctionalList)
*/
@Override
- public <T> IFunctionalList<IPair<E, T>> pairWith(
- IFunctionalList<T> rightList) {
+ public <T> IList<IPair<E, T>> pairWith(
+ IList<T> rightList) {
return combineWith(rightList, Pair<E, T>::new);
}
@@ -407,7 +407,7 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
* @see bjc.utils.funcdata.IFunctionalList#partition(int)
*/
@Override
- public IFunctionalList<IFunctionalList<E>> partition(
+ public IList<IList<E>> partition(
int numberPerPartition) {
if (numberPerPartition < 1
|| numberPerPartition > wrappedList.size()) {
@@ -416,10 +416,10 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
+ wrappedList.size());
}
- IFunctionalList<IFunctionalList<E>> returnedList = new FunctionalList<>();
+ IList<IList<E>> returnedList = new FunctionalList<>();
// The current partition being filled
- IHolder<IFunctionalList<E>> currentPartition = new Identity<>(
+ IHolder<IList<E>> currentPartition = new Identity<>(
new FunctionalList<>());
this.forEach((element) -> {
@@ -559,7 +559,7 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> {
}
@Override
- public IFunctionalList<E> tail() {
+ public IList<E> tail() {
return new FunctionalList<>(wrappedList.subList(1, getSize()));
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java
index fb8bb81..0002a58 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java
@@ -9,7 +9,7 @@ import java.util.function.Function;
import bjc.utils.data.IPair;
/**
- * Basic implementation of {@link IFunctionalMap}
+ * Basic implementation of {@link IMap}
*
* @author ben
*
@@ -19,7 +19,7 @@ import bjc.utils.data.IPair;
* The type of the map's values
*/
public class FunctionalMap<KeyType, ValueType>
- implements IFunctionalMap<KeyType, ValueType> {
+ implements IMap<KeyType, ValueType> {
private Map<KeyType, ValueType> wrappedMap;
/**
@@ -71,7 +71,7 @@ public class FunctionalMap<KeyType, ValueType>
}
@Override
- public IFunctionalMap<KeyType, ValueType> extend() {
+ public IMap<KeyType, ValueType> extend() {
return new ExtendedMap<>(this, new FunctionalMap<>());
}
@@ -115,7 +115,7 @@ public class FunctionalMap<KeyType, ValueType>
}
@Override
- public IFunctionalList<KeyType> keyList() {
+ public IList<KeyType> keyList() {
FunctionalList<KeyType> keys = new FunctionalList<>();
wrappedMap.keySet().forEach((key) -> {
@@ -132,7 +132,7 @@ public class FunctionalMap<KeyType, ValueType>
* Function)
*/
@Override
- public <MappedValue> IFunctionalMap<KeyType, MappedValue> mapValues(
+ public <MappedValue> IMap<KeyType, MappedValue> mapValues(
Function<ValueType, MappedValue> transformer) {
if (transformer == null) {
throw new NullPointerException("Transformer must not be null");
@@ -166,7 +166,7 @@ public class FunctionalMap<KeyType, ValueType>
}
@Override
- public IFunctionalList<ValueType> valueList() {
+ public IList<ValueType> valueList() {
FunctionalList<ValueType> values = new FunctionalList<>();
wrappedMap.values().forEach((value) -> {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
index aa6fca3..18617d1 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
@@ -140,7 +140,7 @@ public class FunctionalStringTokenizer {
*
* @return This tokenizer, converted into a list of strings
*/
- public IFunctionalList<String> toList() {
+ public IList<String> toList() {
return toList((String element) -> element);
}
@@ -155,13 +155,13 @@ public class FunctionalStringTokenizer {
* The function to use to convert tokens.
* @return A list containing all of the converted tokens.
*/
- public <E> IFunctionalList<E> toList(
+ public <E> IList<E> toList(
Function<String, E> tokenTransformer) {
if (tokenTransformer == null) {
throw new NullPointerException("Transformer must not be null");
}
- IFunctionalList<E> returnList = new FunctionalList<>();
+ IList<E> returnList = new FunctionalList<>();
// Add each token to the list after transforming it
forEachToken(token -> {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
index 5327dbe..c45551e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
@@ -22,7 +22,7 @@ import bjc.utils.data.IPair;
* @param <ContainedType>
* The type in this list
*/
-public interface IFunctionalList<ContainedType> {
+public interface IList<ContainedType> {
/**
* Add an item to this list
@@ -87,8 +87,8 @@ public interface IFunctionalList<ContainedType> {
* The function to use for combining element pairs.
* @return A new list containing the merged pairs of lists.
*/
- <OtherType, CombinedType> IFunctionalList<CombinedType> combineWith(
- IFunctionalList<OtherType> rightList,
+ <OtherType, CombinedType> IList<CombinedType> combineWith(
+ IList<OtherType> rightList,
BiFunction<ContainedType, OtherType, CombinedType> itemCombiner);
/**
@@ -126,8 +126,8 @@ public interface IFunctionalList<ContainedType> {
* @return A new list containing the flattened results of applying the
* provided function.
*/
- <MappedType> IFunctionalList<MappedType> flatMap(
- Function<ContainedType, IFunctionalList<MappedType>> elementExpander);
+ <MappedType> IList<MappedType> flatMap(
+ Function<ContainedType, IList<MappedType>> elementExpander);
/**
* Apply a given action for each member of the list
@@ -172,7 +172,7 @@ public interface IFunctionalList<ContainedType> {
* The predicate to match by
* @return A list containing all elements that match the predicate
*/
- IFunctionalList<ContainedType> getMatching(
+ IList<ContainedType> getMatching(
Predicate<ContainedType> matchPredicate);
/**
@@ -200,7 +200,7 @@ public interface IFunctionalList<ContainedType> {
* The function to apply to each element in the list
* @return A new list containing the mapped elements of this list.
*/
- <MappedType> IFunctionalList<MappedType> map(
+ <MappedType> IList<MappedType> map(
Function<ContainedType, MappedType> elementTransformer);
/**
@@ -214,8 +214,8 @@ public interface IFunctionalList<ContainedType> {
* @return A list containing pairs of this element and the specified
* list
*/
- <OtherType> IFunctionalList<IPair<ContainedType, OtherType>> pairWith(
- IFunctionalList<OtherType> rightList);
+ <OtherType> IList<IPair<ContainedType, OtherType>> pairWith(
+ IList<OtherType> rightList);
/**
* Partition this list into a list of sublists
@@ -224,7 +224,7 @@ public interface IFunctionalList<ContainedType> {
* The size of elements to put into each one of the sublists
* @return A list partitioned into partitions of size nPerPart
*/
- IFunctionalList<IFunctionalList<ContainedType>> partition(
+ IList<IList<ContainedType>> partition(
int numberPerPartition);
/**
@@ -330,7 +330,7 @@ public interface IFunctionalList<ContainedType> {
*
* @return The list without the first element
*/
- public IFunctionalList<ContainedType> tail();
+ public IList<ContainedType> tail();
/**
* Convert this list into an array
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
index 8a54246..f5f7a26 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
@@ -15,7 +15,7 @@ import java.util.function.Function;
* The type of this map's values
*
*/
-public interface IFunctionalMap<KeyType, ValueType> {
+public interface IMap<KeyType, ValueType> {
/**
* Check if this map contains the specified key
@@ -32,7 +32,7 @@ public interface IFunctionalMap<KeyType, ValueType> {
*
* @return An extended map
*/
- IFunctionalMap<KeyType, ValueType> extend();
+ IMap<KeyType, ValueType> extend();
/**
* Execute an action for each entry in the map
@@ -81,7 +81,7 @@ public interface IFunctionalMap<KeyType, ValueType> {
*
* @return A list of all the keys in this map
*/
- IFunctionalList<KeyType> keyList();
+ IList<KeyType> keyList();
/**
* Transform the values returned by this map.
@@ -96,7 +96,7 @@ public interface IFunctionalMap<KeyType, ValueType> {
* The function to use to transform values
* @return The map where each value will be transformed after lookup
*/
- <V2> IFunctionalMap<KeyType, V2> mapValues(
+ <V2> IMap<KeyType, V2> mapValues(
Function<ValueType, V2> transformer);
/**
@@ -133,5 +133,5 @@ public interface IFunctionalMap<KeyType, ValueType> {
*
* @return A list of values in this map
*/
- IFunctionalList<ValueType> valueList();
+ IList<ValueType> valueList();
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java
index 026f3f8..e0c63e3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java
@@ -43,7 +43,7 @@ public interface ITree<ContainedType> {
*/
public <NewType, ReturnedType> ReturnedType collapse(
Function<ContainedType, NewType> leafTransform,
- Function<ContainedType, Function<IFunctionalList<NewType>, NewType>> nodeCollapser,
+ Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser,
Function<NewType, ReturnedType> resultTransformer);
/**
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/PushdownMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/PushdownMap.java
index cc31923..ed9aa63 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/PushdownMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/PushdownMap.java
@@ -13,7 +13,7 @@ import java.util.function.Function;
* @param <ValueType>
*/
public class PushdownMap<KeyType, ValueType>
- implements IFunctionalMap<KeyType, ValueType> {
+ implements IMap<KeyType, ValueType> {
@Override
public boolean containsKey(KeyType key) {
@@ -22,7 +22,7 @@ public class PushdownMap<KeyType, ValueType>
}
@Override
- public IFunctionalMap<KeyType, ValueType> extend() {
+ public IMap<KeyType, ValueType> extend() {
// TODO Auto-generated method stub
return null;
}
@@ -58,13 +58,13 @@ public class PushdownMap<KeyType, ValueType>
}
@Override
- public IFunctionalList<KeyType> keyList() {
+ public IList<KeyType> keyList() {
// TODO Auto-generated method stub
return null;
}
@Override
- public <V2> IFunctionalMap<KeyType, V2> mapValues(
+ public <V2> IMap<KeyType, V2> mapValues(
Function<ValueType, V2> transformer) {
// TODO Auto-generated method stub
return null;
@@ -83,7 +83,7 @@ public class PushdownMap<KeyType, ValueType>
}
@Override
- public IFunctionalList<ValueType> valueList() {
+ public IList<ValueType> valueList() {
// TODO Auto-generated method stub
return null;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java
index 1d52d82..cf54935 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java
@@ -17,11 +17,11 @@ import java.util.function.Function;
* The type of the transformed values
*/
final class TransformedValueMap<OldKey, OldValue, NewValue>
- implements IFunctionalMap<OldKey, NewValue> {
- private IFunctionalMap<OldKey, OldValue> mapToTransform;
+ implements IMap<OldKey, NewValue> {
+ private IMap<OldKey, OldValue> mapToTransform;
private Function<OldValue, NewValue> transformer;
- public TransformedValueMap(IFunctionalMap<OldKey, OldValue> destMap,
+ public TransformedValueMap(IMap<OldKey, OldValue> destMap,
Function<OldValue, NewValue> transform) {
mapToTransform = destMap;
transformer = transform;
@@ -33,7 +33,7 @@ final class TransformedValueMap<OldKey, OldValue, NewValue>
}
@Override
- public IFunctionalMap<OldKey, NewValue> extend() {
+ public IMap<OldKey, NewValue> extend() {
return new ExtendedMap<>(this, new FunctionalMap<>());
}
@@ -67,12 +67,12 @@ final class TransformedValueMap<OldKey, OldValue, NewValue>
}
@Override
- public IFunctionalList<OldKey> keyList() {
+ public IList<OldKey> keyList() {
return mapToTransform.keyList();
}
@Override
- public <MappedValue> IFunctionalMap<OldKey, MappedValue> mapValues(
+ public <MappedValue> IMap<OldKey, MappedValue> mapValues(
Function<NewValue, MappedValue> transform) {
return new TransformedValueMap<>(this, transform);
}
@@ -94,7 +94,7 @@ final class TransformedValueMap<OldKey, OldValue, NewValue>
}
@Override
- public IFunctionalList<NewValue> valueList() {
+ public IList<NewValue> valueList() {
return mapToTransform.valueList().map(transformer);
}
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java
index 4ddcd45..34b70d5 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java
@@ -17,7 +17,7 @@ import bjc.utils.funcutils.StringUtils;
*/
public class Tree<ContainedType> implements ITree<ContainedType> {
private ContainedType data;
- private IFunctionalList<ITree<ContainedType>> children;
+ private IList<ITree<ContainedType>> children;
private boolean hasChildren;
@@ -44,7 +44,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
* A list of children for this node
*/
public Tree(ContainedType leafToken,
- IFunctionalList<ITree<ContainedType>> childrn) {
+ IList<ITree<ContainedType>> childrn) {
data = leafToken;
hasChildren = true;
@@ -95,7 +95,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public <NewType, ReturnedType> ReturnedType collapse(
Function<ContainedType, NewType> leafTransform,
- Function<ContainedType, Function<IFunctionalList<NewType>, NewType>> nodeCollapser,
+ Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser,
Function<NewType, ReturnedType> resultTransformer) {
return resultTransformer
@@ -129,12 +129,12 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
protected <NewType> NewType internalCollapse(
Function<ContainedType, NewType> leafTransform,
- Function<ContainedType, Function<IFunctionalList<NewType>, NewType>> nodeCollapser) {
+ Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser) {
if (hasChildren) {
- Function<IFunctionalList<NewType>, NewType> nodeTransformer = nodeCollapser
+ Function<IList<NewType>, NewType> nodeTransformer = nodeCollapser
.apply(data);
- IFunctionalList<NewType> collapsedChildren = children
+ IList<NewType> collapsedChildren = children
.map((child) -> {
return child.collapse(leafTransform, nodeCollapser,
(subTreeVal) -> subTreeVal);
@@ -169,7 +169,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
Function<ContainedType, MappedType> leafTransformer,
Function<ContainedType, MappedType> operatorTransformer) {
if (hasChildren) {
- IFunctionalList<ITree<MappedType>> mappedChildren = children
+ IList<ITree<MappedType>> mappedChildren = children
.map((child) -> {
return child.rebuildTree(leafTransformer,
operatorTransformer);
@@ -279,7 +279,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
public <MappedType> ITree<MappedType> transformTree(
Function<ContainedType, MappedType> transformer) {
if (hasChildren) {
- IFunctionalList<ITree<MappedType>> transformedChildren = children
+ IList<ITree<MappedType>> transformedChildren = children
.map((child) -> child.transformTree(transformer));
return new Tree<>(transformer.apply(data),
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java
index 712f0e3..9cfc9a4 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java
@@ -6,7 +6,7 @@ import java.util.List;
import java.util.function.Predicate;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* A binary search tree, with some mild support for functional traversal.
@@ -74,7 +74,7 @@ public class BinarySearchTree<T> {
* The distance from the pivot
* @return Whether the adjusted pivot is with the list
*/
- private boolean adjustedPivotInBounds(IFunctionalList<T> elements,
+ private boolean adjustedPivotInBounds(IList<T> elements,
int pivot, int pivotAdjustment) {
return (pivot - pivotAdjustment) >= 0
&& (pivot + pivotAdjustment) < elements.getSize();
@@ -85,7 +85,7 @@ public class BinarySearchTree<T> {
* time, but also O(N) space.
*/
public void balance() {
- IFunctionalList<T> elements = new FunctionalList<>();
+ IList<T> elements = new FunctionalList<>();
// Add each element to the list in sorted order
rootElement.forEach(TreeLinearizationMethod.INORDER,
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
index 67fd5ec..61b13ea 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
@@ -4,7 +4,7 @@ import java.util.Random;
import java.util.function.Consumer;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* Utility methods on enums
@@ -31,7 +31,7 @@ public class EnumUtils {
int nValues, Consumer<E> action, Random rnd) {
E[] enumValues = enumClass.getEnumConstants();
- IFunctionalList<E> valueList = new FunctionalList<>(enumValues);
+ IList<E> valueList = new FunctionalList<>(enumValues);
int randomValueCount = enumValues.length - nValues;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
index 67cf4b1..34a7ee0 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
@@ -5,7 +5,7 @@ import java.util.function.Function;
import bjc.utils.data.IHolder;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* Implements a single group partitioning pass on a list
@@ -16,16 +16,16 @@ import bjc.utils.funcdata.IFunctionalList;
* The type of element in the list being partitioned
*/
final class GroupPartIteration<E> implements Consumer<E> {
- private IFunctionalList<IFunctionalList<E>> returnedList;
- private IHolder<IFunctionalList<E>> currentPartition;
- private IFunctionalList<E> rejectedItems;
+ private IList<IList<E>> returnedList;
+ private IHolder<IList<E>> currentPartition;
+ private IList<E> rejectedItems;
private IHolder<Integer> numberInCurrentPartition;
private int numberPerPartition;
private Function<E, Integer> elementCounter;
- public GroupPartIteration(IFunctionalList<IFunctionalList<E>> returned,
- IHolder<IFunctionalList<E>> currPart,
- IFunctionalList<E> rejects, IHolder<Integer> numInCurrPart,
+ public GroupPartIteration(IList<IList<E>> returned,
+ IHolder<IList<E>> currPart,
+ IList<E> rejects, IHolder<Integer> numInCurrPart,
int nPerPart, Function<E, Integer> eleCount) {
this.returnedList = returned;
this.currentPartition = currPart;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
index ea15a78..913ccc4 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
@@ -8,7 +8,7 @@ import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* Utilities for manipulating FunctionalLists that don't belong in the
@@ -28,7 +28,7 @@ public class ListUtils {
* The list of tokens to collapse
* @return The collapsed string of tokens
*/
- public static String collapseTokens(IFunctionalList<String> input) {
+ public static String collapseTokens(IList<String> input) {
if (input == null) {
throw new NullPointerException("Input must not be null");
}
@@ -46,7 +46,7 @@ public class ListUtils {
* The seperator to use for seperating tokens
* @return The collapsed string of tokens
*/
- public static String collapseTokens(IFunctionalList<String> input,
+ public static String collapseTokens(IList<String> input,
String seperator) {
if (input == null) {
throw new NullPointerException("Input must not be null");
@@ -78,8 +78,8 @@ public class ListUtils {
* @return The tokens that have been deaffixed
*
*/
- public static IFunctionalList<String> deAffixTokens(
- IFunctionalList<String> input,
+ public static IList<String> deAffixTokens(
+ IList<String> input,
Deque<IPair<String, String>> operators) {
if (input == null) {
throw new NullPointerException("Input must not be null");
@@ -88,7 +88,7 @@ public class ListUtils {
"Set of operators must not be null");
}
- IHolder<IFunctionalList<String>> returnedList = new Identity<>(
+ IHolder<IList<String>> returnedList = new Identity<>(
input);
operators.forEach((operator) -> returnedList
@@ -115,10 +115,10 @@ public class ListUtils {
* selected from the specified list without replacement
*/
- public static <E> IFunctionalList<E> drawWithoutReplacement(
- IFunctionalList<E> list, int numberOfItems,
+ public static <E> IList<E> drawWithoutReplacement(
+ IList<E> list, int numberOfItems,
Function<Integer, Integer> rng) {
- IFunctionalList<E> selectedItems = new FunctionalList<>(
+ IList<E> selectedItems = new FunctionalList<>(
new ArrayList<>(numberOfItems));
int totalItems = list.getSize();
@@ -153,10 +153,10 @@ public class ListUtils {
* @return A new list containing the desired number of items randomly
* selected from the specified list
*/
- public static <E> IFunctionalList<E> drawWithReplacement(
- IFunctionalList<E> list, int numberOfItems,
+ public static <E> IList<E> drawWithReplacement(
+ IList<E> list, int numberOfItems,
Function<Integer, Integer> rng) {
- IFunctionalList<E> selectedItems = new FunctionalList<>(
+ IList<E> selectedItems = new FunctionalList<>(
new ArrayList<>(numberOfItems));
for (int i = 0; i < numberOfItems; i++) {
@@ -181,8 +181,8 @@ public class ListUtils {
* The number of elements to put in each partition
* @return A list partitioned according to the above rules
*/
- public static <E> IFunctionalList<IFunctionalList<E>> groupPartition(
- IFunctionalList<E> input, Function<E, Integer> elementCounter,
+ public static <E> IList<IList<E>> groupPartition(
+ IList<E> input, Function<E, Integer> elementCounter,
int numberPerPartition) {
if (input == null) {
throw new NullPointerException("Input list must not be null");
@@ -199,17 +199,17 @@ public class ListUtils {
/*
* List that holds our results
*/
- IFunctionalList<IFunctionalList<E>> returnedList = new FunctionalList<>();
+ IList<IList<E>> returnedList = new FunctionalList<>();
/*
* List that holds current partition
*/
- IHolder<IFunctionalList<E>> currentPartition = new Identity<>(
+ IHolder<IList<E>> currentPartition = new Identity<>(
new FunctionalList<>());
/*
* List that holds elements rejected during current pass
*/
- IFunctionalList<E> rejectedElements = new FunctionalList<>();
+ IList<E> rejectedElements = new FunctionalList<>();
/*
* The effective number of elements in the current partitition
@@ -254,11 +254,11 @@ public class ListUtils {
* @return A list containing all the elements of the lists
*/
@SafeVarargs
- public static <E> IFunctionalList<E> mergeLists(
- IFunctionalList<E>... lists) {
- IFunctionalList<E> returnedList = new FunctionalList<>();
+ public static <E> IList<E> mergeLists(
+ IList<E>... lists) {
+ IList<E> returnedList = new FunctionalList<>();
- for (IFunctionalList<E> list : lists) {
+ for (IList<E> list : lists) {
list.forEach(returnedList::add);
}
@@ -279,8 +279,8 @@ public class ListUtils {
* @return A list of tokens split on all the operators
*
*/
- public static IFunctionalList<String> splitTokens(
- IFunctionalList<String> input,
+ public static IList<String> splitTokens(
+ IList<String> input,
Deque<IPair<String, String>> operators) {
if (input == null) {
throw new NullPointerException("Input must not be null");
@@ -289,7 +289,7 @@ public class ListUtils {
"Set of operators must not be null");
}
- IHolder<IFunctionalList<String>> returnedList = new Identity<>(
+ IHolder<IList<String>> returnedList = new Identity<>(
input);
operators.forEach((operator) -> {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
index 9ea3596..6ed4ecf 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
@@ -3,10 +3,10 @@ package bjc.utils.funcutils;
import java.util.function.BiFunction;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
final class TokenDeaffixer
- implements BiFunction<String, String, IFunctionalList<String>> {
+ implements BiFunction<String, String, IList<String>> {
private String token;
public TokenDeaffixer(String tok) {
@@ -14,7 +14,7 @@ final class TokenDeaffixer
}
@Override
- public IFunctionalList<String> apply(String operatorName,
+ public IList<String> apply(String operatorName,
String operatorRegex) {
if (operatorName == null) {
throw new NullPointerException(
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
index 68dde25..b9693a7 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
@@ -3,10 +3,10 @@ package bjc.utils.funcutils;
import java.util.function.BiFunction;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
final class TokenSplitter
- implements BiFunction<String, String, IFunctionalList<String>> {
+ implements BiFunction<String, String, IList<String>> {
private String tokenToSplit;
public TokenSplitter(String tok) {
@@ -14,7 +14,7 @@ final class TokenSplitter
}
@Override
- public IFunctionalList<String> apply(String operatorName,
+ public IList<String> apply(String operatorName,
String operatorRegex) {
if (operatorName == null) {
throw new NullPointerException(
@@ -29,10 +29,10 @@ final class TokenSplitter
return new FunctionalList<>(tokenToSplit);
}
- IFunctionalList<String> splitTokens = new FunctionalList<>(
+ IList<String> splitTokens = new FunctionalList<>(
tokenToSplit.split(operatorRegex));
- IFunctionalList<String> result = new FunctionalList<>();
+ IList<String> result = new FunctionalList<>();
int tokenExpansionSize = splitTokens.getSize();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java b/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java
index 963fb32..a764a08 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java
@@ -1,7 +1,7 @@
package bjc.utils.gen;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* A weighted grammar where all the rules have a equal chance of occuring.
@@ -28,8 +28,8 @@ public class RandomGrammar<E> extends WeightedGrammar<E> {
* The cases to add for this rule.
*/
@SafeVarargs
- public final void addCases(E rule, IFunctionalList<E>... cases) {
- for (IFunctionalList<E> currentCase : cases) {
+ public final void addCases(E rule, IList<E>... cases) {
+ for (IList<E> currentCase : cases) {
super.addCase(rule, 1, currentCase);
}
}
@@ -43,10 +43,10 @@ public class RandomGrammar<E> extends WeightedGrammar<E> {
* The cases to add for this rule.
*/
@SafeVarargs
- public final void makeRule(E rule, IFunctionalList<E>... cases) {
+ public final void makeRule(E rule, IList<E>... cases) {
super.addRule(rule);
- for (IFunctionalList<E> currentCase : cases) {
+ for (IList<E> currentCase : cases) {
super.addCase(rule, 1, currentCase);
}
}
@@ -60,7 +60,7 @@ public class RandomGrammar<E> extends WeightedGrammar<E> {
* The cases to add for this rule.
*/
public void makeRule(E rule,
- IFunctionalList<IFunctionalList<E>> cases) {
+ IList<IList<E>> cases) {
if (cases == null) {
throw new NullPointerException("Cases must not be null");
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java
index 131e507..78db7d8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java
@@ -7,8 +7,8 @@ import bjc.utils.data.IPair;
import bjc.utils.data.Pair;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
/**
* A random grammar, where certain rules will come up more often than
@@ -28,7 +28,7 @@ public class WeightedGrammar<E> {
/**
* The rules currently in this grammar
*/
- protected IFunctionalMap<E, WeightedRandom<IFunctionalList<E>>> rules;
+ protected IMap<E, WeightedRandom<IList<E>>> rules;
/**
* The random number generator used for random numbers
@@ -38,7 +38,7 @@ public class WeightedGrammar<E> {
/**
* All of the subgrammars of this grammar
*/
- protected IFunctionalMap<E, WeightedGrammar<E>> subgrammars;
+ protected IMap<E, WeightedGrammar<E>> subgrammars;
/**
* Create a new weighted grammar.
@@ -77,7 +77,7 @@ public class WeightedGrammar<E> {
* The case being added.
*/
public void addCase(E ruleName, int probability,
- IFunctionalList<E> cse) {
+ IList<E> cse) {
if (ruleName == null) {
throw new NullPointerException("Rule name must be not null");
} else if (cse == null) {
@@ -146,7 +146,7 @@ public class WeightedGrammar<E> {
* @return Whether or not the rule was succesfully added.
*/
public boolean addRule(E name,
- WeightedRandom<IFunctionalList<E>> cases) {
+ WeightedRandom<IList<E>> cases) {
if (name == null) {
throw new NullPointerException("Name must not be null");
} else if (cases == null) {
@@ -222,15 +222,15 @@ public class WeightedGrammar<E> {
* The rule to test.
* @return A set of sentances generated by the specified rule.
*/
- public IFunctionalList<IFunctionalList<E>> generateDebugValues(
+ public IList<IList<E>> generateDebugValues(
E ruleName) {
if (ruleName == null) {
throw new NullPointerException("Rule name must not be null");
}
- IFunctionalList<IFunctionalList<E>> returnedList = new FunctionalList<>();
+ IList<IList<E>> returnedList = new FunctionalList<>();
- WeightedRandom<IFunctionalList<E>> ruleGenerator = rules
+ WeightedRandom<IList<E>> ruleGenerator = rules
.get(ruleName);
for (int i = 0; i < 10; i++) {
@@ -255,7 +255,7 @@ public class WeightedGrammar<E> {
* @return A randomly generated sentance from the specified initial
* rule.
*/
- public <T> IFunctionalList<T> generateGenericValues(E initRule,
+ public <T> IList<T> generateGenericValues(E initRule,
Function<E, T> tokenTransformer, T spacer) {
if (initRule == null) {
throw new NullPointerException(
@@ -266,7 +266,7 @@ public class WeightedGrammar<E> {
throw new NullPointerException("Spacer must not be null");
}
- IFunctionalList<T> returnedList = new FunctionalList<>();
+ IList<T> returnedList = new FunctionalList<>();
if (subgrammars.containsKey(initRule)) {
subgrammars.get(initRule).generateGenericValues(initRule,
@@ -309,7 +309,7 @@ public class WeightedGrammar<E> {
* @return A list of random grammar elements generated by the specified
* rule.
*/
- public IFunctionalList<E> generateListValues(E initRule, E spacer) {
+ public IList<E> generateListValues(E initRule, E spacer) {
return generateGenericValues(initRule, strang -> strang, spacer);
}
@@ -336,7 +336,7 @@ public class WeightedGrammar<E> {
*
* @return The set of all rule names in this grammar
*/
- public IFunctionalList<E> getRuleNames() {
+ public IList<E> getRuleNames() {
return rules.keyList();
}
@@ -389,16 +389,16 @@ public class WeightedGrammar<E> {
"Number of times to prefix must be positive.");
}
- WeightedRandom<IFunctionalList<E>> rule = rules.get(ruleName);
+ WeightedRandom<IList<E>> rule = rules.get(ruleName);
- IFunctionalList<IPair<Integer, IFunctionalList<E>>> newResults = new FunctionalList<>();
+ IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>();
rule.getValues().forEach((pair) -> {
- IFunctionalList<IFunctionalList<E>> newRule = new FunctionalList<>();
+ IList<IList<E>> newRule = new FunctionalList<>();
for (int i = 1; i <= numberOfTimes; i++) {
- IFunctionalList<E> newCase = pair.merge((left, right) -> {
- IFunctionalList<E> returnVal = new FunctionalList<>();
+ IList<E> newCase = pair.merge((left, right) -> {
+ IList<E> returnVal = new FunctionalList<>();
for (E val : right.toIterable()) {
returnVal.add(val);
@@ -449,13 +449,13 @@ public class WeightedGrammar<E> {
"Prefix token must not be null");
}
- WeightedRandom<IFunctionalList<E>> rule = rules.get(ruleName);
+ WeightedRandom<IList<E>> rule = rules.get(ruleName);
- IFunctionalList<IPair<Integer, IFunctionalList<E>>> newResults = new FunctionalList<>();
+ IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>();
rule.getValues().forEach((pair) -> {
- IFunctionalList<E> newCase = pair.merge((left, right) -> {
- IFunctionalList<E> returnVal = new FunctionalList<>();
+ IList<E> newCase = pair.merge((left, right) -> {
+ IList<E> returnVal = new FunctionalList<>();
for (E val : right.toIterable()) {
returnVal.add(val);
@@ -503,13 +503,13 @@ public class WeightedGrammar<E> {
"Prefix token must not be null");
}
- WeightedRandom<IFunctionalList<E>> rule = rules.get(ruleName);
+ WeightedRandom<IList<E>> rule = rules.get(ruleName);
- IFunctionalList<IPair<Integer, IFunctionalList<E>>> newResults = new FunctionalList<>();
+ IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>();
rule.getValues().forEach((par) -> {
- IFunctionalList<E> newCase = par.merge((left, right) -> {
- IFunctionalList<E> returnVal = new FunctionalList<>();
+ IList<E> newCase = par.merge((left, right) -> {
+ IList<E> returnVal = new FunctionalList<>();
for (E val : right.toIterable()) {
returnVal.add(val);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java
index 43d9928..7c6af23 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java
@@ -6,7 +6,7 @@ import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* Represents a random number generator where certain results are weighted
@@ -21,12 +21,12 @@ public class WeightedRandom<E> {
/**
* The list of probabilities for each result
*/
- private IFunctionalList<Integer> probabilities;
+ private IList<Integer> probabilities;
/**
* The list of possible results to pick from
*/
- private IFunctionalList<E> results;
+ private IList<E> results;
/**
* The source for any needed random numbers
@@ -103,7 +103,7 @@ public class WeightedRandom<E> {
*
* @return A list of all the values that can be generated
*/
- public IFunctionalList<E> getResults() {
+ public IList<E> getResults() {
return results;
}
@@ -113,7 +113,7 @@ public class WeightedRandom<E> {
*
* @return A list of pairs of values and value probabilities
*/
- public IFunctionalList<IPair<Integer, E>> getValues() {
+ public IList<IPair<Integer, E>> getValues() {
return probabilities.pairWith(results);
}
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java b/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
index 32d3b34..ff9103e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java
@@ -10,8 +10,8 @@ import bjc.utils.data.IHolder;
import bjc.utils.data.Identity;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
import bjc.utils.funcutils.FuncUtils;
/**
@@ -65,7 +65,7 @@ public class AdjacencyMap<T> {
"The number of vertices must be greater than 0");
}
- IFunctionalList<Integer> vertices = new FunctionalList<>();
+ IList<Integer> vertices = new FunctionalList<>();
FuncUtils.doTimes(numVertices,
(vertexNo) -> vertices.add(vertexNo));
@@ -119,7 +119,7 @@ public class AdjacencyMap<T> {
/**
* The backing storage of the map
*/
- private IFunctionalMap<T, IFunctionalMap<T, Integer>> adjacencyMap = new FunctionalMap<>();
+ private IMap<T, IMap<T, Integer>> adjacencyMap = new FunctionalMap<>();
/**
* Create a new map from a set of vertices
@@ -127,13 +127,13 @@ public class AdjacencyMap<T> {
* @param vertices
* The set of vertices to create a map from
*/
- public AdjacencyMap(IFunctionalList<T> vertices) {
+ public AdjacencyMap(IList<T> vertices) {
if (vertices == null) {
throw new NullPointerException("Vertices must not be null");
}
vertices.forEach(vertex -> {
- IFunctionalMap<T, Integer> vertexRow = new FunctionalMap<>();
+ IMap<T, Integer> vertexRow = new FunctionalMap<>();
vertices.forEach(targetVertex -> {
vertexRow.put(targetVertex, 0);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
index 0574325..798d20d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
@@ -13,8 +13,8 @@ import java.util.function.BiPredicate;
import bjc.utils.data.IHolder;
import bjc.utils.data.Identity;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
/**
* A directed weighted graph, where the vertices have some arbitrary label
@@ -49,7 +49,7 @@ public class Graph<T> {
/**
* The backing representation of the graph
*/
- private final IFunctionalMap<T, IFunctionalMap<T, Integer>> backingGraph;
+ private final IMap<T, IMap<T, Integer>> backingGraph;
/**
* Create a new graph
@@ -135,7 +135,7 @@ public class Graph<T> {
* The vertex to use as a source
* @return All of the edges with the specified vertex as a source
*/
- public IFunctionalMap<T, Integer> getEdges(T source) {
+ public IMap<T, Integer> getEdges(T source) {
// Can't find edges for a null source
if (source == null) {
throw new NullPointerException("The source cannot be null.");
@@ -230,7 +230,7 @@ public class Graph<T> {
*
* @return A unmodifiable set of all the vertices in the graph.
*/
- public IFunctionalList<T> getVertices() {
+ public IList<T> getVertices() {
return backingGraph.keyList();
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java b/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java
index c020bac..bb147df 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java
@@ -6,7 +6,7 @@ import java.util.List;
import javax.swing.filechooser.FileFilter;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* A file filter based on extensions.
@@ -20,7 +20,7 @@ public class ExtensionFileFilter extends FileFilter {
/**
* The list holding all filtered extensions
*/
- private IFunctionalList<String> extensions;
+ private IList<String> extensions;
/**
* Create a new filter only showing files with the specified
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java
index b22f8f4..a116f15 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java
@@ -9,7 +9,7 @@ import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
import bjc.utils.gui.layout.HLayout;
import bjc.utils.gui.layout.VLayout;
@@ -54,7 +54,7 @@ public class ListParameterPanel<E> extends JPanel {
*/
public ListParameterPanel(Supplier<E> addAction,
Consumer<E> editAction, Consumer<E> removeAction,
- IFunctionalList<E> defaultValues) {
+ IList<E> defaultValues) {
setLayout(new VLayout(2));
JList<E> list;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
index 230b768..a375a98 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
@@ -5,7 +5,7 @@ import java.io.FilenameFilter;
import java.util.List;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* Filter a set of filenames by extension.
@@ -19,7 +19,7 @@ public class ExtensionFileFilter implements FilenameFilter {
/**
* The list of extensions to filter
*/
- private IFunctionalList<String> extensions;
+ private IList<String> extensions;
/**
* Create a new filter only showing files with the specified
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java
new file mode 100644
index 0000000..9d9d1b1
--- /dev/null
+++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/RuleBasedReaderPragmas.java
@@ -0,0 +1,81 @@
+package bjc.utils.parserutils;
+
+import java.util.function.BiConsumer;
+
+import bjc.utils.exceptions.PragmaFormatException;
+import bjc.utils.funcdata.FunctionalStringTokenizer;
+import bjc.utils.funcutils.ListUtils;
+
+/**
+ * Contains factory methods for common pragma types
+ *
+ * @author ben
+ *
+ */
+public class RuleBasedReaderPragmas {
+
+ /**
+ * Creates a pragma that takes any number of arguments and collapses
+ * them all into a single string
+ *
+ * @param <StateType>
+ * The type of state that goes along with this pragma
+ * @param name
+ * The name of this pragma, for error message purpose
+ * @param consumer
+ * The function to invoke with the parsed string
+ * @return A pragma that functions as described above.
+ */
+ public static <StateType>
+ BiConsumer<FunctionalStringTokenizer, StateType>
+ buildStringCollapser(String name,
+ BiConsumer<String, StateType> consumer) {
+ return (tokenizer, state) -> {
+ if (!tokenizer.hasMoreTokens()) {
+ throw new PragmaFormatException("Pragma " + name
+ + " requires one string argument");
+ }
+
+ consumer.accept(ListUtils.collapseTokens(
+ tokenizer.toList((strang) -> strang)), state);
+ };
+ }
+
+ /**
+ * Creates a pragma that takes a single integer argument
+ *
+ * @param <StateType>
+ * The type of state that goes along with this pragma
+ * @param name
+ * The name of this pragma, for error message purpose
+ * @param consumer
+ * The function to invoke with the parsed integer
+ * @return A pragma that functions as described above.
+ */
+ public static <StateType>
+ BiConsumer<FunctionalStringTokenizer, StateType> buildInteger(
+ String name, BiConsumer<Integer, StateType> consumer) {
+ return (tokenizer, state) -> {
+ if (!tokenizer.hasMoreTokens()) {
+ throw new PragmaFormatException("Pragma " + name
+ + " requires one integer argument");
+ }
+
+ String token = tokenizer.nextToken();
+
+ try {
+ consumer.accept(Integer.parseInt(token), state);
+ } catch (NumberFormatException nfex) {
+ PragmaFormatException pfex =
+ new PragmaFormatException("Argument " + token
+ + " to version pragma isn't a valid integer. "
+ + "This pragma requires a integer argument");
+
+ pfex.initCause(nfex);
+
+ throw pfex;
+ }
+ };
+ }
+
+}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java
index 2ea23c6..8118faa 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java
@@ -7,8 +7,8 @@ import java.util.function.Function;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
import bjc.utils.funcutils.StringUtils;
/**
@@ -63,11 +63,11 @@ public class ShuntingYard<TokenType> {
}
private final class TokenShunter implements Consumer<String> {
- private IFunctionalList<TokenType> output;
+ private IList<TokenType> output;
private Deque<String> stack;
private Function<String, TokenType> transform;
- public TokenShunter(IFunctionalList<TokenType> outpt,
+ public TokenShunter(IList<TokenType> outpt,
Deque<String> stack,
Function<String, TokenType> transform) {
this.output = outpt;
@@ -105,7 +105,7 @@ public class ShuntingYard<TokenType> {
/**
* Holds all the shuntable operations
*/
- private IFunctionalMap<String, IPrecedent> operators;
+ private IMap<String, IPrecedent> operators;
/**
* Create a new shunting yard with a default set of operators
@@ -176,8 +176,8 @@ public class ShuntingYard<TokenType> {
* The function to use to transform strings to tokens
* @return A list of tokens in postfix notation
*/
- public IFunctionalList<TokenType> postfix(
- IFunctionalList<String> input,
+ public IList<TokenType> postfix(
+ IList<String> input,
Function<String, TokenType> tokenTransformer) {
if (input == null) {
throw new NullPointerException("Input must not be null");
@@ -185,7 +185,7 @@ public class ShuntingYard<TokenType> {
throw new NullPointerException("Transformer must not be null");
}
- IFunctionalList<TokenType> output = new FunctionalList<>();
+ IList<TokenType> output = new FunctionalList<>();
Deque<String> stack = new LinkedList<>();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java
index 283d16e..c703a72 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java
@@ -9,7 +9,7 @@ import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.data.Pair;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
import bjc.utils.funcdata.ITree;
/**
@@ -34,7 +34,7 @@ public class TreeConstructor {
* @return A AST from the expression
*/
public static <TokenType> ITree<TokenType> constructTree(
- IFunctionalList<TokenType> tokens,
+ IList<TokenType> tokens,
Predicate<TokenType> operatorPredicate) {
return constructTree(tokens, operatorPredicate, (op) -> false,
null);
@@ -65,7 +65,7 @@ public class TreeConstructor {
* works
*/
public static <TokenType> ITree<TokenType> constructTree(
- IFunctionalList<TokenType> tokens,
+ IList<TokenType> tokens,
Predicate<TokenType> operatorPredicate,
Predicate<TokenType> isSpecialOperator,
Function<TokenType, Function<Deque<ITree<TokenType>>, ITree<TokenType>>> handleSpecialOperator) {