public static String bestMatch ( Collection < String > supported , String header ) { List < ParseResults > parseResults = new LinkedList <> ( ) ; List < FitnessAndQuality > weightedMatches = new LinkedList <> ( ) ; for ( String r : header . split ( "," ) ) { parseResults . add ( parseMediaRange ( r ) ) ; } for ( String s : supported ) { FitnessAndQuality fitnessAndQuality = fitnessAndQualityParsed ( s , parseResults ) ; fitnessAndQuality . mimeType = s ; weightedMatches . add ( fitnessAndQuality ) ; } Collections . sort ( weightedMatches ) ; FitnessAndQuality lastOne = weightedMatches . get ( weightedMatches . size ( ) - 1 ) ; return Float . compare ( lastOne . quality , 0 ) != 0 ? lastOne . mimeType : NO_MIME_TYPE ; }
Finds best match