@@ -59,9 +59,9 @@ public final class Quality {
5959 public static final Comparator <Qualified > QUALIFIED_COMPARATOR = new Comparator <Qualified >() {
6060
6161 @ Override
62- public int compare (Qualified o1 , Qualified o2 ) {
62+ public int compare (final Qualified o1 , final Qualified o2 ) {
6363 // reverse comparison to achieve the "higher first" behavior.
64- return Integer .compare (o2 .getQuality (), o1 .getQuality ());
64+ return Quality .compare (o2 .getQuality (), o1 .getQuality ());
6565 }
6666 };
6767
@@ -73,9 +73,9 @@ public int compare(Qualified o1, Qualified o2) {
7373 public static final Comparator <Integer > QUALITY_VALUE_COMPARATOR = new Comparator <Integer >() {
7474
7575 @ Override
76- public int compare (Integer q1 , Integer q2 ) {
76+ public int compare (final Integer q1 , final Integer q2 ) {
7777 // reverse comparison to achieve the "higher first" behavior.
78- return Integer .compare (q2 , q1 );
78+ return Quality .compare (q2 , q1 );
7979 }
8080 };
8181
@@ -116,7 +116,7 @@ private Quality() {
116116 * @return parameter map containing the proper quality parameter if necessary.
117117 */
118118 static Map <String , String > enhanceWithQualityParameter (
119- Map <String , String > parameters , final String qualityParamName , final int quality ) {
119+ final Map <String , String > parameters , final String qualityParamName , final int quality ) {
120120
121121 if (quality == DEFAULT ) {
122122 // special handling
@@ -134,15 +134,34 @@ static Map<String, String> enhanceWithQualityParameter(
134134 // Try to update the original map first...
135135 parameters .put (qualityParamName , qualityValueToString (quality ));
136136 return parameters ;
137- } catch (UnsupportedOperationException uoe ) {
137+ } catch (final UnsupportedOperationException uoe ) {
138138 // Unmodifiable map - let's create a new copy...
139139 final Map <String , String > result = new HashMap <String , String >(parameters );
140140 result .put (qualityParamName , qualityValueToString (quality ));
141141 return result ;
142142 }
143143 }
144144
145- private static String qualityValueToString (float quality ) {
145+ /**
146+ * Compares two {@code int} values numerically.
147+ * The value returned is identical to what would be returned by:
148+ * <pre>
149+ * Integer.valueOf(x).compareTo(Integer.valueOf(y))
150+ * </pre>
151+ *
152+ * Note: Taken from {@code Integer.compare()} from JDK 7.
153+ *
154+ * @param x the first {@code int} to compare
155+ * @param y the second {@code int} to compare
156+ * @return the value {@code 0} if {@code x == y};
157+ * a value less than {@code 0} if {@code x < y}; and
158+ * a value greater than {@code 0} if {@code x > y}
159+ */
160+ private static int compare (final int x , final int y ) {
161+ return (x < y ) ? -1 : ((x == y ) ? 0 : 1 );
162+ }
163+
164+ private static String qualityValueToString (final float quality ) {
146165 final StringBuilder qsb = new StringBuilder (String .format ("%3.3f" , (quality / 1000 )));
147166
148167 int lastIndex ;
0 commit comments