mirror of
https://github.com/bisq-network/bisq.git
synced 2025-01-19 05:44:05 +01:00
Replace Predicate<Long> with LongPredicate in *ChartDataModel
Use the slightly more efficient primitive type specialisation for the date filters in 'ChartDataModel' and its subclasses.
This commit is contained in:
parent
d97636eaad
commit
e584c77f9e
@ -26,14 +26,14 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.LongPredicate;
|
||||
import java.util.function.ToLongFunction;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class ChartDataModel extends ActivatableDataModel {
|
||||
protected final TemporalAdjusterModel temporalAdjusterModel = new TemporalAdjusterModel();
|
||||
protected Predicate<Long> dateFilter = e -> true;
|
||||
protected LongPredicate dateFilter = e -> true;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -76,7 +76,7 @@ public abstract class ChartDataModel extends ActivatableDataModel {
|
||||
// Date filter predicate
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public Predicate<Long> getDateFilter() {
|
||||
public LongPredicate getDateFilter() {
|
||||
return dateFilter;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongPredicate;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -238,7 +239,7 @@ public class PriceChartDataModel extends ChartDataModel {
|
||||
private Map<Long, Double> getPriceByInterval(Collection<TradeStatistics3> collection,
|
||||
Predicate<TradeStatistics3> collectionFilter,
|
||||
Function<TradeStatistics3, Long> groupByDateFunction,
|
||||
Predicate<Long> dateFilter,
|
||||
LongPredicate dateFilter,
|
||||
Function<List<TradeStatistics3>, Double> getAveragePriceFunction) {
|
||||
return collection.stream()
|
||||
.filter(collectionFilter)
|
||||
@ -274,7 +275,7 @@ public class PriceChartDataModel extends ChartDataModel {
|
||||
private Map<Long, Double> getBsqMarketCapByInterval(Collection<TradeStatistics3> tradeStatistics3s,
|
||||
Predicate<TradeStatistics3> collectionFilter,
|
||||
Function<TradeStatistics3, Long> groupByDateFunction,
|
||||
Predicate<Long> dateFilter,
|
||||
LongPredicate dateFilter,
|
||||
Function<List<TradeStatistics3>, Double> getAveragePriceFunction) {
|
||||
Map<Long, List<TradeStatistics3>> pricesGroupedByDate = tradeStatistics3s.stream()
|
||||
.filter(collectionFilter)
|
||||
|
@ -31,7 +31,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.LongPredicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -143,7 +143,7 @@ public class VolumeChartDataModel extends ChartDataModel {
|
||||
|
||||
private Map<Long, Long> getVolumeByInterval(Collection<TradeStatistics3> collection,
|
||||
Function<TradeStatistics3, Long> groupByDateFunction,
|
||||
Predicate<Long> dateFilter,
|
||||
LongPredicate dateFilter,
|
||||
Function<List<TradeStatistics3>, Long> getVolumeFunction) {
|
||||
return collection.stream()
|
||||
.collect(Collectors.groupingBy(groupByDateFunction))
|
||||
|
@ -41,7 +41,7 @@ import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.LongPredicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -322,7 +322,7 @@ public class DaoChartDataModel extends ChartDataModel {
|
||||
// Aggregated collection data by interval
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private Map<Long, Long> getIssuedBsqByInterval(Collection<Issuance> issuanceSet, Predicate<Long> dateFilter) {
|
||||
private Map<Long, Long> getIssuedBsqByInterval(Collection<Issuance> issuanceSet, LongPredicate dateFilter) {
|
||||
var allIssuedBsq = issuanceSet.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
issuance -> toTimeInterval(Instant.ofEpochMilli(blockTimeOfIssuanceFunction.apply(issuance))),
|
||||
@ -330,8 +330,7 @@ public class DaoChartDataModel extends ChartDataModel {
|
||||
return getDateFilteredMap(allIssuedBsq, dateFilter);
|
||||
}
|
||||
|
||||
private Map<Long, Long> getHistoricalIssuedBsqByInterval(Map<Long, Long> historicalData,
|
||||
Predicate<Long> dateFilter) {
|
||||
private Map<Long, Long> getHistoricalIssuedBsqByInterval(Map<Long, Long> historicalData, LongPredicate dateFilter) {
|
||||
return historicalData.entrySet().stream()
|
||||
.filter(e -> dateFilter.test(e.getKey()))
|
||||
.collect(Collectors.toMap(e -> toTimeInterval(Instant.ofEpochSecond(e.getKey())),
|
||||
@ -339,7 +338,7 @@ public class DaoChartDataModel extends ChartDataModel {
|
||||
Long::sum));
|
||||
}
|
||||
|
||||
private Map<Long, Long> getBurntBsqByInterval(Stream<Tx> txStream, Predicate<Long> dateFilter) {
|
||||
private Map<Long, Long> getBurntBsqByInterval(Stream<Tx> txStream, LongPredicate dateFilter) {
|
||||
var toTimeIntervalFn = toCachedTimeIntervalFn();
|
||||
var allBurntBsq = txStream.collect(Collectors.groupingBy(
|
||||
tx -> toTimeIntervalFn.applyAsLong(Instant.ofEpochMilli(tx.getTime())),
|
||||
@ -347,7 +346,7 @@ public class DaoChartDataModel extends ChartDataModel {
|
||||
return getDateFilteredMap(allBurntBsq, dateFilter);
|
||||
}
|
||||
|
||||
private Predicate<Long> getPostTagDateFilter() {
|
||||
private LongPredicate getPostTagDateFilter() {
|
||||
// We filter out old dates as it only makes sense since Nov 2021
|
||||
return date -> date >= TAG_DATE.getTimeInMillis() / 1000; // we use seconds
|
||||
}
|
||||
@ -371,7 +370,7 @@ public class DaoChartDataModel extends ChartDataModel {
|
||||
// Utils
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private static <V> Map<Long, V> getDateFilteredMap(Map<Long, V> map, Predicate<Long> dateFilter) {
|
||||
private static <V> Map<Long, V> getDateFilteredMap(Map<Long, V> map, LongPredicate dateFilter) {
|
||||
return map.entrySet().stream()
|
||||
.filter(e -> dateFilter.test(e.getKey()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (u, v) -> v, HashMap::new));
|
||||
|
Loading…
Reference in New Issue
Block a user