Skip to content

Commit

Permalink
Sort Frequency by Display
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Dec 28, 2024
1 parent b6e68f3 commit 505f259
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.function.Function;

import com.projecturanus.betterp2p.client.gui.InfoWrapper;
import org.apache.commons.lang3.StringUtils;

public enum SortModes {

Expand Down Expand Up @@ -49,17 +50,23 @@ private static Comparator<InfoWrapper> compDefault(InfoWrapper selected) {

if (b.getFrequency() == selected.getFrequency()) return 1;
}

if (a.getFrequency() != b.getFrequency()) {
// Unbound first
if (a.getFrequency() == 0) return -1;
if (b.getFrequency() == 0) return 1;

// Errors next
if (a.getError()) return -1;
// Errors next, also sorted by frequency (display)
if (a.getError()) {
if (b.getError()) {
return StringUtils.compare(a.getFreqDisplay(), b.getFreqDisplay());
}
return -1;
}
if (b.getError()) return 1;

// Else, sort by frequency
return b.getFrequency() - a.getFrequency();
// Else, sort by frequency (display)
return StringUtils.compare(a.getFreqDisplay(), b.getFreqDisplay());
}

return compareTypeThenDist(a, b);
Expand Down

0 comments on commit 505f259

Please sign in to comment.