Ticket #11250: 0001-Made-user-map-synchronized.patch

File 0001-Made-user-map-synchronized.patch, 3.5 KB (added by michael2402, 11 years ago)
  • src/org/openstreetmap/josm/data/osm/User.java

    From 9d0c533167518aac56c53d29655725c5ce7b77c6 Mon Sep 17 00:00:00 2001
    From: Michael Zangl <michael.zangl@student.kit.edu>
    Date: Fri, 27 Mar 2015 22:22:46 +0100
    Subject: [PATCH] Made user map synchronized.
    
    ---
     src/org/openstreetmap/josm/data/osm/User.java | 32 +++++++++++++++------------
     1 file changed, 18 insertions(+), 14 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/data/osm/User.java b/src/org/openstreetmap/josm/data/osm/User.java
    index b87df75..481dd22 100644
    a b import java.util.HashSet;  
    99import java.util.List;
    1010import java.util.Map;
    1111import java.util.Set;
    12 import java.util.concurrent.atomic.AtomicLong;
    1312
    1413import org.openstreetmap.josm.tools.Utils;
    1514
    import org.openstreetmap.josm.tools.Utils;  
    2423 */
    2524public final class User {
    2625
    27     private static AtomicLong uidCounter = new AtomicLong();
     26    private static long uidCounter = 0;
    2827
    2928    /**
    3029     * the map of known users
    3130     */
    3231    private static Map<Long,User> userMap = new HashMap<>();
     32
     33    /**
     34     * The anonymous user is a local user used in places where no user is known.
     35     * @see #getAnonymous()
     36     */
    3337    private static final User anonymous = createLocalUser(tr("<anonymous>"));
    3438
    3539    private static long getNextLocalUid() {
    36         return uidCounter.decrementAndGet();
     40        uidCounter--;
     41        return uidCounter;
    3742    }
    3843
    3944    /**
    public final class User {  
    4247     * @param name the name
    4348     * @return a new local user with the given name
    4449     */
    45     public static User createLocalUser(String name) {
    46         for(long i = -1; i >= uidCounter.get(); --i)
     50    public static synchronized User createLocalUser(String name) {
     51        for(long i = -1; i >= uidCounter; --i)
    4752        {
    48           User olduser = getById(i);
    49           if(olduser != null && olduser.hasName(name))
    50             return olduser;
     53            User olduser = getById(i);
     54            if(olduser != null && olduser.hasName(name))
     55                return olduser;
    5156        }
    5257        User user = new User(getNextLocalUid(), name);
    5358        userMap.put(user.getId(), user);
    public final class User {  
    6166     * @param name the name
    6267     * @return a new OSM user with the given name and uid
    6368     */
    64     public static User createOsmUser(long uid, String name) {
     69    public static synchronized User createOsmUser(long uid, String name) {
    6570        User user = userMap.get(uid);
    6671        if (user == null) {
    6772            user = new User(uid, name);
    public final class User {  
    7378
    7479    /**
    7580     * clears the static map of user ids to user objects
    76      *
    7781     */
    78     public static void clearUserMap() {
     82    public static synchronized void clearUserMap() {
    7983        userMap.clear();
    8084    }
    8185
    public final class User {  
    8589     * @param uid the user id
    8690     * @return the user; null, if there is no user with  this id
    8791     */
    88     public static User getById(long uid) {
    89         return userMap.get(uid);
     92    public static synchronized User getById(long uid) {
     93           return userMap.get(uid);
    9094    }
    9195
    9296    /**
    public final class User {  
    97101     * @return the list of users with name <code>name</code> or the empty list if
    98102     * no such users exist
    99103     */
    100     public static List<User> getByName(String name) {
     104    public static synchronized List<User> getByName(String name) {
    101105        if (name == null) {
    102106            name = "";
    103107        }