@Nullable
    public MediaType match(Iterable<MediaType> ranges) {
        requireNonNull(ranges, "ranges");

        MediaType match = null;
        float matchQ = Float.NEGATIVE_INFINITY;    // higher = better
        int matchNumWildcards = Integer.MAX_VALUE; // lower = better
        int matchNumParams = Integer.MIN_VALUE;    // higher = better
        for (MediaType range : ranges) {
            requireNonNull(range, "ranges contains null.");
            float qValue = range.qualityFactor(Float.NEGATIVE_INFINITY);
            final int numWildcards = range.numWildcards();
            final int numParams;
            if (qValue < 0) {
                // qvalue does not exist; use the default value of 1.0.
                qValue = 1.0f;
                numParams = range.parameters().size();
            } else {
                // Do not count the qvalue.
                numParams = range.parameters().size() - 1;
            }

            for (MediaType candidate : mediaTypes) {
                if (!candidate.belongsTo(range)) {
                    continue;
                }

                final boolean isBetter;
                if (qValue > matchQ) {
                    isBetter = true;
                } else if (Math.copySign(qValue - matchQ, 1.0f) <= 0.0001f) {
                    if (matchNumWildcards > numWildcards) {
                        isBetter = true;
                    } else if (matchNumWildcards == numWildcards) {
                        isBetter = numParams > matchNumParams;
                    } else {
                        isBetter = false;
                    }
                } else {
                    isBetter = false;
                }

                if (isBetter) {
                    match = candidate;
                    matchQ = qValue;
                    matchNumWildcards = numWildcards;
                    matchNumParams = numParams;

                    // Won't find another better candidate for this range.
                    break;
                }
            }
        }

        return match;
    }
Finds the {@link MediaType} in this {@link List} that matches one of the specified media ranges.

@return the most preferred {@link MediaType} that matches one of the specified media ranges.
        {@code null} if there are no matches or {@code ranges} does not contain any valid ranges.
core/src/main/java/com/linecorp/armeria/common/MediaTypeSet.java