Changeset 14961 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2019-04-04T14:35:46+02:00 (6 years ago)
Author:
GerdP
Message:

reduce code duplication, add unit test for new access methods

File:
1 edited

Legend:

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

    r14947 r14961  
    192192     */
    193193    public ChangesetDataSetEntry getFirstEntry(PrimitiveId id) {
     194        return getEntry(id, 0);
     195    }
     196
     197    /**
     198     * Replies the last {@link ChangesetDataSetEntry} with id <code>id</code> from this dataset.
     199     * null, if there is no such primitive in the data set.
     200     * @param id the id
     201     * @return the last {@link ChangesetDataSetEntry} with id <code>id</code> from this dataset or null.
     202     * @since 14946
     203     */
     204    public ChangesetDataSetEntry getLastEntry(PrimitiveId id) {
     205        return getEntry(id, 1);
     206    }
     207
     208    private ChangesetDataSetEntry getEntry(PrimitiveId id, int n) {
    194209        if (id == null)
    195210            return null;
     
    199214        if (val instanceof ChangesetDataSetEntry[]) {
    200215            ChangesetDataSetEntry[] entries = (ChangesetDataSetEntry[]) val;
    201             return entries[0];
    202         } else {
    203             return (ChangesetDataSetEntry) val;
    204         }
    205     }
    206 
    207     /**
    208      * Replies the last {@link ChangesetDataSetEntry} with id <code>id</code> from this dataset.
    209      * null, if there is no such primitive in the data set.
    210      * @param id the id
    211      * @return the last {@link ChangesetDataSetEntry} with id <code>id</code> from this dataset or null.
    212      * @since 14946
    213      */
    214     public ChangesetDataSetEntry getLastEntry(PrimitiveId id) {
    215         if (id == null)
    216             return null;
    217         Object val = entryMap.get(id);
    218         if (val == null)
    219             return null;
    220         if (val instanceof ChangesetDataSetEntry[]) {
    221             ChangesetDataSetEntry[] entries = (ChangesetDataSetEntry[]) val;
    222             return entries[1];
     216            return entries[n];
    223217        } else {
    224218            return (ChangesetDataSetEntry) val;
Note: See TracChangeset for help on using the changeset viewer.