From a1f03699fda37360ab27859580b5678d9a4a1c87 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Thu, 16 Jul 2015 13:20:11 +0300 Subject: [PATCH] use Predicate --- .../java/ru/trader/analysis/VendorsGraph.java | 10 +++++----- .../ru/trader/analysis/graph/CCrawler.java | 6 +++--- .../ru/trader/analysis/graph/Crawler.java | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/ru/trader/analysis/VendorsGraph.java b/core/src/main/java/ru/trader/analysis/VendorsGraph.java index ba43637..aa788b3 100644 --- a/core/src/main/java/ru/trader/analysis/VendorsGraph.java +++ b/core/src/main/java/ru/trader/analysis/VendorsGraph.java @@ -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 { this.scorer = scorer; } - public VendorsCrawler crawler(Function>, Boolean> onFoundFunc){ + public VendorsCrawler crawler(Predicate>> onFoundFunc){ return new VendorsCrawler(onFoundFunc); } - public VendorsCrawler crawler(Function, Boolean> isFoundFunc,Function>, Boolean> onFoundFunc){ + public VendorsCrawler crawler(Predicate> isFoundFunc,Predicate>> onFoundFunc){ return new VendorsCrawler(isFoundFunc, onFoundFunc); } @@ -470,13 +470,13 @@ public class VendorsGraph extends ConnectibleGraph { private double startFuel; private double startBalance; - protected VendorsCrawler(Function>, Boolean> onFoundFunc) { + protected VendorsCrawler(Predicate>> onFoundFunc) { super(VendorsGraph.this, onFoundFunc); startFuel = getShip().getTank(); startBalance = getProfile().getBalance(); } - protected VendorsCrawler(Function, Boolean> isFoundFunc, Function>, Boolean> onFoundFunc) { + protected VendorsCrawler(Predicate> isFoundFunc, Predicate>> onFoundFunc) { super(VendorsGraph.this, isFoundFunc, onFoundFunc); startFuel = getShip().getTank(); startBalance = getProfile().getBalance(); diff --git a/core/src/main/java/ru/trader/analysis/graph/CCrawler.java b/core/src/main/java/ru/trader/analysis/graph/CCrawler.java index 9c2aa2e..dc9e94f 100644 --- a/core/src/main/java/ru/trader/analysis/graph/CCrawler.java +++ b/core/src/main/java/ru/trader/analysis/graph/CCrawler.java @@ -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> extends Crawler { private final static Logger LOG = LoggerFactory.getLogger(CCrawler.class); private double startFuel; - public CCrawler(ConnectibleGraph graph, Function>, Boolean> onFoundFunc) { + public CCrawler(ConnectibleGraph graph, Predicate>> onFoundFunc) { super(graph, onFoundFunc); startFuel = getShip().getTank(); } - public CCrawler(ConnectibleGraph graph, Function, Boolean> isFoundFunc, Function>, Boolean> onFoundFunc) { + public CCrawler(ConnectibleGraph graph, Predicate> isFoundFunc, Predicate>> onFoundFunc) { super(graph, isFoundFunc, onFoundFunc); startFuel = getShip().getTank(); } diff --git a/core/src/main/java/ru/trader/analysis/graph/Crawler.java b/core/src/main/java/ru/trader/analysis/graph/Crawler.java index 9de9064..ae6efbc 100644 --- a/core/src/main/java/ru/trader/analysis/graph/Crawler.java +++ b/core/src/main/java/ru/trader/analysis/graph/Crawler.java @@ -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 { private final static Logger LOG = LoggerFactory.getLogger(Crawler.class); @@ -17,19 +17,19 @@ public class Crawler { private final static int SPLIT_SIZE = 3; protected final Graph graph; - private final Function>,Boolean> onFoundFunc; - private final Function,Boolean> isFound; + private final Predicate>> onFoundFunc; + private final Predicate> isFound; private T target; private int maxSize; - public Crawler(Graph graph, Function>, Boolean> onFoundFunc) { + public Crawler(Graph graph, Predicate>> onFoundFunc) { this.graph = graph; maxSize = graph.getRoot().getLevel(); this.onFoundFunc = onFoundFunc; this.isFound = this::isTarget; } - public Crawler(Graph graph, Function,Boolean> isFoundFunc, Function>,Boolean> onFoundFunc) { + public Crawler(Graph graph, Predicate> isFoundFunc, Predicate>> onFoundFunc) { this.graph = graph; maxSize = graph.getRoot().getLevel(); this.onFoundFunc = onFoundFunc; @@ -59,7 +59,7 @@ public class Crawler { } protected boolean isFound(Edge edge){ - return isFound.apply(edge); + return isFound.test(edge); } public int getMaxSize() { @@ -161,7 +161,7 @@ public class Crawler { List> 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 { List> 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 { List> 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 { List> res = entry.toEdges(); LOG.trace("Path found {}", res); found++; - if (!onFoundFunc.apply(res)){ + if (!onFoundFunc.test(res)){ break; } if (found >= count) break;