From 674d9769821775484fe6913b93c650189fbedfed Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sat, 25 Mar 2017 14:07:24 -0400 Subject: General cleanup --- .../src/main/java/bjc/utils/esodata/Tape.java | 3 +- .../main/java/bjc/utils/funcutils/StringUtils.java | 9 ++--- .../main/java/bjc/utils/gen/WeightedGrammar.java | 9 +++-- .../src/main/java/bjc/utils/graph/Graph.java | 32 ++++++++-------- .../java/bjc/utils/parserutils/ShuntingYard.java | 43 +++++++++++++--------- .../utils/parserutils/delims/DelimiterGroup.java | 3 -- .../utils/parserutils/delims/StringDelimiter.java | 2 +- .../bjc/utils/parserutils/pratt/PrattParser.java | 2 - 8 files changed, 54 insertions(+), 49 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils') diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java index 3b3a9a7..58efc80 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java @@ -7,8 +7,9 @@ package bjc.utils.esodata; * only affect elements at that cursor. The size of the array is theoretically * unbounded to the right, but in practice bounded by available memory. * - * @param T + * @param * The element type of the tape. + * * @author bjculkin */ public interface Tape { diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java index 51be875..a35253a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -24,8 +24,7 @@ public class StringUtils { public static boolean containsOnly(String input, String regex) { if (input == null) throw new NullPointerException("Input must not be null"); - else if (regex == null) - throw new NullPointerException("Regex must not be null"); + else if (regex == null) throw new NullPointerException("Regex must not be null"); /* * This regular expression is fairly simple. @@ -78,7 +77,7 @@ public class StringUtils { * @param comma * The string to use as a comma * - * @return + * @return The sequence as an English list. */ public static String toEnglishList(Object[] objects, String join, String comma) { if (objects == null) { @@ -141,7 +140,7 @@ public class StringUtils { * The string to use for separating the last element from * the rest. * - * @return + * @return The sequence as an English list. */ public static String toEnglishList(Object[] objects, String join) { return toEnglishList(objects, join, ","); @@ -155,7 +154,7 @@ public class StringUtils { * @param and * Whether to use 'and' or 'or'. * - * @return + * @return The sequence as an English list. */ public static String toEnglishList(Object[] objects, boolean and) { if (and) { 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 6179850..15d7753 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java @@ -242,19 +242,22 @@ public class WeightedGrammar { } /** - * Generate a generic sentance from a initial rule. + * Generate a generic sentence from a initial rule. * * @param * The type of the transformed output * - * @param initRule + * @param initRules * The initial rule to start with. + * * @param tokenTransformer * The function to transform grammar output into * something. + * * @param spacer * The spacer element to add in between output tokens. - * @return A randomly generated sentance from the specified initial + * + * @return A randomly generated sentence from the specified initial * rule. */ public IList generateGenericValues(E initRules, Function tokenTransformer, T spacer) { 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 003b996..d033f04 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java +++ b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java @@ -72,12 +72,12 @@ public class Graph { */ public void addEdge(T source, T target, int distance, boolean directed) { // Can't add edges with a null source or target - if(source == null) + if (source == null) throw new NullPointerException("The source vertex cannot be null"); - else if(target == null) throw new NullPointerException("The target vertex cannot be null"); + else if (target == null) throw new NullPointerException("The target vertex cannot be null"); // Initialize adjacency list for vertices if necessary - if(!backing.containsKey(source)) { + if (!backing.containsKey(source)) { backing.put(source, new FunctionalMap()); } @@ -85,8 +85,8 @@ public class Graph { backing.get(source).put(target, distance); // Handle possible directed edges - if(!directed) { - if(!backing.containsKey(target)) { + if (!directed) { + if (!backing.containsKey(target)) { backing.put(target, new FunctionalMap()); } @@ -106,12 +106,12 @@ public class Graph { * The action to execute for matching edges */ public void forAllEdgesMatchingAt(T source, BiPredicate matcher, BiConsumer action) { - if(matcher == null) + if (matcher == null) throw new NullPointerException("Matcher must not be null"); - else if(action == null) throw new NullPointerException("Action must not be null"); + else if (action == null) throw new NullPointerException("Action must not be null"); getEdges(source).forEach((target, weight) -> { - if(matcher.test(target, weight)) { + if (matcher.test(target, weight)) { action.accept(target, weight); } }); @@ -126,9 +126,9 @@ public class Graph { */ public IMap getEdges(T source) { // Can't find edges for a null source - if(source == null) + if (source == null) throw new NullPointerException("The source cannot be null."); - else if(!backing.containsKey(source)) + else if (!backing.containsKey(source)) throw new IllegalArgumentException("Vertex " + source + " is not in graph"); return backing.get(source); @@ -168,7 +168,7 @@ public class Graph { visited.add(source.getValue()); // Make sure we visit all the nodes - while(visited.size() != getVertexCount()) { + while (visited.size() != getVertexCount()) { // Grab all edges adjacent to the provided edge forAllEdgesMatchingAt(source.getValue(), (target, weight) -> { @@ -185,7 +185,7 @@ public class Graph { // Only consider edges where we haven't visited the // target of // the edge - while(visited.contains(minimum.getValue())) { + while (visited.contains(minimum.getValue().getTarget())) { minimum.transform((edge) -> available.poll()); } @@ -230,15 +230,15 @@ public class Graph { */ public void removeEdge(T source, T target) { // Can't remove things w/ null vertices - if(source == null) + if (source == null) throw new NullPointerException("The source vertex cannot be null"); - else if(target == null) throw new NullPointerException("The target vertex cannot be null"); + else if (target == null) throw new NullPointerException("The target vertex cannot be null"); // Can't remove if one vertice doesn't exists - if(!backing.containsKey(source)) + if (!backing.containsKey(source)) throw new NoSuchElementException("vertex " + source + " does not exist."); - if(!backing.containsKey(target)) + if (!backing.containsKey(target)) throw new NoSuchElementException("vertex " + target + " does not exist."); backing.get(source).remove(target); 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 2a0bdff..7fc3688 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -72,26 +72,26 @@ public class ShuntingYard { @Override public void accept(String token) { // Handle operators - if(operators.containsKey(token)) { + if (operators.containsKey(token)) { // Pop operators while there isn't a higher // precedence one - while(!stack.isEmpty() && isHigherPrec(token, stack.peek())) { + while (!stack.isEmpty() && isHigherPrec(token, stack.peek())) { output.add(transformer.apply(stack.pop())); } // Put this operator onto the stack stack.push(token); - } else if(StringUtils.containsOnly(token, "\\(")) { + } else if (StringUtils.containsOnly(token, "\\(")) { // Handle groups of parenthesis for multiple // nesting levels stack.push(token); - } else if(StringUtils.containsOnly(token, "\\)")) { + } else if (StringUtils.containsOnly(token, "\\)")) { // Handle groups of parenthesis for multiple // nesting levels String swappedToken = token.replace(')', '('); // Remove tokens up to a matching parenthesis - while(!stack.peek().equals(swappedToken)) { + while (!stack.peek().equals(swappedToken)) { output.add(transformer.apply(stack.pop())); } @@ -119,7 +119,7 @@ public class ShuntingYard { operators = new FunctionalMap<>(); // Add basic operators if we're configured to do so - if(configureBasics) { + if (configureBasics) { operators.put("+", Operator.ADD); operators.put("-", Operator.SUBTRACT); operators.put("*", Operator.MULTIPLY); @@ -130,13 +130,15 @@ public class ShuntingYard { /** * Add an operator to the list of shuntable operators * - * @param operatorToken + * @param operator * The token representing the operator * @param precedence * The precedence of the operator to add */ public void addOp(String operator, int precedence) { - // Create the precedence marker + /* + * Create the precedence marker + */ IPrecedent prec = IPrecedent.newSimplePrecedent(precedence); this.addOp(operator, prec); @@ -145,18 +147,23 @@ public class ShuntingYard { /** * Add an operator to the list of shuntable operators * - * @param operatorToken + * @param operator * The token representing the operator + * * @param precedence * The precedence of the operator */ public void addOp(String operator, IPrecedent precedence) { - // Complain about trying to add an incorrect operator - if(operator == null) + /* + * Complain about trying to add an incorrect operator + */ + if (operator == null) throw new NullPointerException("Operator must not be null"); - else if(precedence == null) throw new NullPointerException("Precedence must not be null"); + else if (precedence == null) throw new NullPointerException("Precedence must not be null"); - // Add the operator to the ones we handle + /* + * Add the operator to the ones we handle + */ operators.put(operator, precedence); } @@ -165,7 +172,7 @@ public class ShuntingYard { boolean exists = operators.containsKey(right); // If it doesn't, the left is higher precedence. - if(!exists) return false; + if (!exists) return false; // Get the precedence of operators int rightPrecedence = operators.get(right).getPrecedence(); @@ -186,9 +193,9 @@ public class ShuntingYard { */ public IList postfix(IList input, Function transformer) { // Check our input - if(input == null) + if (input == null) throw new NullPointerException("Input must not be null"); - else if(transformer == null) throw new NullPointerException("Transformer must not be null"); + else if (transformer == null) throw new NullPointerException("Transformer must not be null"); // Here's what we're handing back IList output = new FunctionalList<>(); @@ -210,13 +217,13 @@ public class ShuntingYard { /** * Remove an operator from the list of shuntable operators * - * @param token + * @param operator * The token representing the operator. If null, remove * all operators */ public void removeOp(String operator) { // Check if we want to remove all operators - if(operator == null) { + if (operator == null) { operators = new FunctionalMap<>(); } else { operators.remove(operator); diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java index 652b8f6..db6ae8c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java @@ -431,9 +431,6 @@ public class DelimiterGroup { * * @param priority * The priority of this sub-group. - * - * @param contained - * Any sub-groups to enclose in this group. */ public void addSubgroup(T subgroup, int priority) { if(subgroup == null) { diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java index cbf99ee..6db1c98 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java @@ -12,7 +12,7 @@ public class StringDelimiter extends SequenceDelimiter { /** * Override of - * {@link SequenceDelimiter#delimitSequence(Object, Object, Object...)} + * {@link SequenceDelimiter#delimitSequence(SequenceCharacteristics, Object...)} * for ease of use for strings. * * @param seq diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java index e8543dc..20572e8 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java @@ -36,8 +36,6 @@ public class PrattParser { /** * Create a new Pratt parser. * - * @param terminal - * The terminal symbol. */ public PrattParser() { leftCommands = new HashMap<>(); -- cgit v1.2.3