L
Luc The Perverse
Sorry if I am asking a dumb question - but I am having a problem, an usual
warning is coming up when I compile my simple program.
When I compile
....\Desktop>javac edit_dist.java
Note: edit_dist.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Recompiling
E:\Documents and Settings\Luc\Desktop>javac edit_dist.java -Xlint:unchecked
edit_dist.java:41: warning: [unchecked] unchecked call to put(K,V) as a
member of the raw type java.util.TreeMap
mtm.put(myCurKey, new Integer(min));
^
Here is my code
import java.util.*;
import java.lang.*;
import java.math.*;
public class edit_dist{
TreeMap mtm = null;
edit_dist(){
mtm = new TreeMap<String, Integer>();
}
public static int naive_editDistance(String Source, String Dest){
if(Source.equals("") || Dest.equals(""))
return Dest.length() + Source.length();
if(Source.charAt(0) == Dest.charAt(0))
return naive_editDistance(Source.substring(1), Dest.substring(1));
int min = 536870911; //arbitrarily large number above max length of
string
for(int i=0;i<2;i++)
for(int j=(i!=0?0:1);j<2;j++)
min = Math.min (min,
1 + naive_editDistance(Source.substring(i),
Dest.substring(j)));
return min; //
}
private static String makeLen(String in, int OSL){
int a = OSL - in.length();
for(int i=0;i<a;i++)
in+=(char) 1;
return in;
}
int memoize_editDistance(String Source, String Dest, int OSL){
if(Source.equals("") || Dest.equals(""))
return Dest.length() + Source.length();
String myCurKey = makeLen(Source, OSL) + Dest;
if(mtm.containsValue(myCurKey))
return ((Integer)mtm.get(myCurKey)).intValue();
if(Source.charAt(0) == Dest.charAt(0))
return naive_editDistance(Source.substring(1), Dest.substring(1));
int min = 536870911; //arbitrarily large number above max length of
string
for(int i=0;i<2;i++)
for(int j=(i!=0?0:1);j<2;j++)
min = Math.min (min,
1 + naive_editDistance(Source.substring(i),
Dest.substring(j)));
mtm.put(myCurKey, new Integer(min));
return min; //
}
public static int memoize_editDistance(String Source, String Dest){
return (new edit_dist()).memoize_editDistance(Source, Dest,
Source.length());
}
public static void main(String[] xs){
String[] x = {"accept", "allow", "ask", "believe", "borrow", "break",
"bring",
"buy", "can/beable", "cancel", "change", "clean", "comb", "complain",
"cough", "count", "cut"};
int[] res = {0, 5, 5, 6, 6, 5, 6, 6, 8, 4, 6, 4, 5, 7, 5, 4, 4, 5, 0, 4,
6, 4, 5,
5, 5, 9, 5, 6, 4, 5, 7, 5, 5, 5, 5, 4, 0, 7, 6, 4, 5, 3, 9, 5, 5, 5, 4, 7,
5, 5, 3, 6, 6, 7, 0,
6, 5, 5, 6, 8, 6, 6, 5, 7, 8, 7, 7, 7, 6, 4, 6, 6, 0, 4, 4, 5, 9, 6, 6, 6,
5, 7, 5, 5, 6, 5, 5,
4, 5, 4, 0, 3, 4, 8, 6, 6, 3, 5, 7, 5, 5, 5, 6, 5, 5, 5, 4, 3, 0, 4, 9, 6,
4, 5, 5, 7, 5, 4, 5,
6, 5, 3, 6, 5, 4, 4, 0, 9, 6, 6, 5, 4, 8, 4, 4, 2, 8, 9, 9, 8, 9, 8, 9, 9,
0, 5, 7, 7, 8, 8, 9,
9, 9, 4, 5, 5, 6, 6, 6, 6, 6, 5, 0, 3, 5, 5, 7, 5, 5, 5, 6, 6, 5, 6, 6, 6,
4, 6, 7, 3, 0, 4, 5,
7, 4, 4, 5, 4, 4, 5, 5, 6, 3, 5, 5, 7, 5, 4, 0, 4, 5, 4, 4, 4, 5, 5, 4, 7,
5, 5, 5, 4, 8, 5, 5,
4, 0, 5, 3, 3, 3, 7, 7, 7, 8, 7, 7, 7, 8, 8, 7, 7, 5, 5, 0, 6, 6, 7, 5, 5,
5, 7, 5, 5, 5, 4, 9,
5, 4, 4, 3, 6, 0, 2, 3, 4, 5, 5, 7, 5, 5, 4, 4, 9, 5, 4, 4, 3, 6, 2, 0, 2,
4, 5, 3, 7, 6, 5, 5,
2, 9, 5, 5, 4, 3, 7, 3, 2, 0}; //results from naive_editDistance assumed
correct
int nc = 0;
int lv = 0;
for(String C : x)
for(String Y : x)
if((lv=memoize_editDistance(C, Y))!=res[nc++])
System.out.println("Failed on " + C +" to " + Y + " got "
+lv + " expecting " + res[nc-1]);
}
}
warning is coming up when I compile my simple program.
When I compile
....\Desktop>javac edit_dist.java
Note: edit_dist.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Recompiling
E:\Documents and Settings\Luc\Desktop>javac edit_dist.java -Xlint:unchecked
edit_dist.java:41: warning: [unchecked] unchecked call to put(K,V) as a
member of the raw type java.util.TreeMap
mtm.put(myCurKey, new Integer(min));
^
Here is my code
import java.util.*;
import java.lang.*;
import java.math.*;
public class edit_dist{
TreeMap mtm = null;
edit_dist(){
mtm = new TreeMap<String, Integer>();
}
public static int naive_editDistance(String Source, String Dest){
if(Source.equals("") || Dest.equals(""))
return Dest.length() + Source.length();
if(Source.charAt(0) == Dest.charAt(0))
return naive_editDistance(Source.substring(1), Dest.substring(1));
int min = 536870911; //arbitrarily large number above max length of
string
for(int i=0;i<2;i++)
for(int j=(i!=0?0:1);j<2;j++)
min = Math.min (min,
1 + naive_editDistance(Source.substring(i),
Dest.substring(j)));
return min; //
}
private static String makeLen(String in, int OSL){
int a = OSL - in.length();
for(int i=0;i<a;i++)
in+=(char) 1;
return in;
}
int memoize_editDistance(String Source, String Dest, int OSL){
if(Source.equals("") || Dest.equals(""))
return Dest.length() + Source.length();
String myCurKey = makeLen(Source, OSL) + Dest;
if(mtm.containsValue(myCurKey))
return ((Integer)mtm.get(myCurKey)).intValue();
if(Source.charAt(0) == Dest.charAt(0))
return naive_editDistance(Source.substring(1), Dest.substring(1));
int min = 536870911; //arbitrarily large number above max length of
string
for(int i=0;i<2;i++)
for(int j=(i!=0?0:1);j<2;j++)
min = Math.min (min,
1 + naive_editDistance(Source.substring(i),
Dest.substring(j)));
mtm.put(myCurKey, new Integer(min));
return min; //
}
public static int memoize_editDistance(String Source, String Dest){
return (new edit_dist()).memoize_editDistance(Source, Dest,
Source.length());
}
public static void main(String[] xs){
String[] x = {"accept", "allow", "ask", "believe", "borrow", "break",
"bring",
"buy", "can/beable", "cancel", "change", "clean", "comb", "complain",
"cough", "count", "cut"};
int[] res = {0, 5, 5, 6, 6, 5, 6, 6, 8, 4, 6, 4, 5, 7, 5, 4, 4, 5, 0, 4,
6, 4, 5,
5, 5, 9, 5, 6, 4, 5, 7, 5, 5, 5, 5, 4, 0, 7, 6, 4, 5, 3, 9, 5, 5, 5, 4, 7,
5, 5, 3, 6, 6, 7, 0,
6, 5, 5, 6, 8, 6, 6, 5, 7, 8, 7, 7, 7, 6, 4, 6, 6, 0, 4, 4, 5, 9, 6, 6, 6,
5, 7, 5, 5, 6, 5, 5,
4, 5, 4, 0, 3, 4, 8, 6, 6, 3, 5, 7, 5, 5, 5, 6, 5, 5, 5, 4, 3, 0, 4, 9, 6,
4, 5, 5, 7, 5, 4, 5,
6, 5, 3, 6, 5, 4, 4, 0, 9, 6, 6, 5, 4, 8, 4, 4, 2, 8, 9, 9, 8, 9, 8, 9, 9,
0, 5, 7, 7, 8, 8, 9,
9, 9, 4, 5, 5, 6, 6, 6, 6, 6, 5, 0, 3, 5, 5, 7, 5, 5, 5, 6, 6, 5, 6, 6, 6,
4, 6, 7, 3, 0, 4, 5,
7, 4, 4, 5, 4, 4, 5, 5, 6, 3, 5, 5, 7, 5, 4, 0, 4, 5, 4, 4, 4, 5, 5, 4, 7,
5, 5, 5, 4, 8, 5, 5,
4, 0, 5, 3, 3, 3, 7, 7, 7, 8, 7, 7, 7, 8, 8, 7, 7, 5, 5, 0, 6, 6, 7, 5, 5,
5, 7, 5, 5, 5, 4, 9,
5, 4, 4, 3, 6, 0, 2, 3, 4, 5, 5, 7, 5, 5, 4, 4, 9, 5, 4, 4, 3, 6, 2, 0, 2,
4, 5, 3, 7, 6, 5, 5,
2, 9, 5, 5, 4, 3, 7, 3, 2, 0}; //results from naive_editDistance assumed
correct
int nc = 0;
int lv = 0;
for(String C : x)
for(String Y : x)
if((lv=memoize_editDistance(C, Y))!=res[nc++])
System.out.println("Failed on " + C +" to " + Y + " got "
+lv + " expecting " + res[nc-1]);
}
}