3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 23:32:16 +00:00

Add two new WalletExtension access methods.

This commit is contained in:
Matt Corallo 2013-06-05 16:59:52 +02:00 committed by Mike Hearn
parent a3f1fe5390
commit c9d411e8e7

View File

@ -3122,6 +3122,41 @@ public class Wallet implements Serializable, BlockChainListener {
if (extensions.containsKey(id)) if (extensions.containsKey(id))
throw new IllegalStateException("Cannot add two extensions with the same ID: " + id); throw new IllegalStateException("Cannot add two extensions with the same ID: " + id);
extensions.put(id, extension); extensions.put(id, extension);
invokeOnWalletChanged();
} finally {
lock.unlock();
}
}
/**
* Atomically adds extension or returns an existing extension if there is one with the same id alreadypresent.
*/
public WalletExtension addOrGetExistingExtension(WalletExtension extension) {
String id = checkNotNull(extension).getWalletExtensionID();
lock.lock();
try {
WalletExtension previousExtension = extensions.get(id);
if (previousExtension != null)
return previousExtension;
extensions.put(id, extension);
invokeOnWalletChanged();
return extension;
} finally {
lock.unlock();
}
}
/**
* Either adds extension as a new extension or replaces the existing extension if one already exists with the same
* id. This also calls onWalletChanged, triggering wallet saving, so may be useful even when called with the same
* extension as is already present.
*/
public void addOrUpdateExtension(WalletExtension extension) {
String id = checkNotNull(extension).getWalletExtensionID();
lock.lock();
try {
extensions.put(id, extension);
invokeOnWalletChanged();
} finally { } finally {
lock.unlock(); lock.unlock();
} }