Following code is a part of a project in which I need to determine the minimum/maximum of datacolumns. The problem is, I don't know whether the column will contain floats or ints. My attempt at making a generic class to do this is the following but this gives me the error on currentVal > compareVal
. My question is; where do I go wrong?
public <T> List<DataRow> compare(boolean Int) {
for(int i = 0; i<table.getRowCount(); i++){
T currentVal = (T) argument.resolve(row).getValue();
DataRow compare = table.getRow(i);
T compareVal = (T) argument.resolve(compare).getValue();
// if there's a new minimum or there's a new maximum
if((currentVal > compareVal && minimum) || (currentVal < compareVal && maximum)){
row = compare;
rowlist.clear();
rowlist.add(compare);
}
// if there's a duplicate minimum/maximum
else if(currentVal == compareVal)
rowlist.add(compare);
}
return rowlist;
}
by the way, in the first if statement, minimum and maximum are booleans which are true either if a minimum or maximum is to be calculated.
This is supposed to be an alternative to my current method(s);
public List<DataRow> floatCompare() {
for(int i = 0; i<table.getRowCount(); i++){
float currentVal = (float) argument.resolve(row).getValue();
DataRow compare = table.getRow(i);
float compareVal = (float) argument.resolve(compare).getValue();
// if there's a new minimum or there's a new maximum
if((currentVal > compareVal && minimum) || (currentVal < compareVal && maximum)){
row = compare;
rowlist.clear();
rowlist.add(compare);
}
// if there's a duplicate minimum/maximum
else if(currentVal == compareVal)
rowlist.add(compare);
}
return rowlist;
}
public List<DataRow> intCompare() {
for(int i = 0; i<table.getRowCount(); i++){
int currentVal = (int) argument.resolve(row).getValue();
DataRow compare = table.getRow(i);
int compareVal = (int) argument.resolve(compare).getValue();
// new minimum or new maximum
if((currentVal > compareVal && minimum) || (currentVal < compareVal && maximum)){
row = compare;
rowlist.clear();
rowlist.add(compare);
}
// duplicate minimum/maximum
else if(currentVal == compareVal)
rowlist.add(compare);
}
return rowlist;
}
These functions work, but I want to combine them into a generic class because they both do exactly the same thing.