Hello friends,
As a kind of an amateur, I have some difficulties in understanding what exactly happens when the code below, which is the main method Test.Case.java, is executed. Is there any friendly soul that could help me understand the code? And if I'm in the wrong forum, please do excuse me.
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class TestCase {
SomeHelperClass someHelperClass = new SomeHelperClass();
public static void main(String[] args) {
TestCase testCase = new TestCase();
try {
testCase.getAll();
} catch (Exception e) {
} finally {
testCase = null;
}
}
public void getAll() throws SystemException {
List list = null;
list = someHelperClass.getFigures();
if (list.get(0) != null) {
if (list.get(0) instanceof Triangle) {
Triangle t1 = (Triangle) list.get(0);
t1.setBase(1);
t1.setHeight(1);
} else if (list.get(0) instanceof Square) {
Square s1 = (Square) list.get(0);
s1.setBase(1);
}
} else {
throw new SystemException("Empty list");
}
FigureComparator comparator = new FigureComparator();
sortList(list, 1, comparator);
Iterator iter = list.iterator();
while (iter.hasNext()) {
Figure figure = (Figure) iter.next();
figure.print();
}
}
public List sortList(List list, int sortChoise, Comparator comparator) {
switch (sortChoise) {
case 1:
someHelperClass.sort(list, 1, comparator);
break;
default:
someHelperClass.sort(list, 2, comparator);
break;
case 2:
someHelperClass.sort(list, 2, comparator);
case 3:
someHelperClass.sort(list, 3, comparator);
break;
}
return list;
}
}