Refactoring: Rearrange method (moved method)

This commit is contained in:
chimp1984 2020-10-01 15:12:15 -05:00
parent 62836d79f5
commit 58efb62b84
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -223,36 +223,6 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
return excludedKeys;
}
/**
* Generic function that can be used to filter a Map<ByteArray, ProtectedStorageEntry || PersistableNetworkPayload>
* by a given set of keys and peer capabilities.
*/
static private <T extends NetworkPayload> Set<T> filterKnownHashes(
Map<ByteArray, T> mapToFilter,
Function<T, ? extends NetworkPayload> objToPayloadFunction,
Set<ByteArray> knownHashes,
Capabilities peerCapabilities,
int maxEntries,
AtomicBoolean wasTruncated) {
AtomicInteger limit = new AtomicInteger(maxEntries);
Set<T> filteredResults = mapToFilter.entrySet().stream()
.filter(e -> !knownHashes.contains(e.getKey()))
.filter(e -> limit.decrementAndGet() >= 0)
.map(Map.Entry::getValue)
.filter(networkPayload -> shouldTransmitPayloadToPeer(peerCapabilities,
objToPayloadFunction.apply(networkPayload)))
.collect(Collectors.toSet());
if (limit.get() < 0) {
wasTruncated.set(true);
}
return filteredResults;
}
/**
* Returns a GetDataResponse object that contains the Payloads known locally, but not remotely.
*/
@ -345,6 +315,35 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
return map;
}
/**
* Generic function that can be used to filter a Map<ByteArray, ProtectedStorageEntry || PersistableNetworkPayload>
* by a given set of keys and peer capabilities.
*/
static private <T extends NetworkPayload> Set<T> filterKnownHashes(
Map<ByteArray, T> mapToFilter,
Function<T, ? extends NetworkPayload> objToPayloadFunction,
Set<ByteArray> knownHashes,
Capabilities peerCapabilities,
int maxEntries,
AtomicBoolean wasTruncated) {
AtomicInteger limit = new AtomicInteger(maxEntries);
Set<T> filteredResults = mapToFilter.entrySet().stream()
.filter(e -> !knownHashes.contains(e.getKey()))
.filter(e -> limit.decrementAndGet() >= 0)
.map(Map.Entry::getValue)
.filter(networkPayload -> shouldTransmitPayloadToPeer(peerCapabilities,
objToPayloadFunction.apply(networkPayload)))
.collect(Collectors.toSet());
if (limit.get() < 0) {
wasTruncated.set(true);
}
return filteredResults;
}
private Set<byte[]> getKeysAsByteSet(Map<ByteArray, ? extends PersistablePayload> map) {
return map.keySet().stream()
.map(e -> e.bytes)