muse-dev[bot] commented on a change in pull request #1954:
URL: https://github.com/apache/lucene-solr/pull/1954#discussion_r512201676



##########
File path: 
lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadMatcherFactory.java
##########
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.payloads;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+
+import org.apache.lucene.queries.payloads.SpanPayloadCheckQuery.PayloadType;
+import org.apache.lucene.util.BytesRef;
+
+/**
+ * Creates a payload matcher object based on a payload type and an operation.
+ * PayloadTypes of INT,FLOAT, or STRING are supported.  Inequality operations 
are supported.
+ */
+public class PayloadMatcherFactory {
+
+  private static final HashMap<PayloadType, HashMap<String, PayloadMatcher>> 
payloadCheckerOpTypeMap;
+  static {
+    payloadCheckerOpTypeMap= new HashMap<PayloadType, HashMap<String, 
PayloadMatcher>>();
+    // ints
+    HashMap<String, PayloadMatcher> intCheckers = new HashMap<String, 
PayloadMatcher>();
+    intCheckers.put("lt", new LTIntPayloadMatcher());
+    intCheckers.put("lte", new LTEIntPayloadMatcher());
+    intCheckers.put("gt", new GTIntPayloadMatcher());
+    intCheckers.put("gte", new GTEIntPayloadMatcher());
+    HashMap<String, PayloadMatcher> floatCheckers = new HashMap<String, 
PayloadMatcher>();
+    floatCheckers.put("lt", new LTFloatPayloadMatcher());
+    floatCheckers.put("lte", new LTEFloatPayloadMatcher());
+    floatCheckers.put("gt", new GTFloatPayloadMatcher());
+    floatCheckers.put("gte", new GTEFloatPayloadMatcher());
+    // strings
+    HashMap<String, PayloadMatcher> stringCheckers = new HashMap<String, 
PayloadMatcher>();
+    stringCheckers.put("lt", new LTStringPayloadMatcher());
+    stringCheckers.put("lte", new LTEStringPayloadMatcher());
+    stringCheckers.put("gt", new GTStringPayloadMatcher());
+    stringCheckers.put("gte", new GTEStringPayloadMatcher());
+    // load the matcher maps per payload type
+    payloadCheckerOpTypeMap.put(PayloadType.INT, intCheckers);
+    payloadCheckerOpTypeMap.put(PayloadType.FLOAT, floatCheckers);
+    payloadCheckerOpTypeMap.put(PayloadType.STRING, stringCheckers);
+  }
+  
+  /**
+   * Return a payload matcher for use in the SpanPayloadCheckQuery that will 
decode the ByteRef from 
+   * a payload based on the payload type, and apply a matching inequality 
operations (eq,lt,lte,gt,and gte)
+   * 
+   * @param payloadType the type of the payload to decode, STRING, INT, FLOAT
+   * @param op and inequalit operation as the test (example: eq for equals, gt 
for greater than)
+   * @return a payload matcher that decodes the payload and applies the 
operation inequality test.
+   * 
+   */
+  public static PayloadMatcher createMatcherForOpAndType(PayloadType 
payloadType, String op) {
+    // special optimization, binary/byte comparison
+    if (op == null || "eq".contentEquals(op)) {
+      return new EQPayloadMatcher();
+    }
+    // otherwise, we need to pay attention to the payload type and operation
+    return payloadCheckerOpTypeMap.get(payloadType).get(op);

Review comment:
       *NULL_DEREFERENCE:*  object returned by 
`org.apache.lucene.queries.payloads.PayloadMatcherFactory.payloadCheckerOpTypeMap.get(payloadType)`
 could be null and is dereferenced at line 72.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to