Changeset 2019 in josm for trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java
- Timestamp:
- 2009-08-31T08:06:25+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java
r1709 r2019 7 7 import java.util.HashMap; 8 8 import java.util.NoSuchElementException; 9 import java.util.concurrent.CopyOnWriteArrayList; 9 10 11 /** 12 * A data set holding histories of OSM primitives. 13 * 14 * 15 */ 10 16 public class HistoryDataSet { 11 17 18 /** the unique instance */ 12 19 private static HistoryDataSet historyDataSet; 13 20 21 /** 22 * Replies the unique instance of the history data set 23 * 24 * @return the unique instance of the history data set 25 */ 14 26 public static HistoryDataSet getInstance() { 15 27 if (historyDataSet == null) { … … 19 31 } 20 32 33 /** the history data */ 21 34 private HashMap<Long, ArrayList<HistoryOsmPrimitive>> data; 35 private CopyOnWriteArrayList<HistoryDataSetListener> listeners; 22 36 23 37 public HistoryDataSet() { 24 38 data = new HashMap<Long, ArrayList<HistoryOsmPrimitive>>(); 39 listeners = new CopyOnWriteArrayList<HistoryDataSetListener>(); 25 40 } 26 41 27 public HistoryOsmPrimitive get(long id, long version) { 42 public void addHistoryDataSetListener(HistoryDataSetListener listener) { 43 synchronized(listeners) { 44 if (!listeners.contains(listener)) { 45 listeners.add(listener); 46 } 47 } 48 } 49 50 public void removeHistoryDataSetListener(HistoryDataSetListener listener) { 51 synchronized(listeners) { 52 if (listeners.contains(listener)) { 53 listeners.remove(listener); 54 } 55 } 56 } 57 58 protected void fireHistoryUpdated(long id) { 59 for (HistoryDataSetListener l : listeners) { 60 l.historyUpdated(this, id); 61 } 62 } 63 64 /** 65 * Replies the history primitive for the primitive with id <code>id</code> 66 * and version <code>version</code> 67 * 68 * @param id the id of the primitive 69 * @param version the version of the primitive 70 * @return the history primitive for the primitive with id <code>id</code> 71 * and version <code>version</code> 72 * @throws NoSuchElementException thrown if this dataset doesn't include the respective 73 * history primitive 74 */ 75 public HistoryOsmPrimitive get(long id, long version) throws NoSuchElementException{ 28 76 ArrayList<HistoryOsmPrimitive> versions = data.get(id); 29 77 if (versions == null) … … 37 85 } 38 86 87 /** 88 * Adds a history primitive to the data set 89 * 90 * @param primitive the history primitive to add 91 */ 39 92 public void put(HistoryOsmPrimitive primitive) { 40 93 if (data.get(primitive.getId()) == null) { … … 42 95 } 43 96 data.get(primitive.getId()).add(primitive); 97 fireHistoryUpdated(primitive.getId()); 44 98 } 45 99 … … 66 120 return; 67 121 for (Long id : other.data.keySet()) { 68 if (!this.data.keySet().contains(id)) { 69 this.data.put(id, other.data.get(id)); 70 } 122 this.data.put(id, other.data.get(id)); 71 123 } 124 fireHistoryUpdated(0); 72 125 } 73 126 }
Note:
See TracChangeset
for help on using the changeset viewer.