Changeset 2638 in josm for trunk/src


Ignore:
Timestamp:
2009-12-14T19:19:16+01:00 (14 years ago)
Author:
mjulius
Message:

fixes #4175 - Exception when user with existing ID but different name is encountered
User now keeps a list of all names for the uid and users are considered equal if the uids are equal. User.getName() now returns all names joined by '/'.

File:
1 edited

Legend:

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

    r2512 r2638  
    22package org.openstreetmap.josm.data.osm;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    5 
    64import java.util.ArrayList;
    75import java.util.HashMap;
     6import java.util.HashSet;
    87import java.util.List;
    98import java.util.concurrent.atomic.AtomicLong;
     
    5655            userMap.put(user.getId(), user);
    5756        }
    58         if (!user.getName().equals(name))
    59             throw new DataIntegrityProblemException(tr("User with the same uid but different name found"));
     57        user.addName(name);
    6058        return user;
    6159    }
     
    9391        List<User> ret = new ArrayList<User>();
    9492        for (User user: userMap.values()) {
    95             if (user.getName().equals(name)) {
     93            if (user.hasName(name)) {
    9694                ret.add(user);
    9795            }
     
    10199
    102100    /** the user name */
    103     private final String name;
     101    private final HashSet<String> names = new HashSet<String>();
    104102    /** the user id */
    105103    private final long uid;
     
    111109     */
    112110    public String getName() {
    113         return name;
     111        StringBuilder sb = new StringBuilder();
     112        for (String name: names) {
     113            sb.append(name);
     114            sb.append('/');
     115        }
     116        sb.deleteCharAt(sb.length() - 1);
     117        return sb.toString();
     118    }
     119
     120    /*
     121     * Returns the list of user names
     122     *
     123     * @returns list of names
     124     */
     125    public ArrayList<String> getNames() {
     126        return new ArrayList<String>(names);
     127    }
     128
     129    /*
     130     * Adds a user name to the list if it is not there, yet.
     131     *
     132     * @param name
     133     */
     134    public void addName(String name) {
     135        names.add(name);
     136    }
     137
     138    /*
     139     * Returns true if the name is in the names list
     140     *
     141     * @param name
     142     */
     143    public boolean hasName(String name) {
     144        return names.contains(name);
    114145    }
    115146
     
    130161    private User(long uid, String name) {
    131162        this.uid = uid;
    132         if (name == null) {
    133             this.name = "";
    134         } else {
    135             this.name = name;
     163        if (name != null) {
     164            addName(name);
    136165        }
    137166    }
     
    149178        final int prime = 31;
    150179        int result = 1;
    151         result = prime * result + name.hashCode();
     180        result = prime * result + getName().hashCode();
    152181        result = prime * result + (int) (uid ^ (uid >>> 32));
    153182        return result;
     
    156185    @Override
    157186    public boolean equals(Object obj) {
    158         if (obj instanceof User) {
    159             User other = (User) obj;
    160             if (!name.equals(other.name))
    161                 return false;
    162             if (uid != other.uid)
    163                 return false;
    164             return true;
    165         } else
     187        if (! (obj instanceof User))
    166188            return false;
     189        User other = (User) obj;
     190        if (uid != other.uid)
     191            return false;
     192        return true;
    167193    }
    168194}
Note: See TracChangeset for help on using the changeset viewer.