Package org.openstreetmap.josm.data.osm
Class ChangesetCache
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.ChangesetCache
-
- All Implemented Interfaces:
PreferenceChangedListener
public final class ChangesetCache extends java.lang.Object implements PreferenceChangedListener
ChangesetCache is global in-memory cache for changesets downloaded from an OSM API server. The unique instance is available as singleton, seegetInstance(). Clients interested in cache updates can register forChangesetCacheEvents usingaddChangesetCacheListener(ChangesetCacheListener). They can useremoveChangesetCacheListener(ChangesetCacheListener)to unregister as cache event listener. The cache itself listens toPreferenceChangeEvents. It clears itself if the OSM API URL is changed in the preferences.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,Changeset>cachethe cached changesetsprivate static ChangesetCacheINSTANCEthe unique instance(package private) java.util.concurrent.CopyOnWriteArrayList<ChangesetCacheListener>listeners
-
Constructor Summary
Constructors Modifier Constructor Description privateChangesetCache()Constructs a newChangesetCache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangesetCacheListener(ChangesetCacheListener listener)Add a changeset cache listener.voidclear()Clears the cache.booleancontains(int id)Determines if the cache contains an entry for given changeset identifier.booleancontains(Changeset cs)Determines if the cache contains an entry for given changeset.private voidfireChangesetCacheEvent(ChangesetCacheEvent e)Changesetget(int id)Returns the entry for given changeset identifier.java.util.Set<Changeset>getChangesets()Returns the set of changesets contained in the cache.static ChangesetCachegetInstance()Replies the unique instance of the cachejava.util.List<Changeset>getOpenChangesets()Replies the list of open changesets.java.util.List<Changeset>getOpenChangesetsForCurrentUser()voidpreferenceChanged(PreferenceChangeEvent e)Triggered when a preference entry value changes.voidrefreshChangesetsFromServer()Refreshes the changesets from the server.voidremove(int id)Remove the entry for the given changeset identifier.private voidremove(int id, DefaultChangesetCacheEvent e)voidremove(java.util.Collection<Changeset> changesets)Removes the changesets inchangesetsfrom the cache.voidremove(Changeset cs)Remove the entry for the given changeset.voidremoveChangesetCacheListener(ChangesetCacheListener listener)Remove a changeset cache listener.intsize()Returns the number of changesets contained in the cache.voidupdate(java.util.Collection<Changeset> changesets)Update a collection of changesets.voidupdate(Changeset cs)Update a single changeset.private voidupdate(Changeset cs, DefaultChangesetCacheEvent e)
-
-
-
Field Detail
-
INSTANCE
private static final ChangesetCache INSTANCE
the unique instance
-
listeners
final java.util.concurrent.CopyOnWriteArrayList<ChangesetCacheListener> listeners
-
-
Constructor Detail
-
ChangesetCache
private ChangesetCache()
Constructs a newChangesetCache.
-
-
Method Detail
-
getInstance
public static ChangesetCache getInstance()
Replies the unique instance of the cache- Returns:
- the unique instance of the cache
-
addChangesetCacheListener
public void addChangesetCacheListener(ChangesetCacheListener listener)
Add a changeset cache listener.- Parameters:
listener- changeset cache listener to add
-
removeChangesetCacheListener
public void removeChangesetCacheListener(ChangesetCacheListener listener)
Remove a changeset cache listener.- Parameters:
listener- changeset cache listener to remove
-
fireChangesetCacheEvent
private void fireChangesetCacheEvent(ChangesetCacheEvent e)
-
update
private void update(Changeset cs, DefaultChangesetCacheEvent e)
-
update
public void update(Changeset cs)
Update a single changeset.- Parameters:
cs- changeset to update
-
update
public void update(java.util.Collection<Changeset> changesets)
Update a collection of changesets.- Parameters:
changesets- changesets to update
-
contains
public boolean contains(int id)
Determines if the cache contains an entry for given changeset identifier.- Parameters:
id- changeset id- Returns:
trueif the cache contains an entry forid
-
contains
public boolean contains(Changeset cs)
Determines if the cache contains an entry for given changeset.- Parameters:
cs- changeset- Returns:
trueif the cache contains an entry forcs
-
get
public Changeset get(int id)
Returns the entry for given changeset identifier.- Parameters:
id- changeset id- Returns:
- the entry for given changeset identifier, or null
-
getChangesets
public java.util.Set<Changeset> getChangesets()
Returns the set of changesets contained in the cache.- Returns:
- the set of changesets contained in the cache
-
remove
private void remove(int id, DefaultChangesetCacheEvent e)
-
remove
public void remove(int id)
Remove the entry for the given changeset identifier. AChangesetCacheEventis fired.- Parameters:
id- changeset id
-
remove
public void remove(Changeset cs)
Remove the entry for the given changeset. AChangesetCacheEventis fired.- Parameters:
cs- changeset
-
remove
public void remove(java.util.Collection<Changeset> changesets)
Removes the changesets inchangesetsfrom the cache. AChangesetCacheEventis fired.- Parameters:
changesets- the changesets to remove. Ignored if null.
-
size
public int size()
Returns the number of changesets contained in the cache.- Returns:
- the number of changesets contained in the cache
-
clear
public void clear()
Clears the cache.
-
getOpenChangesets
public java.util.List<Changeset> getOpenChangesets()
Replies the list of open changesets.- Returns:
- The list of open changesets
-
getOpenChangesetsForCurrentUser
public java.util.List<Changeset> getOpenChangesetsForCurrentUser()
If the current useris known, theopen changesetsfor thecurrent userare returned. Otherwise, the unfilteredopen changesetsare returned.- Returns:
- a list of changesets
-
refreshChangesetsFromServer
public void refreshChangesetsFromServer() throws OsmTransferException
Refreshes the changesets from the server.The server automatically closes changesets after a timeout. We don't get notified of this fact when it happens. This method requests a fresh list from the server and updates the local list. Calling this method reduces (but does not eliminate) the probability of attempting an upload to an already closed changeset.
- Throws:
OsmTransferException- on server error
-
preferenceChanged
public void preferenceChanged(PreferenceChangeEvent e)
Description copied from interface:PreferenceChangedListenerTriggered when a preference entry value changes.- Specified by:
preferenceChangedin interfacePreferenceChangedListener- Parameters:
e- the preference change event
-
-