Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
freimair committed May 22, 2020
1 parent ee5b93b commit 198bc6a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
Expand Down Expand Up @@ -231,15 +230,14 @@ private byte[] getSpecialKey() {
* See if the request contains a "special key".
*
* @param knownPayloadHashes
* @throws NoSuchElementException if there is no "special key" in the list
* @return the "special key"
* @return the "special key" or <code>null</code> if no special key has been found
*/
private String containsSpecialKey(Set<P2PDataStorage.ByteArray> knownPayloadHashes) {
private String findSpecialKey(Set<P2PDataStorage.ByteArray> knownPayloadHashes) {
return knownPayloadHashes.stream()
.map(byteArray -> new String(byteArray.bytes).trim())
.filter(s -> s.matches("^[0-9]\\.[0-9]\\.[0-9]$"))
.findFirst()
.orElseThrow();
.orElse(null);
}

/**
Expand Down Expand Up @@ -317,11 +315,11 @@ public GetDataResponse buildGetDataResponse(
// In case we get a "new" data request, ie. with a "special key" like "1.3.4", we
// pre-filter the data. If there is no "special key", we use all data.
Map<ByteArray, PersistableNetworkPayload> prefilteredData;
try {
String specialKey = containsSpecialKey(excludedKeysAsByteArray);
prefilteredData = this.appendOnlyDataStoreService.getMap("since " + specialKey);
} catch (NoSuchElementException e) {
String specialKey = findSpecialKey(excludedKeysAsByteArray);
if (specialKey == null) {
prefilteredData = this.appendOnlyDataStoreService.getMap();
} else {
prefilteredData = this.appendOnlyDataStoreService.getMap("since " + specialKey);
}

Set<PersistableNetworkPayload> filteredPersistableNetworkPayloads =
Expand Down

0 comments on commit 198bc6a

Please sign in to comment.