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 forChangesetCacheEvent
s usingaddChangesetCacheListener(ChangesetCacheListener)
. They can useremoveChangesetCacheListener(ChangesetCacheListener)
to unregister as cache event listener. The cache itself listens toPreferenceChangeEvent
s. 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>
cache
the cached changesetsprivate static ChangesetCache
INSTANCE
the unique instance(package private) java.util.concurrent.CopyOnWriteArrayList<ChangesetCacheListener>
listeners
-
Constructor Summary
Constructors Modifier Constructor Description private
ChangesetCache()
Constructs a newChangesetCache
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangesetCacheListener(ChangesetCacheListener listener)
Add a changeset cache listener.void
clear()
Clears the cache.boolean
contains(int id)
Determines if the cache contains an entry for given changeset identifier.boolean
contains(Changeset cs)
Determines if the cache contains an entry for given changeset.private void
fireChangesetCacheEvent(ChangesetCacheEvent e)
Changeset
get(int id)
Returns the entry for given changeset identifier.java.util.Set<Changeset>
getChangesets()
Returns the set of changesets contained in the cache.static ChangesetCache
getInstance()
Replies the unique instance of the cachejava.util.List<Changeset>
getOpenChangesets()
Replies the list of open changesets.java.util.List<Changeset>
getOpenChangesetsForCurrentUser()
void
preferenceChanged(PreferenceChangeEvent e)
Triggered when a preference entry value changes.void
refreshChangesetsFromServer()
Refreshes the changesets from the server.void
remove(int id)
Remove the entry for the given changeset identifier.private void
remove(int id, DefaultChangesetCacheEvent e)
void
remove(java.util.Collection<Changeset> changesets)
Removes the changesets inchangesets
from the cache.void
remove(Changeset cs)
Remove the entry for the given changeset.void
removeChangesetCacheListener(ChangesetCacheListener listener)
Remove a changeset cache listener.int
size()
Returns the number of changesets contained in the cache.void
update(java.util.Collection<Changeset> changesets)
Update a collection of changesets.void
update(Changeset cs)
Update a single changeset.private void
update(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:
true
if 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:
true
if 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. AChangesetCacheEvent
is fired.- Parameters:
id
- changeset id
-
remove
public void remove(Changeset cs)
Remove the entry for the given changeset. AChangesetCacheEvent
is fired.- Parameters:
cs
- changeset
-
remove
public void remove(java.util.Collection<Changeset> changesets)
Removes the changesets inchangesets
from the cache. AChangesetCacheEvent
is 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 changesets
for thecurrent user
are returned. Otherwise, the unfilteredopen changesets
are 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:PreferenceChangedListener
Triggered when a preference entry value changes.- Specified by:
preferenceChanged
in interfacePreferenceChangedListener
- Parameters:
e
- the preference change event
-
-