@@ -39,7 +39,7 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
3939 /**
4040 * A robust comparator that handles edge cases for different data types
4141 */
42- private static class RobustComparator <T extends Comparable <T >> implements Comparator <T > {
42+ private static final class RobustComparator <T extends Comparable <T >> implements Comparator <T > {
4343
4444 @ Override
4545 @ SuppressWarnings ("unchecked" )
@@ -76,37 +76,37 @@ public int compare(T a, T b) {
7676
7777 private int compareDoubles (Double a , Double b ) {
7878 // Handle NaN: NaN should come last
79- if (Double .isNaN (a ) && Double .isNaN (b )) return 0 ;
80- if (Double .isNaN (a )) return 1 ;
81- if (Double .isNaN (b )) return -1 ;
79+ if (Double .isNaN (a ) && Double .isNaN (b )) { return 0 ; }
80+ if (Double .isNaN (a )) { return 1 ; }
81+ if (Double .isNaN (b )) { return -1 ; }
8282
8383 // Handle infinities
84- if (a .equals (Double .NEGATIVE_INFINITY ) && b .equals (Double .NEGATIVE_INFINITY )) return 0 ;
85- if (a .equals (Double .NEGATIVE_INFINITY )) return -1 ;
86- if (b .equals (Double .NEGATIVE_INFINITY )) return 1 ;
84+ if (a .equals (Double .NEGATIVE_INFINITY ) && b .equals (Double .NEGATIVE_INFINITY )) { return 0 ; }
85+ if (a .equals (Double .NEGATIVE_INFINITY )) { return -1 ; }
86+ if (b .equals (Double .NEGATIVE_INFINITY )) { return 1 ; }
8787
88- if (a .equals (Double .POSITIVE_INFINITY ) && b .equals (Double .POSITIVE_INFINITY )) return 0 ;
89- if (a .equals (Double .POSITIVE_INFINITY )) return 1 ;
90- if (b .equals (Double .POSITIVE_INFINITY )) return -1 ;
88+ if (a .equals (Double .POSITIVE_INFINITY ) && b .equals (Double .POSITIVE_INFINITY )) { return 0 ; }
89+ if (a .equals (Double .POSITIVE_INFINITY )) { return 1 ; }
90+ if (b .equals (Double .POSITIVE_INFINITY )) { return -1 ; }
9191
9292 // Normal comparison
9393 return Double .compare (a , b );
9494 }
9595
9696 private int compareFloats (Float a , Float b ) {
9797 // Handle NaN: NaN should come last
98- if (Float .isNaN (a ) && Float .isNaN (b )) return 0 ;
99- if (Float .isNaN (a )) return 1 ;
100- if (Float .isNaN (b )) return -1 ;
98+ if (Float .isNaN (a ) && Float .isNaN (b )) { return 0 ; }
99+ if (Float .isNaN (a )) { return 1 ; }
100+ if (Float .isNaN (b )) { return -1 ; }
101101
102102 // Handle infinities
103- if (a .equals (Float .NEGATIVE_INFINITY ) && b .equals (Float .NEGATIVE_INFINITY )) return 0 ;
104- if (a .equals (Float .NEGATIVE_INFINITY )) return -1 ;
105- if (b .equals (Float .NEGATIVE_INFINITY )) return 1 ;
103+ if (a .equals (Float .NEGATIVE_INFINITY ) && b .equals (Float .NEGATIVE_INFINITY )) { return 0 ; }
104+ if (a .equals (Float .NEGATIVE_INFINITY )) { return -1 ; }
105+ if (b .equals (Float .NEGATIVE_INFINITY )) { return 1 ; }
106106
107- if (a .equals (Float .POSITIVE_INFINITY ) && b .equals (Float .POSITIVE_INFINITY )) return 0 ;
108- if (a .equals (Float .POSITIVE_INFINITY )) return 1 ;
109- if (b .equals (Float .POSITIVE_INFINITY )) return -1 ;
107+ if (a .equals (Float .POSITIVE_INFINITY ) && b .equals (Float .POSITIVE_INFINITY )) { return 0 ; }
108+ if (a .equals (Float .POSITIVE_INFINITY )) { return 1 ; }
109+ if (b .equals (Float .POSITIVE_INFINITY )) { return -1 ; }
110110
111111 // Normal comparison
112112 return Float .compare (a , b );
@@ -121,9 +121,9 @@ private int compareNumbers(Number a, Number b) {
121121
122122 private int compareStrings (String a , String b ) {
123123 // Handle empty strings properly - they should come before non-empty strings
124- if (a .isEmpty () && b .isEmpty ()) return 0 ;
125- if (a .isEmpty ()) return -1 ;
126- if (b .isEmpty ()) return 1 ;
124+ if (a .isEmpty () && b .isEmpty ()) { return 0 ; }
125+ if (a .isEmpty ()) { return -1 ; }
126+ if (b .isEmpty ()) { return 1 ; }
127127
128128 // Normal string comparison
129129 return a .compareTo (b );
0 commit comments