use Predicate
This commit is contained in:
@@ -8,7 +8,7 @@ import ru.trader.core.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.concurrent.RecursiveAction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
||||
this.scorer = scorer;
|
||||
}
|
||||
|
||||
public VendorsCrawler crawler(Function<List<Edge<Vendor>>, Boolean> onFoundFunc){
|
||||
public VendorsCrawler crawler(Predicate<List<Edge<Vendor>>> onFoundFunc){
|
||||
return new VendorsCrawler(onFoundFunc);
|
||||
}
|
||||
|
||||
public VendorsCrawler crawler(Function<Edge<Vendor>, Boolean> isFoundFunc,Function<List<Edge<Vendor>>, Boolean> onFoundFunc){
|
||||
public VendorsCrawler crawler(Predicate<Edge<Vendor>> isFoundFunc,Predicate<List<Edge<Vendor>>> onFoundFunc){
|
||||
return new VendorsCrawler(isFoundFunc, onFoundFunc);
|
||||
}
|
||||
|
||||
@@ -470,13 +470,13 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
||||
private double startFuel;
|
||||
private double startBalance;
|
||||
|
||||
protected VendorsCrawler(Function<List<Edge<Vendor>>, Boolean> onFoundFunc) {
|
||||
protected VendorsCrawler(Predicate<List<Edge<Vendor>>> onFoundFunc) {
|
||||
super(VendorsGraph.this, onFoundFunc);
|
||||
startFuel = getShip().getTank();
|
||||
startBalance = getProfile().getBalance();
|
||||
}
|
||||
|
||||
protected VendorsCrawler(Function<Edge<Vendor>, Boolean> isFoundFunc, Function<List<Edge<Vendor>>, Boolean> onFoundFunc) {
|
||||
protected VendorsCrawler(Predicate<Edge<Vendor>> isFoundFunc, Predicate<List<Edge<Vendor>>> onFoundFunc) {
|
||||
super(VendorsGraph.this, isFoundFunc, onFoundFunc);
|
||||
startFuel = getShip().getTank();
|
||||
startBalance = getProfile().getBalance();
|
||||
|
||||
@@ -8,19 +8,19 @@ import ru.trader.graph.Connectable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CCrawler<T extends Connectable<T>> extends Crawler<T> {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(CCrawler.class);
|
||||
private double startFuel;
|
||||
|
||||
public CCrawler(ConnectibleGraph<T> graph, Function<List<Edge<T>>, Boolean> onFoundFunc) {
|
||||
public CCrawler(ConnectibleGraph<T> graph, Predicate<List<Edge<T>>> onFoundFunc) {
|
||||
super(graph, onFoundFunc);
|
||||
startFuel = getShip().getTank();
|
||||
}
|
||||
|
||||
public CCrawler(ConnectibleGraph<T> graph, Function<Edge<T>, Boolean> isFoundFunc, Function<List<Edge<T>>, Boolean> onFoundFunc) {
|
||||
public CCrawler(ConnectibleGraph<T> graph, Predicate<Edge<T>> isFoundFunc, Predicate<List<Edge<T>>> onFoundFunc) {
|
||||
super(graph, isFoundFunc, onFoundFunc);
|
||||
startFuel = getShip().getTank();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import ru.trader.analysis.LimitedQueue;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.RecursiveAction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class Crawler<T> {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(Crawler.class);
|
||||
@@ -17,19 +17,19 @@ public class Crawler<T> {
|
||||
private final static int SPLIT_SIZE = 3;
|
||||
|
||||
protected final Graph<T> graph;
|
||||
private final Function<List<Edge<T>>,Boolean> onFoundFunc;
|
||||
private final Function<Edge<T>,Boolean> isFound;
|
||||
private final Predicate<List<Edge<T>>> onFoundFunc;
|
||||
private final Predicate<Edge<T>> isFound;
|
||||
private T target;
|
||||
private int maxSize;
|
||||
|
||||
public Crawler(Graph<T> graph, Function<List<Edge<T>>, Boolean> onFoundFunc) {
|
||||
public Crawler(Graph<T> graph, Predicate<List<Edge<T>>> onFoundFunc) {
|
||||
this.graph = graph;
|
||||
maxSize = graph.getRoot().getLevel();
|
||||
this.onFoundFunc = onFoundFunc;
|
||||
this.isFound = this::isTarget;
|
||||
}
|
||||
|
||||
public Crawler(Graph<T> graph, Function<Edge<T>,Boolean> isFoundFunc, Function<List<Edge<T>>,Boolean> onFoundFunc) {
|
||||
public Crawler(Graph<T> graph, Predicate<Edge<T>> isFoundFunc, Predicate<List<Edge<T>>> onFoundFunc) {
|
||||
this.graph = graph;
|
||||
maxSize = graph.getRoot().getLevel();
|
||||
this.onFoundFunc = onFoundFunc;
|
||||
@@ -59,7 +59,7 @@ public class Crawler<T> {
|
||||
}
|
||||
|
||||
protected boolean isFound(Edge<T> edge){
|
||||
return isFound.apply(edge);
|
||||
return isFound.test(edge);
|
||||
}
|
||||
|
||||
public int getMaxSize() {
|
||||
@@ -161,7 +161,7 @@ public class Crawler<T> {
|
||||
List<Edge<T>> res = getCopyList(entry, next);
|
||||
LOG.debug("Last edge found, path {}", res);
|
||||
found++;
|
||||
if (!onFoundFunc.apply(res)){
|
||||
if (!onFoundFunc.test(res)){
|
||||
stop = true;
|
||||
}
|
||||
break;
|
||||
@@ -202,7 +202,7 @@ public class Crawler<T> {
|
||||
List<Edge<T>> res = getCopyList(entry, edge);
|
||||
LOG.debug("Last edge found, path {}", res);
|
||||
found++;
|
||||
if (!onFoundFunc.apply(res)){
|
||||
if (!onFoundFunc.test(res)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ public class Crawler<T> {
|
||||
List<Edge<T>> res = entry.toEdges();
|
||||
LOG.debug("Path found {}", res);
|
||||
found++;
|
||||
if (!onFoundFunc.apply(res)){
|
||||
if (!onFoundFunc.test(res)){
|
||||
break;
|
||||
}
|
||||
if (found >= count) break;
|
||||
@@ -281,7 +281,7 @@ public class Crawler<T> {
|
||||
List<Edge<T>> res = entry.toEdges();
|
||||
LOG.trace("Path found {}", res);
|
||||
found++;
|
||||
if (!onFoundFunc.apply(res)){
|
||||
if (!onFoundFunc.test(res)){
|
||||
break;
|
||||
}
|
||||
if (found >= count) break;
|
||||
|
||||
Reference in New Issue
Block a user