Changeset 10841 in josm for trunk


Ignore:
Timestamp:
2016-08-18T19:23:21+02:00 (8 years ago)
Author:
simon04
Message:

fix #8251 fix #10922 - Improve handling of user names that have changed

  • User#getName only returns one user name instead of all /-joined
  • User#setPreferredName sets a preferred user name when parsing a changeset or reading the OSM history
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r9371 r10841  
    55
    66import java.util.ArrayList;
     7import java.util.Collection;
    78import java.util.HashMap;
    8 import java.util.HashSet;
     9import java.util.LinkedHashSet;
    910import java.util.List;
    1011import java.util.Map;
    1112import java.util.Objects;
    12 import java.util.Set;
    13 
    14 import org.openstreetmap.josm.tools.Utils;
    1513
    1614/**
     
    135133
    136134    /** the user name */
    137     private final Set<String> names = new HashSet<>();
     135    private final LinkedHashSet<String> names = new LinkedHashSet<>();
    138136    /** the user id */
    139137    private final long uid;
     
    143141     *
    144142     * @return the user name. Never <code>null</code>, but may be the empty string
     143     * @see #getByName(String)
     144     * @see #createOsmUser(long, String)
     145     * @see #createLocalUser(String)
    145146     */
    146147    public String getName() {
    147         return Utils.join("/", names);
     148        return names.isEmpty() ? "" : names.iterator().next();
    148149    }
    149150
     
    164165    public void addName(String name) {
    165166        names.add(name);
     167    }
     168
     169    /**
     170     * Sets the preferred user name, i.e., the one that will be returned when calling {@link #getName()}.
     171     *
     172     * Rationale: A user can change its name multiple times and after reading various (outdated w.r.t. user name)
     173     * data files it is unclear which is the up-to-date user name.
     174     * @param name the preferred user name to set
     175     */
     176    public void setPreferredName(String name) {
     177        if (names.size() == 1 && names.contains(name)) {
     178            return;
     179        }
     180        final Collection<String> allNames = new LinkedHashSet<>(names);
     181        names.clear();
     182        names.add(name);
     183        names.addAll(allNames);
    166184    }
    167185
  • trunk/src/org/openstreetmap/josm/io/AbstractParser.java

    r8510 r10841  
    117117            if (uid != null) {
    118118                user = User.createOsmUser(uid, userStr);
     119                user.setPreferredName(userStr);
    119120            } else {
    120121                user = User.createLocalUser(userStr);
Note: See TracChangeset for help on using the changeset viewer.