/** * Returns the quality factor of this {@link MediaType}. If it is not specified, * {@code 1.0f} will be returned. */ public float qualityFactor() { return qualityFactor(1.0f); }
@VisibleForTesting static int compareMediaType(MediaType m1, MediaType m2) { // The order should be "q=1.0, q=0.5". // To ensure descending order, we pass the q values of m2 and m1 respectively. final int qCompare = Float.compare(m2.qualityFactor(), m1.qualityFactor()); if (qCompare != 0) { return qCompare; } // The order should be "application/*, */*". final int wildcardCompare = Integer.compare(m1.numWildcards(), m2.numWildcards()); if (wildcardCompare != 0) { return wildcardCompare; } // Finally, sort by lexicographic order. ex, application/*, image/* return m1.type().compareTo(m2.type()); }
for (MediaType range : ranges) { requireNonNull(range, "ranges contains null."); float qValue = range.qualityFactor(Float.NEGATIVE_INFINITY); final int numWildcards = range.numWildcards(); final int numParams;