general cleanup to use java 8 feautures

This commit is contained in:
Noble Paul 2016-10-27 15:03:05 +05:30
parent d6b6e74703
commit 0feca1a974
6 changed files with 38 additions and 64 deletions

View File

@ -35,7 +35,7 @@ public interface DIHCache extends Iterable<Map<String,Object>> {
* includes any parameters needed by the cache impl. This must be called * includes any parameters needed by the cache impl. This must be called
* before any read/write operations are permitted. * before any read/write operations are permitted.
*/ */
public void open(Context context); void open(Context context);
/** /**
* <p> * <p>
@ -43,14 +43,14 @@ public interface DIHCache extends Iterable<Map<String,Object>> {
* but not destroyed. * but not destroyed.
* </p> * </p>
*/ */
public void close(); void close();
/** /**
* <p> * <p>
* Persists any pending data to the cache * Persists any pending data to the cache
* </p> * </p>
*/ */
public void flush(); void flush();
/** /**
* <p> * <p>
@ -67,7 +67,7 @@ public interface DIHCache extends Iterable<Map<String,Object>> {
* update a key's documents, first call delete(Object key). * update a key's documents, first call delete(Object key).
* </p> * </p>
*/ */
public void add(Map<String,Object> rec); void add(Map<String, Object> rec);
/** /**
* <p> * <p>
@ -76,7 +76,7 @@ public interface DIHCache extends Iterable<Map<String,Object>> {
* </p> * </p>
*/ */
@Override @Override
public Iterator<Map<String,Object>> iterator(); Iterator<Map<String,Object>> iterator();
/** /**
* <p> * <p>
@ -84,20 +84,20 @@ public interface DIHCache extends Iterable<Map<String,Object>> {
* match the given key in insertion order. * match the given key in insertion order.
* </p> * </p>
*/ */
public Iterator<Map<String,Object>> iterator(Object key); Iterator<Map<String,Object>> iterator(Object key);
/** /**
* <p> * <p>
* Delete all documents associated with the given key * Delete all documents associated with the given key
* </p> * </p>
*/ */
public void delete(Object key); void delete(Object key);
/** /**
* <p> * <p>
* Delete all data from the cache,leaving the empty cache intact. * Delete all data from the cache,leaving the empty cache intact.
* </p> * </p>
*/ */
public void deleteAll(); void deleteAll();
} }

View File

@ -30,6 +30,6 @@ public interface EventListener {
* *
* @param ctx the Context in which this event was called * @param ctx the Context in which this event was called
*/ */
public void onEvent(Context ctx); void onEvent(Context ctx);
} }

View File

