diff --git a/src/main/java/org/sablecc/sablecc/GenParser.java b/src/main/java/org/sablecc/sablecc/GenParser.java index 8bb50c4c4f9718e0ce8bbda9c8f6dc172141c2fd..8ba18065d7fb7e3fd72584c0c39cf8b8a65e1a65 100644 --- a/src/main/java/org/sablecc/sablecc/GenParser.java +++ b/src/main/java/org/sablecc/sablecc/GenParser.java @@ -475,7 +475,7 @@ public class GenParser extends DepthFirstAdapter String mostFrequentAction = "ERROR"; int mostFrequentDestination = i; int frequence = 0; - Map map = new TreeMap(IntegerComparator.instance); + Map<Integer, Integer> map = new TreeMap<>(); for(int j = 0; j < Grammar.action_[i].length; j++) { @@ -483,10 +483,10 @@ public class GenParser extends DepthFirstAdapter { if(Grammar.action_[i][j][0] == 1) { - Integer index = new Integer(Grammar.action_[i][j][1]); - Integer count = (Integer) map.get(index); - int freq = count == null ? 0 : count.intValue(); - map.put(index, new Integer(++freq)); + int index = Grammar.action_[i][j][1]; + Integer count = map.get(index); + int freq = count == null ? 0 : count; + map.put(index, ++freq); if(freq > frequence) { frequence = freq; @@ -566,16 +566,16 @@ public class GenParser extends DepthFirstAdapter int mostFrequent = -1; int frequence = 0; - Map map = new TreeMap(IntegerComparator.instance); + Map<Integer, Integer> map = new TreeMap<>(); for(int i = 0; i < Grammar.goto_.length; i++) { if(Grammar.goto_[i][j] != -1) { - Integer index = new Integer(Grammar.goto_[i][j]); - Integer count = (Integer) map.get(index); - int freq = count == null ? 0 : count.intValue(); - map.put(index, new Integer(++freq)); + int index = Grammar.goto_[i][j]; + Integer count = map.get(index); + int freq = count == null ? 0 : count; + map.put(index, ++freq); if(freq > frequence) { frequence = freq; diff --git a/src/main/java/org/sablecc/sablecc/IntegerComparator.java b/src/main/java/org/sablecc/sablecc/IntegerComparator.java deleted file mode 100644 index ca5e9a236334f3f4d6e1bccc43ee555ba73afab1..0000000000000000000000000000000000000000 --- a/src/main/java/org/sablecc/sablecc/IntegerComparator.java +++ /dev/null @@ -1,23 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * This file is part of SableCC. * - * See the file "LICENSE" for copyright information and the * - * terms and conditions for copying, distribution and * - * modification of SableCC. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -package org.sablecc.sablecc; - -import java.util.*; - -public class IntegerComparator implements Comparator -{ - public final static IntegerComparator instance = new IntegerComparator(); - - private IntegerComparator() - {} - - public int compare(Object o1, Object o2) - { - return ((Integer) o1).intValue() - ((Integer) o2).intValue(); - } -} diff --git a/src/main/java/org/sablecc/sablecc/Production.java b/src/main/java/org/sablecc/sablecc/Production.java index 9fb1cc1690ce6d03de3716c2ad3da196373aff43..7457e0a51cf3cc91b3cabfc512c9ed901156edcd 100644 --- a/src/main/java/org/sablecc/sablecc/Production.java +++ b/src/main/java/org/sablecc/sablecc/Production.java @@ -19,14 +19,14 @@ final class Production private final Vector rightside = new Vector(); private static final Vector productions = new Vector(0); - private static TreeMap alternatives_ = new TreeMap(IntegerComparator.instance); + private static TreeMap<Integer, Production[]> alternatives_ = new TreeMap<>(); private static boolean modified_ = true; private static Production[] productions_; public static void reinit() { productions.removeAllElements(); - alternatives_ = new TreeMap(IntegerComparator.instance); + alternatives_ = new TreeMap<>(); productions_ = null; modified_ = true; productions_ = null; @@ -90,10 +90,10 @@ final class Production { if(modified_) { - alternatives_ = new TreeMap(IntegerComparator.instance); + alternatives_ = new TreeMap<>(); } - Production[] result = (Production[]) alternatives_.get(new Integer(nonterminal)); + Production[] result = alternatives_.get(nonterminal); if(result == null) { @@ -112,7 +112,7 @@ final class Production result = new Production[alternatives.size()]; alternatives.copyInto(result); - alternatives_.put(new Integer(nonterminal), result); + alternatives_.put(nonterminal, result); } return result; diff --git a/src/main/java/org/sablecc/sablecc/StringComparator.java b/src/main/java/org/sablecc/sablecc/StringComparator.java deleted file mode 100644 index ab7fb2f5358ca9486d6502ac92ad767e6ec614db..0000000000000000000000000000000000000000 --- a/src/main/java/org/sablecc/sablecc/StringComparator.java +++ /dev/null @@ -1,23 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * This file is part of SableCC. * - * See the file "LICENSE" for copyright information and the * - * terms and conditions for copying, distribution and * - * modification of SableCC. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -package org.sablecc.sablecc; - -import java.util.*; - -public class StringComparator implements Comparator -{ - public final static StringComparator instance = new StringComparator(); - - private StringComparator() - {} - - public int compare(Object o1, Object o2) - { - return ((String) o1).compareTo((String) o2); - } -} diff --git a/src/main/java/org/sablecc/sablecc/Symbol.java b/src/main/java/org/sablecc/sablecc/Symbol.java index bc10c42c7498ac148c0b4d61fdbe97b086c78375..76c8e034fc9d324930b5dcb7d2b1bcc1dce9da04 100644 --- a/src/main/java/org/sablecc/sablecc/Symbol.java +++ b/src/main/java/org/sablecc/sablecc/Symbol.java @@ -14,7 +14,7 @@ final class Symbol implements Comparable { private static Vector terminals; private static Vector nonterminals; - private static TreeMap names; + private static TreeMap<String, Symbol> names; private static boolean modified_ = true; private static Symbol[] symbols_; @@ -59,7 +59,7 @@ final class Symbol implements Comparable { terminals = new Vector(); nonterminals = new Vector(); - names = new TreeMap(StringComparator.instance); + names = new TreeMap<>(); modified_ = true; symbols_ = null; terminals_ = null; @@ -68,7 +68,7 @@ final class Symbol implements Comparable static Symbol symbol(String name) { - return (Symbol) names.get(name); + return names.get(name); } static Symbol symbol(int index, boolean terminal)