Skip to content

Commit

Permalink
Fix the index out of bound exception of rank calculation (eclipse-bir…
Browse files Browse the repository at this point in the history
  • Loading branch information
speckyspooky committed Jul 16, 2024
1 parent af6352c commit 66bebdb
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,29 @@ public void finish() throws DataException {
* </code>
*
* @param key
* @return rank
*/
private void calculateRank(List<Object> sortedList, boolean useDenseRank) {

int currentRank = 1;
int currentDenseRank = 1;
Object currentValue = sortedList.get(0);
if (sortedList != null && sortedList.size() > 0) {
Object currentValue = sortedList.get(0);

for (int i = 0; i < sortedList.size(); i++) {
Object integer = sortedList.get(i);
if (!Objects.equals(integer, currentValue)) {
for (int i = 0; i < sortedList.size(); i++) {
Object integer = sortedList.get(i);
if (!Objects.equals(integer, currentValue)) {

rankMap.put(currentValue, useDenseRank ? currentDenseRank : currentRank);
currentValue = integer;
currentDenseRank++;
currentRank = i + 1;
}

rankMap.put(currentValue, useDenseRank ? currentDenseRank : currentRank);
currentValue = integer;
currentDenseRank++;
currentRank = i + 1;
}

// Handle the last integer in the list
rankMap.put(currentValue, useDenseRank ? currentDenseRank : currentRank);
}

// Handle the last integer in the list
rankMap.put(currentValue, useDenseRank ? currentDenseRank : currentRank);
}

/*
Expand Down

0 comments on commit 66bebdb

Please sign in to comment.