Changeset 2448 in josm for trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java
- Timestamp:
- 2009-11-14T17:59:10+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java
r2163 r2448 6 6 import java.util.ArrayList; 7 7 import java.util.HashMap; 8 import java.util.NoSuchElementException;9 8 import java.util.concurrent.CopyOnWriteArrayList; 9 import java.util.logging.Logger; 10 11 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 import org.openstreetmap.josm.data.osm.PrimitiveId; 13 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 10 14 11 15 /** … … 15 19 */ 16 20 public class HistoryDataSet { 21 private final static Logger logger = Logger.getLogger(HistoryDataSet.class.getName()); 17 22 18 23 /** the unique instance */ … … 32 37 33 38 /** the history data */ 34 private HashMap< Long, ArrayList<HistoryOsmPrimitive>> data;39 private HashMap<PrimitiveId, ArrayList<HistoryOsmPrimitive>> data; 35 40 private CopyOnWriteArrayList<HistoryDataSetListener> listeners; 36 41 37 42 public HistoryDataSet() { 38 data = new HashMap< Long, ArrayList<HistoryOsmPrimitive>>();43 data = new HashMap<PrimitiveId, ArrayList<HistoryOsmPrimitive>>(); 39 44 listeners = new CopyOnWriteArrayList<HistoryDataSetListener>(); 40 45 } … … 56 61 } 57 62 58 protected void fireHistoryUpdated( longid) {63 protected void fireHistoryUpdated(SimplePrimitiveId id) { 59 64 for (HistoryDataSetListener l : listeners) { 60 65 l.historyUpdated(this, id); … … 64 69 /** 65 70 * Replies the history primitive for the primitive with id <code>id</code> 66 * and version <code>version</code> 71 * and version <code>version</code>. null, if no such primitive exists. 67 72 * 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 73 * @param id the id of the primitive. > 0 required. 74 * @param type the primitive type. Must not be null. 75 * @param version the version of the primitive. > 0 required 76 * @return the history primitive for the primitive with id <code>id</code>, 77 * type <code>type</code>, and version <code>version</code> 74 78 */ 75 public HistoryOsmPrimitive get(long id, long version) throws NoSuchElementException{ 76 ArrayList<HistoryOsmPrimitive> versions = data.get(id); 79 public HistoryOsmPrimitive get(long id, OsmPrimitiveType type, long version){ 80 if (id <= 0) 81 throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0 expected, got {1}", "id", id)); 82 if (type == null) 83 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "type")); 84 if (version <= 0) 85 throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0 expected, got {1}", "version", version)); 86 87 SimplePrimitiveId pid = new SimplePrimitiveId(id, type); 88 ArrayList<HistoryOsmPrimitive> versions = data.get(pid); 77 89 if (versions == null) 78 throw new NoSuchElementException(tr("Didn't find an primitive with id {0} in this dataset", id)); 79 90 return null; 80 91 for (HistoryOsmPrimitive primitive: versions) { 81 92 if (primitive.matches(id, version)) 82 93 return primitive; 83 94 } 84 throw new NoSuchElementException(tr("Didn't find an primitive with id {0} and version {1} in this dataset", id, version));95 return null; 85 96 } 86 97 … … 91 102 */ 92 103 public void put(HistoryOsmPrimitive primitive) { 93 if (data.get(primitive.getId()) == null) { 94 data.put(primitive.getId(), new ArrayList<HistoryOsmPrimitive>()); 104 SimplePrimitiveId id = new SimplePrimitiveId(primitive.getId(), primitive.getType()); 105 if (data.get(id) == null) { 106 data.put(id, new ArrayList<HistoryOsmPrimitive>()); 95 107 } 96 data.get( primitive.getId()).add(primitive);97 fireHistoryUpdated( primitive.getId());108 data.get(id).add(primitive); 109 fireHistoryUpdated(id); 98 110 } 99 111 100 112 /** 101 113 * Replies the history for a given primitive with id <code>id</code> 114 * and type <code>type</code>. 102 115 * 103 * @param id the id 104 * @return the history 116 * @param id the id the if of the primitive. > 0 required 117 * @param type the type of the primitive. Must not be null. 118 * @return the history. null, if there isn't a history for <code>id</code> and 119 * <code>type</code>. 120 * @throws IllegalArgumentException thrown if id <= 0 121 * @throws IllegalArgumentException thrown if type is null 105 122 */ 106 public History getHistory(long id) { 107 ArrayList<HistoryOsmPrimitive> versions = data.get(id); 123 public History getHistory(long id, OsmPrimitiveType type) throws IllegalArgumentException{ 124 if (id <= 0) 125 throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0 expected, got {1}", "id", id)); 126 if (type == null) 127 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "type")); 128 SimplePrimitiveId pid = new SimplePrimitiveId(id, type); 129 return getHistory(pid); 130 } 131 132 /** 133 * Replies the history for a primitive with id <code>id</code>. null, if no 134 * such history exists. 135 * 136 * @param pid the primitive id. Must not be null. 137 * @return the history for a primitive with id <code>id</code>. null, if no 138 * such history exists 139 * @throws IllegalArgumentException thrown if pid is null 140 */ 141 public History getHistory(PrimitiveId pid) throws IllegalArgumentException{ 142 if (pid == null) 143 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "pid")); 144 ArrayList<HistoryOsmPrimitive> versions = data.get(pid); 108 145 if (versions == null) 109 146 return null; 110 return new History( id, versions);147 return new History(pid.getUniqueId(), pid.getType(), versions); 111 148 } 112 149 … … 119 156 if (other == null) 120 157 return; 121 for ( Longid : other.data.keySet()) {158 for (PrimitiveId id : other.data.keySet()) { 122 159 this.data.put(id, other.data.get(id)); 123 160 } 124 fireHistoryUpdated( 0);161 fireHistoryUpdated(null); 125 162 } 126 163 }
Note:
See TracChangeset
for help on using the changeset viewer.