diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/balance/BalanceModel.java b/core/src/main/java/bisq/core/dao/burningman/accounting/balance/BalanceModel.java index 920ee3baf7..4d94de6af5 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/balance/BalanceModel.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/balance/BalanceModel.java @@ -23,7 +23,6 @@ import bisq.core.dao.burningman.model.BurningManCandidate; import bisq.common.util.DateUtil; import java.util.Calendar; -import java.util.Collection; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; @@ -54,8 +53,7 @@ public class BalanceModel { receivedBtcBalanceEntries.add(balanceEntry); Date month = balanceEntry.getMonth(); - receivedBtcBalanceEntriesByMonth.putIfAbsent(month, new HashSet<>()); - receivedBtcBalanceEntriesByMonth.get(month).add(balanceEntry); + receivedBtcBalanceEntriesByMonth.computeIfAbsent(month, m -> new HashSet<>()).add(balanceEntry); } public Set getReceivedBtcBalanceEntries() { @@ -63,11 +61,7 @@ public class BalanceModel { } public Set getReceivedBtcBalanceEntriesByMonth(Date month) { - return receivedBtcBalanceEntriesByMonth.entrySet().stream() - .filter(e -> e.getKey().equals(month)) - .map(Map.Entry::getValue) - .flatMap(Collection::stream) - .collect(Collectors.toSet()); + return receivedBtcBalanceEntriesByMonth.getOrDefault(month, Set.of()); } public Stream getBurnedBsqBalanceEntries(Set burnOutputModels) { diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java index 0c070e928e..79f801485a 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java @@ -33,12 +33,15 @@ import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreService; import bisq.common.config.Config; import bisq.common.file.JsonFileManager; +import bisq.common.util.RangeUtils; import com.google.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import com.google.common.collect.Range; + import javafx.collections.FXCollections; import javafx.collections.ObservableSet; @@ -136,10 +139,10 @@ public class TradeStatisticsManager { } public List getTradeStatisticsList(long dateStart, long dateEnd) { - return observableTradeStatisticsSet.stream() - .filter(x -> x.getDateAsLong() > dateStart && x.getDateAsLong() <= dateEnd) - .sorted((o1, o2) -> (Long.compare(o2.getDateAsLong(), o1.getDateAsLong()))) - .collect(Collectors.toList()); + return new ArrayList<>(RangeUtils.subSet(navigableTradeStatisticsSet) + .withKey(TradeStatistics3::getDateAsLong) + .overRange(Range.openClosed(Math.min(dateStart, dateEnd), dateEnd)) + .descendingSet()); } private void maybeDumpStatistics() { diff --git a/daemon/src/main/java/bisq/daemon/grpc/interceptor/CallRateMeteringInterceptor.java b/daemon/src/main/java/bisq/daemon/grpc/interceptor/CallRateMeteringInterceptor.java index 5f1dfd5c13..79ef7aaef9 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/interceptor/CallRateMeteringInterceptor.java +++ b/daemon/src/main/java/bisq/daemon/grpc/interceptor/CallRateMeteringInterceptor.java @@ -103,8 +103,8 @@ public final class CallRateMeteringInterceptor implements ServerInterceptor { private Optional> getRateMeterKV(ServerCall serverCall) { String rateMeterKey = getRateMeterKey(serverCall); - return serviceCallRateMeters.entrySet().stream() - .filter((e) -> e.getKey().equals(rateMeterKey)).findFirst(); + return Optional.ofNullable(serviceCallRateMeters.get(rateMeterKey)) + .map(meter -> Map.entry(rateMeterKey, meter)); } private String getRateMeterKey(ServerCall serverCall) { diff --git a/restapi/src/main/java/bisq/restapi/endpoints/ExplorerTransactionsApi.java b/restapi/src/main/java/bisq/restapi/endpoints/ExplorerTransactionsApi.java index 3ce58aabdf..2e48b61269 100644 --- a/restapi/src/main/java/bisq/restapi/endpoints/ExplorerTransactionsApi.java +++ b/restapi/src/main/java/bisq/restapi/endpoints/ExplorerTransactionsApi.java @@ -22,11 +22,10 @@ import bisq.core.dao.state.model.blockchain.BaseTx; import bisq.core.dao.state.model.blockchain.Tx; import bisq.core.dao.state.model.blockchain.TxType; -import java.util.Collection; import java.util.Comparator; import java.util.List; -import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; @@ -86,10 +85,7 @@ public class ExplorerTransactionsApi { address = address.substring(1, address.length()); } String finalAddress = address; - List result = daoStateService.getTxIdSetByAddress().entrySet().stream() - .filter(e -> e.getKey().equals(finalAddress)) - .map(Map.Entry::getValue) - .flatMap(Collection::stream) + List result = daoStateService.getTxIdSetByAddress().getOrDefault(finalAddress, Set.of()).stream() .flatMap(txId -> daoStateService.getTx(txId).stream()) .map(tx -> BlockDataToJsonConverter.getJsonTx(daoStateService, tx)) .collect(Collectors.toList());