[2711] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.osm;
|
---|
| 3 |
|
---|
| 4 | import java.util.Collection;
|
---|
| 5 | import java.util.Collections;
|
---|
| 6 | import java.util.HashSet;
|
---|
| 7 | import java.util.Set;
|
---|
| 8 |
|
---|
[12189] | 9 | /**
|
---|
| 10 | * The default event implementation that is used to indicate a change in the {@link ChangesetCache}
|
---|
| 11 | */
|
---|
[9059] | 12 | public class DefaultChangesetCacheEvent implements ChangesetCacheEvent {
|
---|
[2711] | 13 |
|
---|
| 14 | private final Set<Changeset> added;
|
---|
| 15 | private final Set<Changeset> modified;
|
---|
| 16 | private final Set<Changeset> removed;
|
---|
| 17 | private final ChangesetCache source;
|
---|
| 18 |
|
---|
[12189] | 19 | /**
|
---|
| 20 | * Creates a basic, empty {@link ChangesetCacheEvent}
|
---|
| 21 | * @param source The source changeset
|
---|
| 22 | */
|
---|
[2711] | 23 | public DefaultChangesetCacheEvent(ChangesetCache source) {
|
---|
| 24 | this.source = source;
|
---|
[7005] | 25 | added = new HashSet<>();
|
---|
| 26 | modified = new HashSet<>();
|
---|
| 27 | removed = new HashSet<>();
|
---|
[2711] | 28 | }
|
---|
| 29 |
|
---|
[6084] | 30 | @Override
|
---|
[12189] | 31 | public ChangesetCache getSource() {
|
---|
| 32 | return source;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @Override
|
---|
[2711] | 36 | public Collection<Changeset> getAddedChangesets() {
|
---|
| 37 | return Collections.unmodifiableCollection(added);
|
---|
| 38 | }
|
---|
[8510] | 39 |
|
---|
[6084] | 40 | @Override
|
---|
[2711] | 41 | public Collection<Changeset> getRemovedChangesets() {
|
---|
| 42 | return Collections.unmodifiableCollection(removed);
|
---|
| 43 | }
|
---|
[8510] | 44 |
|
---|
[6084] | 45 | @Override
|
---|
[2711] | 46 | public Collection<Changeset> getUpdatedChangesets() {
|
---|
| 47 | return Collections.unmodifiableCollection(modified);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[12189] | 50 | /**
|
---|
| 51 | * Adds a {@link Changeset} to the added list
|
---|
| 52 | * @param cs the {@link Changeset}
|
---|
| 53 | */
|
---|
[2711] | 54 | public void rememberAddedChangeset(Changeset cs) {
|
---|
| 55 | if (cs == null) return;
|
---|
| 56 | added.add(cs);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[12189] | 59 | /**
|
---|
| 60 | * Adds a {@link Changeset} to the updated list
|
---|
| 61 | * @param cs the {@link Changeset}
|
---|
| 62 | */
|
---|
[2711] | 63 | public void rememberUpdatedChangeset(Changeset cs) {
|
---|
| 64 | if (cs == null) return;
|
---|
| 65 | modified.add(cs);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[12189] | 68 | /**
|
---|
| 69 | * Adds a {@link Changeset} to the removed list
|
---|
| 70 | * @param cs the {@link Changeset}
|
---|
| 71 | */
|
---|
[2711] | 72 | public void rememberRemovedChangeset(Changeset cs) {
|
---|
| 73 | if (cs == null) return;
|
---|
| 74 | removed.add(cs);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[12189] | 77 | /**
|
---|
| 78 | * Checks if this event contains any {@link Changeset}s
|
---|
| 79 | * @return <code>true</code> if changesets were added
|
---|
| 80 | */
|
---|
[2711] | 81 | public boolean isEmpty() {
|
---|
| 82 | return added.isEmpty() && modified.isEmpty() && removed.isEmpty();
|
---|
| 83 | }
|
---|
| 84 | }
|
---|