@ -323,13 +323,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
rowIterator = getRowIterator(data, s); rowIterator = getRowIterator(data, s);
} else { } else {
try { try {
xpathReader.streamRecords(data, new XPathRecordReader.Handler() { xpathReader.streamRecords(data, (record, xpath) -> rows.add(readRow(record, xpath)));
@Override
@SuppressWarnings("unchecked")
public void handle(Map<String, Object> record, String xpath) {
rows.add(readRow(record, xpath));
}
});
} catch (Exception e) { } catch (Exception e) {
String msg = "Parsing failed for xml, url:" + s + " rows processed:" + rows.size(); String msg = "Parsing failed for xml, url:" + s + " rows processed:" + rows.size();
if (rows.size() > 0) msg += " last row: " + rows.get(rows.size() - 1); if (rows.size() > 0) msg += " last row: " + rows.get(rows.size() - 1);
@ -433,10 +427,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
@Override @Override
public void run() { public void run() {
try { try {
xpathReader.streamRecords(data, new XPathRecordReader.Handler() { xpathReader.streamRecords(data, (record, xpath) -> {
@Override
@SuppressWarnings("unchecked")
public void handle(Map<String, Object> record, String xpath) {
if (isEnd.get()) { if (isEnd.get()) {
throwExp.set(false); throwExp.set(false);
//To end the streaming . otherwise the parsing will go on forever //To end the streaming . otherwise the parsing will go on forever
@ -451,7 +442,6 @@ public class XPathEntityProcessor extends EntityProcessorBase {
return; return;
} }
offer(row); offer(row);
}
}); });
} catch (Exception e) { } catch (Exception e) {
if(throwExp.get()) exp.set(e); if(throwExp.get()) exp.set(e);

View File

@ -162,12 +162,7 @@ public class XPathRecordReader {
*/ */
public List<Map<String, Object>> getAllRecords(Reader r) { public List<Map<String, Object>> getAllRecords(Reader r) {
final List<Map<String, Object>> results = new ArrayList<>(); final List<Map<String, Object>> results = new ArrayList<>();
streamRecords(r, new Handler() { streamRecords(r, (record, s) -> results.add(record));
@Override
public void handle(Map<String, Object> record, String s) {
results.add(record);
}
});
return results; return results;
} }
@ -182,8 +177,8 @@ public class XPathRecordReader {
public void streamRecords(Reader r, Handler handler) { public void streamRecords(Reader r, Handler handler) {
try { try {
XMLStreamReader parser = factory.createXMLStreamReader(r); XMLStreamReader parser = factory.createXMLStreamReader(r);
rootNode.parse(parser, handler, new HashMap<String, Object>(), rootNode.parse(parser, handler, new HashMap<>(),
new Stack<Set<String>>(), false); new Stack<>(), false);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -657,7 +652,7 @@ public class XPathRecordReader {
/**Implement this interface to stream records as and when one is found. /**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 * @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 * 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 * If there is any change all parsing will be aborted and the Exception
* is propagated up * 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 private static final Pattern ATTRIB_PRESENT_WITHVAL = Pattern

View File

@ -20,7 +20,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -28,6 +27,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SuppressForbidden; import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
@ -145,7 +145,7 @@ public abstract class AbstractDataImportHandlerTestCase extends
if (resolver == null) resolver = new VariableResolver(); if (resolver == null) resolver = new VariableResolver();
final Context delegate = new ContextImpl(parent, resolver, final Context delegate = new ContextImpl(parent, resolver,
parentDataSource, currProcess, parentDataSource, currProcess,
new HashMap<String, Object>(), null, null); new HashMap<>(), null, null);
return new TestContext(entityAttrs, delegate, entityFields, parent == null); return new TestContext(entityAttrs, delegate, entityFields, parent == null);
} }
@ -155,15 +155,7 @@ public abstract class AbstractDataImportHandlerTestCase extends
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Map createMap(Object... args) { public static Map createMap(Object... args) {
Map result = new LinkedHashMap(); return Utils.makeMap(args);
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;
} }
@SuppressForbidden(reason = "Needs currentTimeMillis to set modified time for a file") @SuppressForbidden(reason = "Needs currentTimeMillis to set modified time for a file")

View File

@ -16,13 +16,13 @@
*/ */
package org.apache.solr.handler.dataimport; package org.apache.solr.handler.dataimport;
import org.junit.Test;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Test;
/** /**
* <p> Test for XPathRecordReader </p> * <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>> a = new ArrayList<>();
final List<Map<String, Object>> x = new ArrayList<>(); final List<Map<String, Object>> x = new ArrayList<>();
rr.streamRecords(new StringReader(xml), new XPathRecordReader.Handler() { rr.streamRecords(new StringReader(xml), (record, xpath) -> {
@Override
public void handle(Map<String, Object> record, String xpath) {
if (record == null) return; if (record == null) return;
if (xpath.equals("/root/a")) a.add(record); if (xpath.equals("/root/a")) a.add(record);
if (xpath.equals("/root/x")) x.add(record); if (xpath.equals("/root/x")) x.add(record);
}
}); });
assertEquals(1, a.size()); assertEquals(1, a.size());