This is just weird. The code in bold is a boolean that measures whether or not the String parameter and the String of the method are the same. I have tried using equals, startsWith and contains methods and all keep returning false when its true! Using my debugger, I've confirmed that on the 2nd iteration (when counter = 1) that both value and compare are MAT350. I know it. Eclipse knows it (even assigns both variables id = 37.) So why doesn't java know it?!?!?!? The chunk of code at the bottom is from the Junit test case.
Code:public class CourseList implements DiaryItemList {
private static LinkedNode head;
private class LinkedNode {
private String name;
private String daystimes;
public DiaryItem data;
public LinkedNode link;
public LinkedNode(Course o, LinkedNode link) {
data = o;
this.link = link;
if(o != null){
this.name = o.getName();
this.daystimes = o.getDaysTimes();
}
}
}
public CourseList() {
head = null;
}
public CourseList(String x){
try {
Course temp = new Course();
FileReader from = new FileReader(x);
BufferedReader input = new BufferedReader(from);
String courseinfo = input.readLine();
StringTokenizer cl = new StringTokenizer(courseinfo);
String coname = cl.nextToken();
temp.setName(coname);
temp.setSection(cl.nextToken());
String startT = cl.nextToken();
startT = startT.replaceAll(":","");
startT.trim();
int starter = temp.toMilitaryTime(startT);
if(starter >= 1200){
startT = "" + startT + "PM";
}
else {
startT = "" + startT + "AM";
}
temp.setStartTime(starter);
String endT = cl.nextToken();
endT = endT.replaceAll(":","");
endT.trim();
int ender =temp.toMilitaryTime(endT);
if(ender >= 1200){
endT = "" + endT + "PM";
}
else {
endT = "" + endT + "AM";
}
temp.setEndTime(ender);
String dayconvertor = cl.nextToken();
dayconvertor = dayconvertor.replace('H','Y');
dayconvertor = dayconvertor.replace('F','Z');
temp.setDays(dayconvertor);
courseinfo = input.readLine();
insertAtFront(temp);
System.out.print(temp);
}
catch (FileNotFoundException e) {
System.out.println("File classy.txt not found");
}
catch(IOException e) {
System.err.println("Exception in reading from file");
}
}
public DiaryItem getItemAt(int index) {
LinkedNode p = head;
if(p == null)
return null;
int counter = 0;
while (p != null && counter != index){
p = p.link;
counter++;
}
if(counter == index){
return (DiaryItem) p.data;
}
return null;
}
public int indexOf(String value) {
LinkedNode current = head;
LinkedNode previous = null;
String compare = current.data.getName();
[B][U]boolean match = compare.startsWith(value);[/U][/B]
int counter = 0;
while(current != null && match == false) {
previous = current;
current = current.link;
compare = current.data.getName();
counter++;
}
if(current != null && match == true) {
return counter;
}
return counter;
}
public void testIndexOf() {
String Beta = B.getName(); // String = "MAT350"
myList.addInNameOrder(A);
myList.addInNameOrder(B);
myList.addInNameOrder(E);
int b = myList.indexOf(Beta);
assertEquals("index of b should equal ", 1, b);

