Update PersistableNetworkPayloadStore

This commit is contained in:
chimp1984 2020-10-01 17:25:19 -05:00
parent 5a1cd0ee2c
commit e2f0f61943
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -22,16 +22,30 @@ import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
import bisq.common.proto.persistable.PersistableEnvelope;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
/**
* Base class for store implementations using a map with a PersistableNetworkPayload
* as the type of the map value.
* Store for PersistableNetworkPayload map entries with it's data hash as key.
*/
public abstract class PersistableNetworkPayloadStore implements PersistableEnvelope {
@Slf4j
public abstract class PersistableNetworkPayloadStore<T extends PersistableNetworkPayload> implements PersistableEnvelope {
@Getter
public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
protected final Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
protected PersistableNetworkPayloadStore() {
}
protected PersistableNetworkPayloadStore(Collection<T> collection) {
collection.forEach(item -> map.put(new P2PDataStorage.ByteArray(item.getHash()), item));
}
public boolean containsKey(P2PDataStorage.ByteArray hash) {
return map.containsKey(hash);
}
}