From d9df565a4298a45107ea69c86a7da18e73290828 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 27 Jul 2017 18:19:12 -0700 Subject: [PATCH] Switch all uses of *List, *Map to just List and Map. --- src/org/nwapw/abacus/lexing/Lexer.java | 4 ++-- src/org/nwapw/abacus/lexing/pattern/Pattern.java | 3 ++- .../nwapw/abacus/lexing/pattern/PatternNode.java | 3 ++- src/org/nwapw/abacus/plugin/Plugin.java | 5 +++-- src/org/nwapw/abacus/plugin/PluginManager.java | 16 ++++++++-------- src/org/nwapw/abacus/tree/FunctionNode.java | 3 ++- src/org/nwapw/abacus/tree/TreeBuilder.java | 12 ++++++------ .../nwapw/abacus/window/HistoryTableModel.java | 3 ++- 8 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/org/nwapw/abacus/lexing/Lexer.java b/src/org/nwapw/abacus/lexing/Lexer.java index 213330a..5839801 100644 --- a/src/org/nwapw/abacus/lexing/Lexer.java +++ b/src/org/nwapw/abacus/lexing/Lexer.java @@ -54,7 +54,7 @@ public class Lexer { /** * The registered patterns. */ - private HashMap, Pattern> patterns; + private Map, Pattern> patterns; /** * Creates a new lexer with no registered patterns. @@ -127,7 +127,7 @@ public class Lexer { * @param compare the comparator used to sort matches by their IDs. * @return the resulting list of matches, in order, or null on error. */ - public ArrayList> lexAll(String from, int startAt, Comparator compare){ + public List> lexAll(String from, int startAt, Comparator compare){ int index = startAt; ArrayList> matches = new ArrayList<>(); Match lastMatch = null; diff --git a/src/org/nwapw/abacus/lexing/pattern/Pattern.java b/src/org/nwapw/abacus/lexing/pattern/Pattern.java index a5ae8d9..29c3513 100644 --- a/src/org/nwapw/abacus/lexing/pattern/Pattern.java +++ b/src/org/nwapw/abacus/lexing/pattern/Pattern.java @@ -2,6 +2,7 @@ package org.nwapw.abacus.lexing.pattern; import java.util.Collection; import java.util.HashMap; +import java.util.Map; import java.util.Stack; import java.util.function.Function; @@ -32,7 +33,7 @@ public class Pattern { * A map of regex operator to functions that modify a PatternChain * with the appropriate operation. */ - private HashMap, PatternChain>> operations = + private Map, PatternChain>> operations = new HashMap, PatternChain>>() {{ put('+', Pattern.this::transformPlus); put('*', Pattern.this::transformStar); diff --git a/src/org/nwapw/abacus/lexing/pattern/PatternNode.java b/src/org/nwapw/abacus/lexing/pattern/PatternNode.java index 51208db..4108ccc 100644 --- a/src/org/nwapw/abacus/lexing/pattern/PatternNode.java +++ b/src/org/nwapw/abacus/lexing/pattern/PatternNode.java @@ -3,6 +3,7 @@ package org.nwapw.abacus.lexing.pattern; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.Set; /** * A base class for a pattern node. Provides all functions @@ -16,7 +17,7 @@ public class PatternNode { * The set of states to which the lexer should continue * should this node be correctly matched. */ - protected HashSet> outputStates; + protected Set> outputStates; /** * Creates a new pattern node. diff --git a/src/org/nwapw/abacus/plugin/Plugin.java b/src/org/nwapw/abacus/plugin/Plugin.java index 9e87be2..1f57b1d 100644 --- a/src/org/nwapw/abacus/plugin/Plugin.java +++ b/src/org/nwapw/abacus/plugin/Plugin.java @@ -4,6 +4,7 @@ import org.nwapw.abacus.function.Function; import org.nwapw.abacus.function.Operator; import java.util.HashMap; +import java.util.Map; import java.util.Set; /** @@ -18,11 +19,11 @@ public abstract class Plugin { /** * A hash map of functions mapped to their string names. */ - private HashMap functions; + private Map functions; /** * A hash map of operators mapped to their string names. */ - private HashMap operators; + private Map operators; /** * The plugin manager in which to search for functions * not inside this package, diff --git a/src/org/nwapw/abacus/plugin/PluginManager.java b/src/org/nwapw/abacus/plugin/PluginManager.java index f654332..ff3b784 100644 --- a/src/org/nwapw/abacus/plugin/PluginManager.java +++ b/src/org/nwapw/abacus/plugin/PluginManager.java @@ -15,29 +15,29 @@ public class PluginManager { /** * A list of loaded plugins. */ - private ArrayList plugins; + private List plugins; /** * List of functions that have been cached, * that is, found in a plugin and returned. */ - private HashMap cachedFunctions; + private Map cachedFunctions; /** * List of operators tha have been cached, * that is, found in a plugin and returned. */ - private HashMap cachedOperators; + private Map cachedOperators; /** * List of all functions loaded by the plugins. */ - private HashSet allFunctions; + private Set allFunctions; /** * List of all operators loaded by the plugins. */ - private HashSet allOperators; + private Set allOperators; /** * The list of plugin listeners attached to this instance. */ - private HashSet listeners; + private Set listeners; /** * Creates a new plugin manager. @@ -155,7 +155,7 @@ public class PluginManager { * Gets all the functions loaded by the Plugin Manager. * @return the set of all functions that were loaded. */ - public HashSet getAllFunctions() { + public Set getAllFunctions() { return allFunctions; } @@ -163,7 +163,7 @@ public class PluginManager { * Gets all the operators loaded by the Plugin Manager. * @return the set of all operators that were loaded. */ - public HashSet getAllOperators() { + public Set getAllOperators() { return allOperators; } diff --git a/src/org/nwapw/abacus/tree/FunctionNode.java b/src/org/nwapw/abacus/tree/FunctionNode.java index 6fbd626..13d7a8a 100644 --- a/src/org/nwapw/abacus/tree/FunctionNode.java +++ b/src/org/nwapw/abacus/tree/FunctionNode.java @@ -1,6 +1,7 @@ package org.nwapw.abacus.tree; import java.util.ArrayList; +import java.util.List; /** * A node that represents a function call. @@ -14,7 +15,7 @@ public class FunctionNode extends TreeNode { /** * The list of arguments to the function. */ - private ArrayList children; + private List children; /** * Creates a function node with no function. diff --git a/src/org/nwapw/abacus/tree/TreeBuilder.java b/src/org/nwapw/abacus/tree/TreeBuilder.java index 4eb9741..9c57741 100644 --- a/src/org/nwapw/abacus/tree/TreeBuilder.java +++ b/src/org/nwapw/abacus/tree/TreeBuilder.java @@ -19,11 +19,11 @@ public class TreeBuilder { /** * The map of operator precedences. */ - private HashMap precedenceMap; + private Map precedenceMap; /** * The map of operator associativity. */ - private HashMap associativityMap; + private Map associativityMap; /** * Comparator used to sort token types. @@ -70,7 +70,7 @@ public class TreeBuilder { * @param string the string to tokenize. * @return the list of tokens produced. */ - public ArrayList> tokenize(String string){ + public List> tokenize(String string){ return lexer.lexAll(string, 0, tokenSorter); } @@ -80,7 +80,7 @@ public class TreeBuilder { * @param from the tokens to be rearranged. * @return the resulting list of rearranged tokens. */ - public ArrayList> intoPostfix(String source, ArrayList> from){ + public List> intoPostfix(String source, List> from){ ArrayList> output = new ArrayList<>(); Stack> tokenStack = new Stack<>(); while(!from.isEmpty()){ @@ -138,7 +138,7 @@ public class TreeBuilder { * @param matches the list of tokens from the source string. * @return the construct tree expression. */ - public TreeNode fromStringRecursive(String source, ArrayList> matches){ + public TreeNode fromStringRecursive(String source, List> matches){ if(matches.size() == 0) return null; Match match = matches.remove(0); TokenType matchType = match.getType(); @@ -170,7 +170,7 @@ public class TreeBuilder { * @return the resulting tree. */ public TreeNode fromString(String string){ - ArrayList> matches = tokenize(string); + List> matches = tokenize(string); if(matches == null) return null; matches.removeIf(m -> m.getType() == TokenType.WHITESPACE); matches = intoPostfix(string, matches); diff --git a/src/org/nwapw/abacus/window/HistoryTableModel.java b/src/org/nwapw/abacus/window/HistoryTableModel.java index f488faf..323e209 100644 --- a/src/org/nwapw/abacus/window/HistoryTableModel.java +++ b/src/org/nwapw/abacus/window/HistoryTableModel.java @@ -6,6 +6,7 @@ import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; import java.util.ArrayList; +import java.util.List; /** * A table model to store data about the history of inputs @@ -57,7 +58,7 @@ public class HistoryTableModel extends AbstractTableModel { /** * The list of entries. */ - ArrayList entries; + List entries; /** * Creates a new empty history table model