1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
/**
*
* @param value to find into table
* @return index where value is stored
*/
public int addFilter(String value){
int mediane = 0,
min=0, // first index
max= this.getRowCount()-1, //last index
goal = Integer.parseInt(value);
int maxValue = Integer.parseInt(getValueAt(max,0).toString());
int minValue = Integer.parseInt(getValueAt(min,0).toString());
if(goal<= maxValue && goal>minValue) {//dichotomy is needed only if goal is between min value and max value
while((max-min)>1){//dichotomy
mediane = (min+max)/2;
if(Integer.parseInt(getValueAt(mediane,0).toString())<goal) min = mediane;
else if(Integer.parseInt(getValueAt(mediane,0).toString())>goal)max = mediane;
else break;
}//end dichotomy
if(Integer.parseInt(getValueAt(mediane,0).toString())<goal) mediane++;
}
else if (goal>maxValue)
mediane = max;
else
mediane = min;// loop is true while itr lte mediane in order to display everything, mediane = -1
lastIndexFiltered = mediane;
return mediane;
} |