in commons-statistics-ranking/src/main/java/org/apache/commons/statistics/ranking/NaturalRanking.java [392:430]
private void resolveTie(double[] ranks, IntList tiesTrace, int finalIndex) {
tiesTrace.add(finalIndex);
// Constant value of ranks over tiesTrace.
// Note: c is a rank counter starting from 1 so limited to an int.
final double c = ranks[tiesTrace.get(0)];
// length of sequence of tied ranks
final int length = tiesTrace.size();
switch (tiesStrategy) {
case AVERAGE: // Replace ranks with average: (lower + upper) / 2
fill(ranks, tiesTrace, (2 * c + length - 1) * 0.5);
break;
case MAXIMUM: // Replace ranks with maximum values
fill(ranks, tiesTrace, c + length - 1);
break;
case MINIMUM: // Replace ties with minimum
// Note that the tie sequence already has all values set to c so
// no requirement to fill again.
break;
case SEQUENTIAL: // Fill sequentially from c to c + length - 1
case RANDOM: // Fill with randomized sequential values in [c, c + length - 1]
// This cast is safe as c is a counter.
int r = (int) c;
if (tiesStrategy == TiesStrategy.RANDOM) {
tiesTrace.shuffle(getRandomIntFunction());
}
final int size = tiesTrace.size();
for (int i = 0; i < size; i++) {
ranks[tiesTrace.get(i)] = r++;
}
break;
default: // this should not happen unless TiesStrategy enum is changed
throw new IllegalStateException();
}
tiesTrace.clear();
}