Package org.openstreetmap.josm.data.osm
Class ChangesetCache
java.lang.Object
org.openstreetmap.josm.data.osm.ChangesetCache
- All Implemented Interfaces:
PreferenceChangedListener
ChangesetCache is global in-memory cache for changesets downloaded from
an OSM API server. The unique instance is available as singleton, see
getInstance().
Clients interested in cache updates can register for ChangesetCacheEvents
using addChangesetCacheListener(ChangesetCacheListener). They can use
removeChangesetCacheListener(ChangesetCacheListener) to unregister as
cache event listener.
The cache itself listens to PreferenceChangeEvents. It
clears itself if the OSM API URL is changed in the preferences.-
Field Summary
FieldsModifier and TypeFieldDescriptionthe cached changesetsprivate static final ChangesetCachethe unique instance(package private) final CopyOnWriteArrayList<ChangesetCacheListener> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a changeset cache listener.voidclear()Clears the cache.booleancontains(int id) Determines if the cache contains an entry for given changeset identifier.booleanDetermines if the cache contains an entry for given changeset.private voidget(int id) Returns the entry for given changeset identifier.Returns the set of changesets contained in the cache.static ChangesetCacheReplies the unique instance of the cacheReplies the list of open changesets.voidTriggered when a preference entry value changes.voidRefreshes the changesets from the server.voidremove(int id) Remove the entry for the given changeset identifier.private voidremove(int id, DefaultChangesetCacheEvent e) voidremove(Collection<Changeset> changesets) Removes the changesets inchangesetsfrom the cache.voidRemove the entry for the given changeset.voidRemove a changeset cache listener.intsize()Returns the number of changesets contained in the cache.voidupdate(Collection<Changeset> changesets) Update a collection of changesets.voidUpdate a single changeset.private void
-
Field Details
-
INSTANCE
the unique instance -
cache
the cached changesets -
listeners
-
-
Constructor Details
-
ChangesetCache
private ChangesetCache()Constructs a newChangesetCache.
-
-
Method Details
-
getInstance
Replies the unique instance of the cache- Returns:
- the unique instance of the cache
-
addChangesetCacheListener
Add a changeset cache listener.- Parameters:
listener- changeset cache listener to add
-
removeChangesetCacheListener
Remove a changeset cache listener.- Parameters:
listener- changeset cache listener to remove
-
fireChangesetCacheEvent
-
update
-
update
Update a single changeset.- Parameters:
cs- changeset to update
-
update
Update a collection of changesets.- Parameters:
changesets- changesets to update
-
contains
Determines if the cache contains an entry for given changeset identifier.- Parameters:
id- changeset id- Returns:
trueif the cache contains an entry forid
-
contains
Determines if the cache contains an entry for given changeset.- Parameters:
cs- changeset- Returns:
trueif the cache contains an entry forcs
-
get
Returns the entry for given changeset identifier.- Parameters:
id- changeset id- Returns:
- the entry for given changeset identifier, or null
-
getChangesets
Returns the set of changesets contained in the cache.- Returns:
- the set of changesets contained in the cache
-
remove
-
remove
Remove the entry for the given changeset identifier. AChangesetCacheEventis fired.- Parameters:
id- changeset id
-
remove
Remove the entry for the given changeset. AChangesetCacheEventis fired.- Parameters:
cs- changeset
-
remove
Removes the changesets inchangesetsfrom the cache. AChangesetCacheEventis fired.- Parameters:
changesets- the changesets to remove. Ignored if null.
-
size
Returns the number of changesets contained in the cache.- Returns:
- the number of changesets contained in the cache
-
clear
Clears the cache. -
getOpenChangesets
Replies the list of open changesets.- Returns:
- The list of open changesets
-
getOpenChangesetsForCurrentUser
If the current useris known, theopen changesetsfor thecurrent userare returned. Otherwise, the unfilteredopen changesetsare returned.- Returns:
- a list of changesets
-
refreshChangesetsFromServer
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
Description copied from interface:PreferenceChangedListenerTriggered when a preference entry value changes.- Specified by:
preferenceChangedin interfacePreferenceChangedListener- Parameters:
e- the preference change event
-