You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2020/06/04 17:32:49 UTC

[lucene-solr] 01/04: SOLR-14470: Fix inconsistent formatting.

This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch jira/solr-14470-2
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit d8154202b45b3d3c606a7cf1d454a62bd03b22d5
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Thu Jun 4 18:42:07 2020 +0200

    SOLR-14470: Fix inconsistent formatting.
---
 .../client/solrj/io/stream/expr/StreamFactory.java | 212 ++++++++++-----------
 1 file changed, 99 insertions(+), 113 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
index 883c57b..451add8 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
@@ -45,8 +45,8 @@ import org.apache.solr.client.solrj.io.stream.metrics.Metric;
  */
 public class StreamFactory implements Serializable {
   
-  private transient HashMap<String,String> collectionZkHosts;
-  private transient HashMap<String,Supplier<Class<? extends Expressible>>> functionNames;
+  private transient HashMap<String, String> collectionZkHosts;
+  private transient HashMap<String, Supplier<Class<? extends Expressible>>> functionNames;
   private transient String defaultZkHost;
   private transient String defaultCollection;
   private transient String defaultSort;
@@ -56,12 +56,12 @@ public class StreamFactory implements Serializable {
     functionNames = new HashMap<>();
   }
 
-  public StreamFactory(HashMap<String,Supplier<Class<? extends Expressible>>> functionNames) {
+  public StreamFactory(HashMap<String, Supplier<Class<? extends Expressible>>> functionNames) {
     this.functionNames = functionNames;
     collectionZkHosts = new HashMap<>();
   }
   
-  public StreamFactory withCollectionZkHost(String collectionName, String zkHost){
+  public StreamFactory withCollectionZkHost(String collectionName, String zkHost) {
     this.collectionZkHosts.put(collectionName, zkHost);
     this.defaultCollection = collectionName;
     return this;
@@ -95,8 +95,8 @@ public class StreamFactory implements Serializable {
     return this.defaultZkHost;
   }
 
-  public String getCollectionZkHost(String collectionName){
-    if(this.collectionZkHosts.containsKey(collectionName)){
+  public String getCollectionZkHost(String collectionName) {
+    if (this.collectionZkHosts.containsKey(collectionName)) {
       return this.collectionZkHosts.get(collectionName);
     }
     return null;
@@ -105,12 +105,13 @@ public class StreamFactory implements Serializable {
   public Map<String, Supplier<Class<? extends Expressible>>> getFunctionNames() {
     return Collections.unmodifiableMap(functionNames);
   }
-  public StreamFactory withFunctionName(String functionName, Class<? extends Expressible> clazz){
+
+  public StreamFactory withFunctionName(String functionName, Class<? extends Expressible> clazz) {
     this.functionNames.put(functionName, () -> clazz);
     return this;
   }
 
-   public StreamFactory withFunctionName(String functionName, Supplier< Class<? extends Expressible>> clazz){
+   public StreamFactory withFunctionName(String functionName, Supplier< Class<? extends Expressible>> clazz) {
     this.functionNames.put(functionName, clazz);
     return this;
   }
@@ -120,94 +121,88 @@ public class StreamFactory implements Serializable {
     return this;
   }
 
-
-  public StreamExpressionParameter getOperand(StreamExpression expression, int parameterIndex){
-    if(null == expression.getParameters() || parameterIndex >= expression.getParameters().size()){
+  public StreamExpressionParameter getOperand(StreamExpression expression, int parameterIndex) {
+    if (null == expression.getParameters() || parameterIndex >= expression.getParameters().size()) {
       return null;
     }
-    
     return expression.getParameters().get(parameterIndex);
   }
   
-  public List<String> getValueOperands(StreamExpression expression){
+  public List<String> getValueOperands(StreamExpression expression) {
     return getOperandsOfType(expression, StreamExpressionValue.class).stream().map(item -> ((StreamExpressionValue) item).getValue()).collect(Collectors.toList());
   }
   
   /** Given an expression, will return the value parameter at the given index, or null if doesn't exist */
-  public String getValueOperand(StreamExpression expression, int parameterIndex){
+  public String getValueOperand(StreamExpression expression, int parameterIndex) {
     StreamExpressionParameter parameter = getOperand(expression, parameterIndex);
-    if(null != parameter){ 
-      if(parameter instanceof StreamExpressionValue){
+    if (null != parameter) {
+      if (parameter instanceof StreamExpressionValue) {
         return ((StreamExpressionValue)parameter).getValue();
-      } else if(parameter instanceof StreamExpression) {
+      } else if (parameter instanceof StreamExpression) {
         return parameter.toString();
       }
     }
-    
     return null;
   }
   
-  public List<StreamExpressionNamedParameter> getNamedOperands(StreamExpression expression){
+  public List<StreamExpressionNamedParameter> getNamedOperands(StreamExpression expression) {
     List<StreamExpressionNamedParameter> namedParameters = new ArrayList<>();
-    for(StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpressionNamedParameter.class)){
-      namedParameters.add((StreamExpressionNamedParameter)parameter);
+    for (StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpressionNamedParameter.class)) {
+      namedParameters.add((StreamExpressionNamedParameter) parameter);
     }
-    
     return namedParameters;
   }
-  public StreamExpressionNamedParameter getNamedOperand(StreamExpression expression, String name){
+
+  public StreamExpressionNamedParameter getNamedOperand(StreamExpression expression, String name) {
     List<StreamExpressionNamedParameter> namedParameters = getNamedOperands(expression);
-    for(StreamExpressionNamedParameter param : namedParameters){
-      if(param.getName().equals(name)){
+    for (StreamExpressionNamedParameter param : namedParameters) {
+      if (param.getName().equals(name)) {
         return param;
       }
     }
-    
     return null;
   }
   
-  public List<StreamExpression> getExpressionOperands(StreamExpression expression){
+  public List<StreamExpression> getExpressionOperands(StreamExpression expression) {
     List<StreamExpression> namedParameters = new ArrayList<>();
-    for(StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpression.class)){
-      namedParameters.add((StreamExpression)parameter);
+    for (StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpression.class)) {
+      namedParameters.add((StreamExpression) parameter);
     }
-    
     return namedParameters;
   }
-  public List<StreamExpression> getExpressionOperands(StreamExpression expression, String functionName){
+
+  public List<StreamExpression> getExpressionOperands(StreamExpression expression, String functionName) {
     List<StreamExpression> namedParameters = new ArrayList<>();
-    for(StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpression.class)){
-      StreamExpression expressionOperand = (StreamExpression)parameter;
-      if(expressionOperand.getFunctionName().equals(functionName)){
+    for (StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpression.class)) {
+      StreamExpression expressionOperand = (StreamExpression) parameter;
+      if (expressionOperand.getFunctionName().equals(functionName)) {
         namedParameters.add(expressionOperand);
       }
     }
-    
     return namedParameters;
   }
-  public List<StreamExpressionParameter> getOperandsOfType(StreamExpression expression, Class ... clazzes){
+
+  public List<StreamExpressionParameter> getOperandsOfType(StreamExpression expression, Class ... clazzes) {
     List<StreamExpressionParameter> parameters = new ArrayList<>();
     
     parameterLoop:
-     for(StreamExpressionParameter parameter : expression.getParameters()){
-      for(Class clazz : clazzes){
-        if(!clazz.isAssignableFrom(parameter.getClass())){
+     for (StreamExpressionParameter parameter : expression.getParameters()) {
+      for (Class clazz : clazzes) {
+        if (!clazz.isAssignableFrom(parameter.getClass())) {
           continue parameterLoop; // go to the next parameter since this parameter cannot be assigned to at least one of the classes
         }
       }
-      
       parameters.add(parameter);
     }
-    
     return parameters;
   }
   
-  public List<StreamExpression> getExpressionOperandsRepresentingTypes(StreamExpression expression, Class ... clazzes){
+  public List<StreamExpression> getExpressionOperandsRepresentingTypes(StreamExpression expression, Class ... clazzes) {
     List<StreamExpression> matchingStreamExpressions = new ArrayList<>();
     List<StreamExpression> allStreamExpressions = getExpressionOperands(expression);
     
     parameterLoop:
-    for(StreamExpression streamExpression : allStreamExpressions) {
+    for (StreamExpression streamExpression : allStreamExpressions) {
       Supplier<Class<? extends Expressible>> classSupplier = functionNames.get(streamExpression.getFunctionName());
       if (classSupplier != null) {
         for (Class clazz : clazzes) {
@@ -215,180 +210,170 @@ public class StreamFactory implements Serializable {
             continue parameterLoop;
           }
         }
-
         matchingStreamExpressions.add(streamExpression);
       }
     }
-    
     return matchingStreamExpressions;   
   }
   
-  public boolean doesRepresentTypes(StreamExpression expression, Class ... clazzes){
+  public boolean doesRepresentTypes(StreamExpression expression, Class ... clazzes) {
     Supplier<Class<? extends Expressible>> classSupplier = functionNames.get(expression.getFunctionName());
-    if(classSupplier != null){
-      for(Class clazz : clazzes){
-        if(!clazz.isAssignableFrom(classSupplier.get())){
+    if (classSupplier != null) {
+      for (Class clazz : clazzes) {
+        if (!clazz.isAssignableFrom(classSupplier.get())) {
           return false;
         }
       }
       return true;
     }
-    
     return false;    
   }
   
-  public int getIntOperand(StreamExpression expression, String paramName, Integer defaultValue) throws IOException{
+  public int getIntOperand(StreamExpression expression, String paramName, Integer defaultValue) throws IOException {
     StreamExpressionNamedParameter param = getNamedOperand(expression, paramName);
 
-    if(null == param || null == param.getParameter() || !(param.getParameter() instanceof StreamExpressionValue)){
-      if(null != defaultValue){
+    if (null == param || null == param.getParameter() || !(param.getParameter() instanceof StreamExpressionValue)) {
+      if (null != defaultValue) {
         return defaultValue;
       }
       throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting a single '%s' parameter of type integer but didn't find one",expression, paramName));
     }
-    String nStr = ((StreamExpressionValue)param.getParameter()).getValue();
-    try{
+    String nStr = ((StreamExpressionValue) param.getParameter()).getValue();
+    try {
       return Integer.parseInt(nStr);
-    }
-    catch(NumberFormatException e){
-      if(null != defaultValue){
+    } catch (NumberFormatException e) {
+      if (null != defaultValue) {
         return defaultValue;
       }
-      throw new IOException(String.format(Locale.ROOT,"invalid expression %s - %s '%s' is not a valid integer.",expression, paramName, nStr));
+      throw new IOException(String.format(Locale.ROOT,"invalid expression %s - %s '%s' is not a valid integer.", expression, paramName, nStr));
     }
   }
 
-  public boolean getBooleanOperand(StreamExpression expression, String paramName, Boolean defaultValue) throws IOException{
+  public boolean getBooleanOperand(StreamExpression expression, String paramName, Boolean defaultValue) throws IOException {
     StreamExpressionNamedParameter param = getNamedOperand(expression, paramName);
     
-    if(null == param || null == param.getParameter() || !(param.getParameter() instanceof StreamExpressionValue)){
-      if(null != defaultValue){
+    if (null == param || null == param.getParameter() || !(param.getParameter() instanceof StreamExpressionValue)) {
+      if (null != defaultValue) {
         return defaultValue;
       }
-      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting a single '%s' parameter of type boolean but didn't find one",expression, paramName));
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting a single '%s' parameter of type boolean but didn't find one", expression, paramName));
     }
-    String nStr = ((StreamExpressionValue)param.getParameter()).getValue();
+    String nStr = ((StreamExpressionValue) param.getParameter()).getValue();
     return Boolean.parseBoolean(nStr);
   }
 
-  
   public TupleStream constructStream(String expressionClause) throws IOException {
     return constructStream(StreamExpressionParser.parse(expressionClause));
   }
-  public TupleStream constructStream(StreamExpression expression) throws IOException{
+  public TupleStream constructStream(StreamExpression expression) throws IOException {
     String function = expression.getFunctionName();
     Supplier<Class<? extends Expressible>> classSupplier = functionNames.get(function);
 
-    if(classSupplier != null){
+    if (classSupplier != null) {
       Class<? extends Expressible> clazz =  classSupplier.get();
-      if(Expressible.class.isAssignableFrom(clazz) && TupleStream.class.isAssignableFrom(clazz)){
+      if (Expressible.class.isAssignableFrom(clazz) && TupleStream.class.isAssignableFrom(clazz)) {
         return (TupleStream)createInstance(clazz, new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
       }
     }
     
-    throw new IOException(String.format(Locale.ROOT,"Invalid stream expression %s - function '%s' is unknown (not mapped to a valid TupleStream)", expression, expression.getFunctionName()));
+    throw new IOException(String.format(Locale.ROOT, "Invalid stream expression %s - function '%s' is unknown (not mapped to a valid TupleStream)", expression, expression.getFunctionName()));
   }
   
   public Metric constructMetric(String expressionClause) throws IOException {
     return constructMetric(StreamExpressionParser.parse(expressionClause));
   }
-  public Metric constructMetric(StreamExpression expression) throws IOException{
+
+  public Metric constructMetric(StreamExpression expression) throws IOException {
     String function = expression.getFunctionName();
     Supplier<Class<? extends Expressible>> classSupplier = functionNames.get(function);
-    if(classSupplier != null){
+    if (classSupplier != null) {
       Class<? extends Expressible> clazz = classSupplier.get();
-      if(Expressible.class.isAssignableFrom(clazz) && Metric.class.isAssignableFrom(clazz)){
+      if (Expressible.class.isAssignableFrom(clazz) && Metric.class.isAssignableFrom(clazz)) {
         return (Metric)createInstance(clazz, new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
       }
     }
     
-    throw new IOException(String.format(Locale.ROOT,"Invalid metric expression %s - function '%s' is unknown (not mapped to a valid Metric)", expression, expression.getFunctionName()));
+    throw new IOException(String.format(Locale.ROOT, "Invalid metric expression %s - function '%s' is unknown (not mapped to a valid Metric)", expression, expression.getFunctionName()));
   }
 
   public StreamComparator constructComparator(String comparatorString, Class comparatorType) throws IOException {
-    if(comparatorString.contains(",")){
+    if (comparatorString.contains(",")) {
       String[] parts = comparatorString.split(",");
       StreamComparator[] comps = new StreamComparator[parts.length];
-      for(int idx = 0; idx < parts.length; ++idx){
+      for (int idx = 0; idx < parts.length; ++idx) {
         comps[idx] = constructComparator(parts[idx].trim(), comparatorType);
       }
       return new MultipleFieldComparator(comps);
-    }
-    else if(comparatorString.contains("=")){
+    } else if (comparatorString.contains("=")) {
       // expected format is "left=right order"
       String[] parts = comparatorString.split("[ =]");
       
-      if(parts.length < 3){
-        throw new IOException(String.format(Locale.ROOT,"Invalid comparator expression %s - expecting 'left=right order'",comparatorString));
+      if (parts.length < 3) {
+        throw new IOException(String.format(Locale.ROOT, "Invalid comparator expression %s - expecting 'left=right order'",comparatorString));
       }
       
       String leftFieldName = null;
       String rightFieldName = null;
       String order = null;
-      for(String part : parts){
+      for (String part : parts) {
         // skip empty
-        if(null == part || 0 == part.trim().length()){ continue; }
+        if (null == part || 0 == part.trim().length()) { continue; }
         
         // assign each in order
-        if(null == leftFieldName){ 
+        if (null == leftFieldName) {
           leftFieldName = part.trim(); 
-        }
-        else if(null == rightFieldName){ 
+        } else if (null == rightFieldName) {
           rightFieldName = part.trim(); 
-        }
-        else {
+        } else {
           order = part.trim();
           break; // we're done, stop looping
         }
       }
       
-      if(null == leftFieldName || null == rightFieldName || null == order){
-        throw new IOException(String.format(Locale.ROOT,"Invalid comparator expression %s - expecting 'left=right order'",comparatorString));
+      if (null == leftFieldName || null == rightFieldName || null == order) {
+        throw new IOException(String.format(Locale.ROOT, "Invalid comparator expression %s - expecting 'left=right order'",comparatorString));
       }
       
-      return (StreamComparator)createInstance(comparatorType, new Class[]{ String.class, String.class, ComparatorOrder.class }, new Object[]{ leftFieldName, rightFieldName, ComparatorOrder.fromString(order) });
-    }
-    else{
+      return (StreamComparator) createInstance(comparatorType, new Class[]{ String.class, String.class, ComparatorOrder.class }, new Object[]{ leftFieldName, rightFieldName, ComparatorOrder.fromString(order) });
+    } else {
       // expected format is "field order"
       String[] parts = comparatorString.split(" ");
-      if(2 != parts.length){
-        throw new IOException(String.format(Locale.ROOT,"Invalid comparator expression %s - expecting 'field order'",comparatorString));
+      if (2 != parts.length) {
+        throw new IOException(String.format(Locale.ROOT, "Invalid comparator expression %s - expecting 'field order'",comparatorString));
       }
       
       String fieldName = parts[0].trim();
       String order = parts[1].trim();
       
-      return (StreamComparator)createInstance(comparatorType, new Class[]{ String.class, ComparatorOrder.class }, new Object[]{ fieldName, ComparatorOrder.fromString(order) });
+      return (StreamComparator) createInstance(comparatorType, new Class[]{ String.class, ComparatorOrder.class }, new Object[]{ fieldName, ComparatorOrder.fromString(order) });
     }
   }
     
   public StreamEqualitor constructEqualitor(String equalitorString, Class equalitorType) throws IOException {
-    if(equalitorString.contains(",")){
+    if (equalitorString.contains(",")) {
       String[] parts = equalitorString.split(",");
       StreamEqualitor[] eqs = new StreamEqualitor[parts.length];
-      for(int idx = 0; idx < parts.length; ++idx){
+      for (int idx = 0; idx < parts.length; ++idx) {
         eqs[idx] = constructEqualitor(parts[idx].trim(), equalitorType);
       }
       return new MultipleFieldEqualitor(eqs);
-    }
-    else{
+    } else {
       String leftFieldName;
       String rightFieldName;
       
-      if(equalitorString.contains("=")){
+      if (equalitorString.contains("=")) {
         String[] parts = equalitorString.split("=");
-        if(2 != parts.length){
-          throw new IOException(String.format(Locale.ROOT,"Invalid equalitor expression %s - expecting fieldName=fieldName",equalitorString));
+        if (2 != parts.length) {
+          throw new IOException(String.format(Locale.ROOT, "Invalid equalitor expression %s - expecting fieldName=fieldName",equalitorString));
         }
         
         leftFieldName = parts[0].trim();
         rightFieldName = parts[1].trim();
-      }
-      else{
+      } else {
         leftFieldName = rightFieldName = equalitorString.trim();
       }
       
-      return (StreamEqualitor)createInstance(equalitorType, new Class[]{ String.class, String.class }, new Object[]{ leftFieldName, rightFieldName });
+      return (StreamEqualitor) createInstance(equalitorType, new Class[]{ String.class, String.class }, new Object[]{ leftFieldName, rightFieldName });
     }
   }
   
@@ -412,18 +397,19 @@ public class StreamFactory implements Serializable {
   public org.apache.solr.client.solrj.io.eval.StreamEvaluator constructEvaluator(String expressionClause) throws IOException {
     return constructEvaluator(StreamExpressionParser.parse(expressionClause));
   }
-  public org.apache.solr.client.solrj.io.eval.StreamEvaluator constructEvaluator(StreamExpression expression) throws IOException{
+
+  public org.apache.solr.client.solrj.io.eval.StreamEvaluator constructEvaluator(StreamExpression expression) throws IOException {
     String function = expression.getFunctionName();
     Supplier<Class<? extends Expressible>> classSupplier = functionNames.get(function);
 
-    if(classSupplier != null){
+    if (classSupplier != null) {
       Class<? extends Expressible> clazz = classSupplier.get();
-      if(Expressible.class.isAssignableFrom(clazz) && StreamEvaluator.class.isAssignableFrom(clazz)){
+      if (Expressible.class.isAssignableFrom(clazz) && StreamEvaluator.class.isAssignableFrom(clazz)) {
         return (org.apache.solr.client.solrj.io.eval.StreamEvaluator)createInstance(clazz, new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
       }
     }
     
-    throw new IOException(String.format(Locale.ROOT,"Invalid evaluator expression %s - function '%s' is unknown (not mapped to a valid StreamEvaluator)", expression, expression.getFunctionName()));
+    throw new IOException(String.format(Locale.ROOT, "Invalid evaluator expression %s - function '%s' is unknown (not mapped to a valid StreamEvaluator)", expression, expression.getFunctionName()));
   }
 
   public boolean isStream(StreamExpression expression) throws IOException {
@@ -478,13 +464,13 @@ public class StreamFactory implements Serializable {
     throw new IOException(String.format(Locale.ROOT, "Unable to find function name for class '%s'", clazz.getName()));
   }
 
-  public Object constructPrimitiveObject(String original){
+  public Object constructPrimitiveObject(String original) {
     String lower = original.trim().toLowerCase(Locale.ROOT);
 
-    if("null".equals(lower)){ return null; }
-    if("true".equals(lower) || "false".equals(lower)){ return Boolean.parseBoolean(lower); }
-    try{ return Long.valueOf(original); } catch(Exception ignored){};
-    try{ return Double.valueOf(original); } catch(Exception ignored){};
+    if ("null".equals(lower)) { return null; }
+    if ("true".equals(lower) || "false".equals(lower)){ return Boolean.parseBoolean(lower); }
+    try { return Long.valueOf(original); } catch(Exception ignored) { };
+    try { return Double.valueOf(original); } catch(Exception ignored) { };
 
     // is a string
     return original;