From 8011c48685e78850a88e7cc06650f678a375037d Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 28 Feb 2019 18:37:02 +1100 Subject: [PATCH] Issue #3404 Updated QCSV Double usage Signed-off-by: Greg Wilkins --- .../eclipse/jetty/http/QuotedQualityCSV.java | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/QuotedQualityCSV.java b/jetty-http/src/main/java/org/eclipse/jetty/http/QuotedQualityCSV.java index 61cee88bfd5..c7047c57a4b 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/QuotedQualityCSV.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/QuotedQualityCSV.java @@ -25,6 +25,8 @@ import java.util.Iterator; import java.util.List; import java.util.function.Function; +import org.eclipse.jetty.util.log.Log; + /* ------------------------------------------------------------ */ /** * Implements a quoted comma separated list of quality values @@ -37,21 +39,16 @@ import java.util.function.Function; */ public class QuotedQualityCSV extends QuotedCSV implements Iterable { - private final static Double ZERO=new Double(0.0); - private final static Double ONE=new Double(1.0); - + private final static Double ZERO = 0.0D; + private final static Double ONE = 1.0D; /** - * Function to apply a most specific MIME encoding secondary ordering + * Lambda to apply a most specific MIME encoding secondary ordering */ - public static Function MOST_SPECIFIC = new Function() + public static Function MOST_SPECIFIC = s -> { - @Override - public Integer apply(String s) - { - String[] elements = s.split("/"); - return 1000000*elements.length+1000*elements[0].length()+elements[elements.length-1].length(); - } + String[] elements = s.split("/"); + return 1000000*elements.length+1000*elements[0].length()+elements[elements.length-1].length(); }; private final List _quality = new ArrayList<>(); @@ -74,7 +71,8 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable */ public QuotedQualityCSV(String[] preferredOrder) { - this((s) -> { + this((s) -> + { for (int i=0;i protected void parsedValue(StringBuffer buffer) { super.parsedValue(buffer); + + // Assume a quality of ONE _quality.add(ONE); } @@ -108,30 +108,32 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable @Override protected void parsedParam(StringBuffer buffer, int valueLength, int paramName, int paramValue) { - if (paramName<0) + if (paramName < 0) { - if (buffer.charAt(buffer.length()-1)==';') - buffer.setLength(buffer.length()-1); + if (buffer.charAt(buffer.length() - 1) == ';') + buffer.setLength(buffer.length() - 1); } - else if (paramValue>=0 && - buffer.charAt(paramName)=='q' && paramValue>paramName && - buffer.length()>=paramName && buffer.charAt(paramName+1)=='=') + else if (paramValue >= 0 && + buffer.charAt(paramName) == 'q' && paramValue > paramName && + buffer.length() >= paramName && buffer.charAt(paramName + 1) == '=') { Double q; try { - q=(_keepQuotes && buffer.charAt(paramValue)=='"') - ?new Double(buffer.substring(paramValue+1,buffer.length()-1)) - :new Double(buffer.substring(paramValue)); + q = (_keepQuotes && buffer.charAt(paramValue) == '"') + ? Double.valueOf(buffer.substring(paramValue + 1, buffer.length() - 1)) + : Double.valueOf(buffer.substring(paramValue)); } - catch(Exception e) + catch (Exception e) { - q=ZERO; - } - buffer.setLength(Math.max(0,paramName-1)); - - if (!ONE.equals(q)) - _quality.set(_quality.size()-1,q); + Log.getLogger(QuotedQualityCSV.class).ignore(e); + q = ZERO; + } + buffer.setLength(Math.max(0, paramName - 1)); + + if (!ONE.equals(q)) + // replace assumed quality + _quality.set(_quality.size() - 1, q); } }