@Test public void testBestMatch() { System.out.println("bestMatch"); Collection<String> acceps = new ArrayList<String>(); acceps.add("text/html"); acceps.add("text*;q=0.8"); String fileContentType = "text/plain"; String expResult = "text/*;q=0.9"; String result = MMTypeTools.bestMatch(acceps, fileContentType); assertEquals(expResult, result); }
public static String bestMatch(Collection<String> supported, String header) { List<ParseResults> parseResults = new LinkedList<ParseResults>(); List<FitnessAndQuality> weightedMatches = new LinkedList<FitnessAndQuality>(); 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); if (lastOne.quality != 0) { return lastOne.mimeType; } return ""; }
MMTypeTools { public static String bestMatch(Collection<String> supported, String header) { List<ParseResults> parseResults = new LinkedList<ParseResults>(); List<FitnessAndQuality> weightedMatches = new LinkedList<FitnessAndQuality>(); 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); if (lastOne.quality != 0) { return lastOne.mimeType; } return ""; } }
MMTypeTools { public static String bestMatch(Collection<String> supported, String header) { List<ParseResults> parseResults = new LinkedList<ParseResults>(); List<FitnessAndQuality> weightedMatches = new LinkedList<FitnessAndQuality>(); 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); if (lastOne.quality != 0) { return lastOne.mimeType; } return ""; }  }
MMTypeTools { public static String bestMatch(Collection<String> supported, String header) { List<ParseResults> parseResults = new LinkedList<ParseResults>(); List<FitnessAndQuality> weightedMatches = new LinkedList<FitnessAndQuality>(); 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); if (lastOne.quality != 0) { return lastOne.mimeType; } return ""; }  static String bestMatch(Collection<String> supported, String header); }
MMTypeTools { public static String bestMatch(Collection<String> supported, String header) { List<ParseResults> parseResults = new LinkedList<ParseResults>(); List<FitnessAndQuality> weightedMatches = new LinkedList<FitnessAndQuality>(); 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); if (lastOne.quality != 0) { return lastOne.mimeType; } return ""; }  static String bestMatch(Collection<String> supported, String header);  }