Ignore:
Timestamp:
2009-11-14T17:59:10+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #3352: History doesn't get invalidated on upload?
fixed #3912: Extend history dialog to contain the currently modified version
new: zoom to node in list of nodes in history dialog (popup menu)
new: load history of node from node list in history dialog (popup menu or double click)
fixed: close all history dialogs when the number of layers drop to 0
fixed: implemented equals() and hashCode() on SimplePrimitiveId
fixed: history features now usePrimitiveId instead of long.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java

    r2163 r2448  
    66import java.util.ArrayList;
    77import java.util.HashMap;
    8 import java.util.NoSuchElementException;
    98import java.util.concurrent.CopyOnWriteArrayList;
     9import java.util.logging.Logger;
     10
     11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     12import org.openstreetmap.josm.data.osm.PrimitiveId;
     13import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
    1014
    1115/**
     
    1519 */
    1620public class HistoryDataSet {
     21    private final static Logger logger = Logger.getLogger(HistoryDataSet.class.getName());
    1722
    1823    /** the unique instance */
     
    3237
    3338    /** the history data */
    34     private HashMap<Long, ArrayList<HistoryOsmPrimitive>> data;
     39    private HashMap<PrimitiveId, ArrayList<HistoryOsmPrimitive>> data;
    3540    private CopyOnWriteArrayList<HistoryDataSetListener> listeners;
    3641
    3742    public HistoryDataSet() {
    38         data = new HashMap<Long, ArrayList<HistoryOsmPrimitive>>();
     43        data = new HashMap<PrimitiveId, ArrayList<HistoryOsmPrimitive>>();
    3944        listeners = new CopyOnWriteArrayList<HistoryDataSetListener>();
    4045    }
     
    5661    }
    5762
    58     protected void fireHistoryUpdated(long id) {
     63    protected void fireHistoryUpdated(SimplePrimitiveId id) {
    5964        for (HistoryDataSetListener l : listeners) {
    6065            l.historyUpdated(this, id);
     
    6469    /**
    6570     * 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.
    6772     *
    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>
    7478     */
    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);
    7789        if (versions == null)
    78             throw new NoSuchElementException(tr("Didn't find an primitive with id {0} in this dataset", id));
    79 
     90            return null;
    8091        for (HistoryOsmPrimitive primitive: versions) {
    8192            if (primitive.matches(id, version))
    8293                return primitive;
    8394        }
    84         throw new NoSuchElementException(tr("Didn't find an primitive with id {0} and version {1} in this dataset", id, version));
     95        return null;
    8596    }
    8697
     
    91102     */
    92103    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>());
    95107        }
    96         data.get(primitive.getId()).add(primitive);
    97         fireHistoryUpdated(primitive.getId());
     108        data.get(id).add(primitive);
     109        fireHistoryUpdated(id);
    98110    }
    99111
    100112    /**
    101113     * Replies the history for a given primitive with id <code>id</code>
     114     * and type <code>type</code>.
    102115     *
    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
    105122     */
    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);
    108145        if (versions == null)
    109146            return null;
    110         return new History(id, versions);
     147        return new History(pid.getUniqueId(), pid.getType(), versions);
    111148    }
    112149
     
    119156        if (other == null)
    120157            return;
    121         for (Long id : other.data.keySet()) {
     158        for (PrimitiveId id : other.data.keySet()) {
    122159            this.data.put(id, other.data.get(id));
    123160        }
    124         fireHistoryUpdated(0);
     161        fireHistoryUpdated(null);
    125162    }
    126163}
Note: See TracChangeset for help on using the changeset viewer.