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
Branches
Tags
No related merge requests found
......@@ -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;
......
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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
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;
......
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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
{
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment