mirror of https://github.com/apache/lucene.git
SOLR-7377,SOLR-7524:Make Streaming Expressions Java 7 Compatible
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1679376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bbc8484653
commit
6503e980c3
|
@ -1,5 +1,7 @@
|
|||
package org.apache.solr.client.solrj.io.comp;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
||||
/*
|
||||
|
@ -22,6 +24,6 @@ import org.apache.solr.client.solrj.io.Tuple;
|
|||
/**
|
||||
* Interface for use with a comparator lambda
|
||||
*/
|
||||
public interface ComparatorLambda {
|
||||
public interface ComparatorLambda extends Serializable {
|
||||
public int compare(Tuple leftTuple, Tuple rightTuple);
|
||||
}
|
||||
|
|
|
@ -70,22 +70,21 @@ public class FieldComparator extends StreamComparator implements Comparator<Tupl
|
|||
*/
|
||||
private void assignComparator(){
|
||||
if(ComparatorOrder.DESCENDING == order){
|
||||
// What black magic is this type intersection??
|
||||
// Because this class is serializable we need to make sure the lambda is also serializable.
|
||||
// This can be done by providing this type intersection on the definition of the lambda.
|
||||
// Why not do it in the lambda interface? Functional Interfaces don't allow extends clauses
|
||||
comparator = (ComparatorLambda & Serializable)(leftTuple, rightTuple) -> {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftField);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightField);
|
||||
return rightComp.compareTo(leftComp);
|
||||
comparator = new ComparatorLambda() {
|
||||
public int compare(Tuple leftTuple, Tuple rightTuple) {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftField);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightField);
|
||||
return rightComp.compareTo(leftComp);
|
||||
}
|
||||
};
|
||||
}
|
||||
else{
|
||||
// See above for black magic reasoning.
|
||||
comparator = (ComparatorLambda & Serializable)(leftTuple, rightTuple) -> {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftField);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightField);
|
||||
return leftComp.compareTo(rightComp);
|
||||
comparator = new ComparatorLambda() {
|
||||
public int compare(Tuple leftTuple, Tuple rightTuple) {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftField);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightField);
|
||||
return leftComp.compareTo(rightComp);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,10 @@ public class StreamFactory implements Serializable {
|
|||
return this;
|
||||
}
|
||||
public String getCollectionZkHost(String collectionName){
|
||||
return this.collectionZkHosts.getOrDefault(collectionName, null);
|
||||
if(this.collectionZkHosts.containsKey(collectionName)){
|
||||
return this.collectionZkHosts.get(collectionName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String,Class> getStreamFunctions(){
|
||||
|
|
Loading…
Reference in New Issue