lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sar...@apache.org
Subject [02/50] [abbrv] lucene-solr:apiv2: general cleanup to use java 8 feautures
Date Wed, 02 Nov 2016 23:58:59 GMT
general cleanup to use java 8 feautures


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0feca1a9
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0feca1a9
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0feca1a9

Branch: refs/heads/apiv2
Commit: 0feca1a9742a5c945024e6e2bbc9098a003ab538
Parents: d6b6e74
Author: Noble Paul <noble@apache.org>
Authored: Thu Oct 27 15:03:05 2016 +0530
Committer: Noble Paul <noble@apache.org>
Committed: Thu Oct 27 15:05:07 2016 +0530

----------------------------------------------------------------------
 .../solr/handler/dataimport/DIHCache.java       | 16 ++++----
 .../solr/handler/dataimport/EventListener.java  |  2 +-
 .../dataimport/XPathEntityProcessor.java        | 40 ++++++++------------
 .../handler/dataimport/XPathRecordReader.java   | 15 +++-----
 .../AbstractDataImportHandlerTestCase.java      | 14 ++-----
 .../dataimport/TestXPathRecordReader.java       | 15 +++-----
 6 files changed, 38 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0feca1a9/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCache.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCache.java
b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCache.java
index 7e72d4e..a67b3e4 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCache.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCache.java
@@ -35,7 +35,7 @@ public interface DIHCache extends Iterable<Map<String,Object>>
{
    * includes any parameters needed by the cache impl. This must be called
    * before any read/write operations are permitted.
    */
-  public void open(Context context);
+  void open(Context context);
   
   /**
    * <p>
@@ -43,14 +43,14 @@ public interface DIHCache extends Iterable<Map<String,Object>>
{
    * but not destroyed.
    * </p>
    */
-  public void close();
+  void close();
   
   /**
    * <p>
    * Persists any pending data to the cache
    * </p>
    */
-  public void flush();
+  void flush();
   
   /**
    * <p>
@@ -67,7 +67,7 @@ public interface DIHCache extends Iterable<Map<String,Object>>
{
    * update a key's documents, first call delete(Object key).
    * </p>
    */
-  public void add(Map<String,Object> rec);
+  void add(Map<String, Object> rec);
   
   /**
    * <p>
@@ -76,7 +76,7 @@ public interface DIHCache extends Iterable<Map<String,Object>>
{
    * </p>
    */
   @Override
-  public Iterator<Map<String,Object>> iterator();
+  Iterator<Map<String,Object>> iterator();
   
   /**
    * <p>
@@ -84,20 +84,20 @@ public interface DIHCache extends Iterable<Map<String,Object>>
{
    * match the given key in insertion order.
    * </p>
    */
-  public Iterator<Map<String,Object>> iterator(Object key);
+  Iterator<Map<String,Object>> iterator(Object key);
   
   /**
    * <p>
    * Delete all documents associated with the given key
    * </p>
    */
-  public void delete(Object key);
+  void delete(Object key);
   
   /**
    * <p>
    * Delete all data from the cache,leaving the empty cache intact.
    * </p>
    */
-  public void deleteAll();
+  void deleteAll();
   
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0feca1a9/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EventListener.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EventListener.java
b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EventListener.java
index 0f22513..0c43a0b 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EventListener.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EventListener.java
@@ -30,6 +30,6 @@ public interface EventListener {
    *
    * @param ctx the Context in which this event was called
    */
-  public void onEvent(Context ctx);
+  void onEvent(Context ctx);
 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0feca1a9/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathEntityProcessor.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathEntityProcessor.java
b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathEntityProcessor.java
index cc28dc4..70b9aba 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathEntityProcessor.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathEntityProcessor.java
@@ -323,13 +323,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
         rowIterator = getRowIterator(data, s);
       } else {
         try {
-          xpathReader.streamRecords(data, new XPathRecordReader.Handler() {
-            @Override
-            @SuppressWarnings("unchecked")
-            public void handle(Map<String, Object> record, String xpath) {
-              rows.add(readRow(record, xpath));
-            }
-          });
+          xpathReader.streamRecords(data, (record, xpath) -> rows.add(readRow(record,
xpath)));
         } catch (Exception e) {
           String msg = "Parsing failed for xml, url:" + s + " rows processed:" + rows.size();
           if (rows.size() > 0) msg += " last row: " + rows.get(rows.size() - 1);
@@ -433,25 +427,21 @@ public class XPathEntityProcessor extends EntityProcessorBase {
       @Override
       public void run() {
         try {
-          xpathReader.streamRecords(data, new XPathRecordReader.Handler() {
-            @Override
-            @SuppressWarnings("unchecked")
-            public void handle(Map<String, Object> record, String xpath) {
-              if (isEnd.get()) {
-                throwExp.set(false);
-                //To end the streaming . otherwise the parsing will go on forever
-                //though consumer has gone away
-                throw new RuntimeException("BREAK");
-              }
-              Map<String, Object> row;
-              try {
-                row = readRow(record, xpath);
-              } catch (Exception e) {
-                isEnd.set(true);
-                return;
-              }
-              offer(row);
+          xpathReader.streamRecords(data, (record, xpath) -> {
+            if (isEnd.get()) {
+              throwExp.set(false);
+              //To end the streaming . otherwise the parsing will go on forever
+              //though consumer has gone away
+              throw new RuntimeException("BREAK");
+            }
+            Map<String, Object> row;
+            try {
+              row = readRow(record, xpath);
+            } catch (Exception e) {
+              isEnd.set(true);
+              return;
             }
+            offer(row);
           });
         } catch (Exception e) {
           if(throwExp.get()) exp.set(e);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0feca1a9/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathRecordReader.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathRecordReader.java
b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathRecordReader.java
index 266e047..69c6c57 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathRecordReader.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/XPathRecordReader.java
@@ -162,12 +162,7 @@ public class XPathRecordReader {
    */
   public List<Map<String, Object>> getAllRecords(Reader r) {
     final List<Map<String, Object>> results = new ArrayList<>();
-    streamRecords(r, new Handler() {
-      @Override
-      public void handle(Map<String, Object> record, String s) {
-        results.add(record);
-      }
-    });
+    streamRecords(r, (record, s) -> results.add(record));
     return results;
   }
 
@@ -182,8 +177,8 @@ public class XPathRecordReader {
   public void streamRecords(Reader r, Handler handler) {
     try {
       XMLStreamReader parser = factory.createXMLStreamReader(r);
-      rootNode.parse(parser, handler, new HashMap<String, Object>(),
-              new Stack<Set<String>>(), false);
+      rootNode.parse(parser, handler, new HashMap<>(),
+          new Stack<>(), false);
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
@@ -657,7 +652,7 @@ public class XPathRecordReader {
   /**Implement this interface to stream records as and when one is found.
    *
    */
-  public static interface Handler {
+  public interface Handler {
     /**
      * @param record The record map. The key is the field name as provided in 
      * the addField() methods. The value can be a single String (for single 
@@ -666,7 +661,7 @@ public class XPathRecordReader {
      * If there is any change all parsing will be aborted and the Exception
      * is propagated up
      */
-    public void handle(Map<String, Object> record, String xpath);
+    void handle(Map<String, Object> record, String xpath);
   }
 
   private static final Pattern ATTRIB_PRESENT_WITHVAL = Pattern

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0feca1a9/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
index 60f0811..db02993 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java
@@ -20,7 +20,6 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -28,6 +27,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SuppressForbidden;
+import org.apache.solr.common.util.Utils;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
@@ -145,7 +145,7 @@ public abstract class AbstractDataImportHandlerTestCase extends
     if (resolver == null) resolver = new VariableResolver();
     final Context delegate = new ContextImpl(parent, resolver,
             parentDataSource, currProcess,
-            new HashMap<String, Object>(), null, null);
+        new HashMap<>(), null, null);
     return new TestContext(entityAttrs, delegate, entityFields, parent == null);
   }
 
@@ -155,15 +155,7 @@ public abstract class AbstractDataImportHandlerTestCase extends
    */
   @SuppressWarnings("unchecked")
   public static Map createMap(Object... args) {
-    Map result = new LinkedHashMap();
-
-    if (args == null || args.length == 0)
-      return result;
-
-    for (int i = 0; i < args.length - 1; i += 2)
-      result.put(args[i], args[i + 1]);
-
-    return result;
+   return Utils.makeMap(args);
   }
 
   @SuppressForbidden(reason = "Needs currentTimeMillis to set modified time for a file")

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0feca1a9/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathRecordReader.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathRecordReader.java
b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathRecordReader.java
index 5f9a5ca..d8e3cbe 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathRecordReader.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathRecordReader.java
@@ -16,13 +16,13 @@
  */
 package org.apache.solr.handler.dataimport;
 
-import org.junit.Test;
-
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.junit.Test;
+
 /**
  * <p> Test for XPathRecordReader </p>
  *
@@ -138,13 +138,10 @@ public class TestXPathRecordReader extends AbstractDataImportHandlerTestCase
{
 
     final List<Map<String, Object>> a = new ArrayList<>();
     final List<Map<String, Object>> x = new ArrayList<>();
-    rr.streamRecords(new StringReader(xml), new XPathRecordReader.Handler() {
-      @Override
-      public void handle(Map<String, Object> record, String xpath) {
-        if (record == null) return;
-        if (xpath.equals("/root/a")) a.add(record);
-        if (xpath.equals("/root/x")) x.add(record);
-      }
+    rr.streamRecords(new StringReader(xml), (record, xpath) -> {
+      if (record == null) return;
+      if (xpath.equals("/root/a")) a.add(record);
+      if (xpath.equals("/root/x")) x.add(record);
     });
 
     assertEquals(1, a.size());


Mime
View raw message