Source:
private Set<ProtectedStorageEntry> getFilteredProtectedStorageEntries(GetDataRequest getDataRequest, Connection connection) { final Set<ProtectedStorageEntry> filteredDataSet = new HashSet<>(); final Set<Integer> lookupSet = new HashSet<>(); AtomicInteger maxSize = new AtomicInteger(MAX_ENTRIES); Set<P2PDataStorage.ByteArray> excludedKeysAsByteArray = P2PDataStorage.ByteArray.convertBytesSetToByteArraySet(getDataRequest.getExcludedKeys()); Set<ProtectedStorageEntry> filteredSet = dataStorage.getMap().entrySet().stream() .filter(e -> !excludedKeysAsByteArray.contains(e.getKey())) .filter(e -> maxSize.decrementAndGet() >= 0) .map(Map.Entry::getValue) .collect(Collectors.toSet()); if (maxSize.get() <= 0) { log.warn("The peer request caused too much ProtectedStorageEntry entries to get delivered. We limited the entries for the response to entries", MAX_ENTRIES); } log.info("getFilteredProtectedStorageEntries " + filteredSet.size()); for (ProtectedStorageEntry protectedStorageEntry : filteredSet) { final ProtectedStoragePayload protectedStoragePayload = protectedStorageEntry.getProtectedStoragePayload(); boolean doAdd = false; if (protectedStoragePayload instanceof CapabilityRequiringPayload) { if (connection.getCapabilities().containsAll(((CapabilityRequiringPayload) protectedStoragePayload).getRequiredCapabilities())) doAdd = true; else log.debug("We do not send the message to the peer because they do not support the required capability for that message type.\n" + "storagePayload is: " + Utilities.toTruncatedString(protectedStoragePayload)); } else { doAdd = true; } if (doAdd) { boolean notContained = lookupSet.add(protectedStoragePayload.hashCode()); if (notContained) filteredDataSet.add(protectedStorageEntry); } } log.info("ProtectedStorageEntry set contains entries ", filteredDataSet.size()); return filteredDataSet; }

Target:
private Set<ProtectedStorageEntry> getFilteredProtectedStorageEntries(GetDataRequest getDataRequest, Connection connection) { Set<ProtectedStorageEntry> filteredDataSet = new HashSet<>(); Set<Integer> lookupSet = new HashSet<>(); String connectionInfo = "connectionInfo" + connection.getPeersNodeAddressOptional() .map(e -> "node address " + e.getFullAddress()) .orElseGet(() -> "connection UID " + connection.getUid()); AtomicInteger maxSize = new AtomicInteger(MAX_ENTRIES); Set<P2PDataStorage.ByteArray> excludedKeysAsByteArray = P2PDataStorage.ByteArray.convertBytesSetToByteArraySet(getDataRequest.getExcludedKeys()); Set<ProtectedStorageEntry> filteredSet = dataStorage.getMap().entrySet().stream() .filter(e -> !excludedKeysAsByteArray.contains(e.getKey())) .filter(e -> maxSize.decrementAndGet() >= 0) .map(Map.Entry::getValue) .collect(Collectors.toSet()); if (maxSize.get() <= 0) { log.warn("The getData request from peer with caused too much ProtectedStorageEntry " + "entries to get delivered. We limited the entries for the response to entries", connectionInfo, MAX_ENTRIES); } log.info("getFilteredProtectedStorageEntries " + filteredSet.size()); for (ProtectedStorageEntry protectedStorageEntry : filteredSet) { final ProtectedStoragePayload protectedStoragePayload = protectedStorageEntry.getProtectedStoragePayload(); boolean doAdd = false; if (protectedStoragePayload instanceof CapabilityRequiringPayload) { if (connection.getCapabilities().containsAll(((CapabilityRequiringPayload) protectedStoragePayload).getRequiredCapabilities())) doAdd = true; else log.debug("We do not send the message to the peer because they do not support the required capability for that message type.\n" + "storagePayload is: " + Utilities.toTruncatedString(protectedStoragePayload)); } else { doAdd = true; } if (doAdd) { boolean notContained = lookupSet.add(protectedStoragePayload.hashCode()); if (notContained) filteredDataSet.add(protectedStorageEntry); } } log.info("The getData request from peer with contains ProtectedStorageEntry entries ", connectionInfo, filteredDataSet.size()); return filteredDataSet; }