Skip to content
Snippets Groups Projects
Commit 7fb93897 authored by dgelessus's avatar dgelessus
Browse files

Remove unnecessary custom comparators

TreeMap already works natively with String and Integer objects, because
they implement Comparable.
parent 4bc01e93
No related branches found
No related tags found
No related merge requests found
...@@ -475,7 +475,7 @@ public class GenParser extends DepthFirstAdapter ...@@ -475,7 +475,7 @@ public class GenParser extends DepthFirstAdapter
String mostFrequentAction = "ERROR"; String mostFrequentAction = "ERROR";
int mostFrequentDestination = i; int mostFrequentDestination = i;
int frequence = 0; 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++) for(int j = 0; j < Grammar.action_[i].length; j++)
{ {
...@@ -483,10 +483,10 @@ public class GenParser extends DepthFirstAdapter ...@@ -483,10 +483,10 @@ public class GenParser extends DepthFirstAdapter
{ {
if(Grammar.action_[i][j][0] == 1) if(Grammar.action_[i][j][0] == 1)
{ {
Integer index = new Integer(Grammar.action_[i][j][1]); int index = Grammar.action_[i][j][1];
Integer count = (Integer) map.get(index); Integer count = map.get(index);
int freq = count == null ? 0 : count.intValue(); int freq = count == null ? 0 : count;
map.put(index, new Integer(++freq)); map.put(index, ++freq);
if(freq > frequence) if(freq > frequence)
{ {
frequence = freq; frequence = freq;
...@@ -566,16 +566,16 @@ public class GenParser extends DepthFirstAdapter ...@@ -566,16 +566,16 @@ public class GenParser extends DepthFirstAdapter
int mostFrequent = -1; int mostFrequent = -1;
int frequence = 0; int frequence = 0;
Map map = new TreeMap(IntegerComparator.instance); Map<Integer, Integer> map = new TreeMap<>();
for(int i = 0; i < Grammar.goto_.length; i++) for(int i = 0; i < Grammar.goto_.length; i++)
{ {
if(Grammar.goto_[i][j] != -1) if(Grammar.goto_[i][j] != -1)
{ {
Integer index = new Integer(Grammar.goto_[i][j]); int index = Grammar.goto_[i][j];
Integer count = (Integer) map.get(index); Integer count = map.get(index);
int freq = count == null ? 0 : count.intValue(); int freq = count == null ? 0 : count;
map.put(index, new Integer(++freq)); map.put(index, ++freq);
if(freq > frequence) if(freq > frequence)
{ {
frequence = freq; frequence = freq;
......
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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();
}
}
...@@ -19,14 +19,14 @@ final class Production ...@@ -19,14 +19,14 @@ final class Production
private final Vector rightside = new Vector(); private final Vector rightside = new Vector();
private static final Vector productions = new Vector(0); 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 boolean modified_ = true;
private static Production[] productions_; private static Production[] productions_;
public static void reinit() public static void reinit()
{ {
productions.removeAllElements(); productions.removeAllElements();
alternatives_ = new TreeMap(IntegerComparator.instance); alternatives_ = new TreeMap<>();
productions_ = null; productions_ = null;
modified_ = true; modified_ = true;
productions_ = null; productions_ = null;
...@@ -90,10 +90,10 @@ final class Production ...@@ -90,10 +90,10 @@ final class Production
{ {
if(modified_) 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) if(result == null)
{ {
...@@ -112,7 +112,7 @@ final class Production ...@@ -112,7 +112,7 @@ final class Production
result = new Production[alternatives.size()]; result = new Production[alternatives.size()];
alternatives.copyInto(result); alternatives.copyInto(result);
alternatives_.put(new Integer(nonterminal), result); alternatives_.put(nonterminal, result);
} }
return result; return result;
......
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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);
}
}
...@@ -14,7 +14,7 @@ final class Symbol implements Comparable ...@@ -14,7 +14,7 @@ final class Symbol implements Comparable
{ {
private static Vector terminals; private static Vector terminals;
private static Vector nonterminals; private static Vector nonterminals;
private static TreeMap names; private static TreeMap<String, Symbol> names;
private static boolean modified_ = true; private static boolean modified_ = true;
private static Symbol[] symbols_; private static Symbol[] symbols_;
...@@ -59,7 +59,7 @@ final class Symbol implements Comparable ...@@ -59,7 +59,7 @@ final class Symbol implements Comparable
{ {
terminals = new Vector(); terminals = new Vector();
nonterminals = new Vector(); nonterminals = new Vector();
names = new TreeMap(StringComparator.instance); names = new TreeMap<>();
modified_ = true; modified_ = true;
symbols_ = null; symbols_ = null;
terminals_ = null; terminals_ = null;
...@@ -68,7 +68,7 @@ final class Symbol implements Comparable ...@@ -68,7 +68,7 @@ final class Symbol implements Comparable
static Symbol symbol(String name) static Symbol symbol(String name)
{ {
return (Symbol) names.get(name); return names.get(name);
} }
static Symbol symbol(int index, boolean terminal) static Symbol symbol(int index, boolean terminal)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment