From bc38be3e0708f0d45a5d9cb37c7b96bc5d7ef727 Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Tue, 26 Nov 2013 02:42:18 +0000 Subject: [PATCH] SOLR-5488: Fix up test failures for analytics component. Some cleanups suggested by IntelliJ's analysis git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1545514 13f79535-47bb-0310-9956-ffa450edef68 --- .../analytics/expression/ExpressionFactory.java | 12 ++++-------- .../statistics/StatsCollectorSupplierFactory.java | 14 +++++++------- .../solr/analytics/facet/FieldFacetTest.java | 9 +++++---- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/analytics/expression/ExpressionFactory.java b/solr/core/src/java/org/apache/solr/analytics/expression/ExpressionFactory.java index 9dc78d4b031..5da5fb011c3 100644 --- a/solr/core/src/java/org/apache/solr/analytics/expression/ExpressionFactory.java +++ b/solr/core/src/java/org/apache/solr/analytics/expression/ExpressionFactory.java @@ -160,21 +160,17 @@ public class ExpressionFactory { int start = 0; List arguments = new ArrayList(); char[] chars = expression.toCharArray(); - boolean escapedCharacter = false; for (int count = 0; count < expression.length(); count++) { char c = chars[count]; - if (c==',' && stack == 0 && !escapedCharacter) { + if (c==',' && stack == 0) { arguments.add(expression.substring(start, count).replace("\\(","(").replace("\\)",")").replace("\\,",",").trim()); start = count+1; - } else if (c == '(' && !escapedCharacter) { + } else if (c == '(') { stack ++; - } else if (c == ')' && !escapedCharacter) { + } else if (c == ')') { stack --; } else if (c == '\\') { - escapedCharacter=true; - } - if (escapedCharacter) { - escapedCharacter=false; + ; // Do nothing. } } if (stack==0) { diff --git a/solr/core/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.java b/solr/core/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.java index 20d92d470a4..c4dea1b7ab9 100644 --- a/solr/core/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.java +++ b/solr/core/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.java @@ -421,7 +421,7 @@ public class StatsCollectorSupplierFactory { return null; } Object defaultObject; - Class type = delegateSource.getClass(); + ValueSource src = delegateSource; if (delegateSource instanceof FilterFieldSource) { src = ((FilterFieldSource)delegateSource).getRootSource(); @@ -432,6 +432,12 @@ public class StatsCollectorSupplierFactory { } catch (NumberFormatException e) { throw new SolrException(ErrorCode.BAD_REQUEST,"The filter value "+arguments[1]+" cannot be converted into an integer.",e); } + } else if ( src instanceof DateFieldSource || src instanceof MultiDateFunction) { + try { + defaultObject = TrieDateField.parseDate(arguments[1]); + } catch (ParseException e) { + throw new SolrException(ErrorCode.BAD_REQUEST,"The filter value "+arguments[1]+" cannot be converted into a date.",e); + } } else if ( src instanceof LongFieldSource ) { try { defaultObject = new Long(arguments[1]); @@ -451,12 +457,6 @@ public class StatsCollectorSupplierFactory { } catch (NumberFormatException e) { throw new SolrException(ErrorCode.BAD_REQUEST,"The filter value "+arguments[1]+" cannot be converted into a double.",e); } - } else if ( src instanceof DateFieldSource || src instanceof MultiDateFunction) { - try { - defaultObject = TrieDateField.parseDate(arguments[1]); - } catch (ParseException e) { - throw new SolrException(ErrorCode.BAD_REQUEST,"The filter value "+arguments[1]+" cannot be converted into a date.",e); - } } else { defaultObject = arguments[1]; } diff --git a/solr/core/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java b/solr/core/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java index 0a18edc45a2..895c43b6546 100644 --- a/solr/core/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java +++ b/solr/core/src/test/org/apache/solr/analytics/facet/FieldFacetTest.java @@ -1186,11 +1186,12 @@ public class FieldFacetTest extends AbstractAnalyticsFacetTest{ } private boolean checkStddevs(ArrayList list1, ArrayList list2) { - boolean b = true; - for (int i = 0; i