Ignore:
Timestamp:
2009-09-06T23:07:33+02:00 (15 years ago)
Author:
Gubaer
Message:

new: rewrite of CombineWay action
new: conflict resolution dialog for CombineWay, including conflicts for different relation memberships
cleanup: cleanup in OsmReader, reduces memory footprint and reduces parsing time
cleanup: made most of the public fields in OsmPrimitive @deprecated, added accessors and changed the code
cleanup: replaced usages of @deprecated constructors for ExtendedDialog
fixed #3208: Combine ways brokes relation order

WARNING: this changeset touches a lot of code all over the code base. "latest" might become slightly unstable in the next days. Also experience incompatibility issues with plugins in the next few days.

File:
1 edited

Legend:

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

    r2034 r2070  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.ArrayList;
    45import java.util.HashMap;
     6import java.util.List;
    57
    68/**
     
    1113 * is only one user object.
    1214 *
    13  * @author fred
    1415 *
    1516 */
    1617public class User {
     18    static private long uidCounter = 0;
     19    /**
     20     * the map of known users
     21     */
     22    private static HashMap<Long,User> userMap = new HashMap<Long,User>();
    1723
    18     /** storage for existing User objects. */
    19     private static HashMap<String,User> userMap = new HashMap<String,User>();
    2024
    21     /** the username. */
    22     public String name;
     25    private static long getNextLocalUid() {
     26        synchronized(User.class) {
     27            uidCounter--;
     28            return uidCounter;
     29        }
     30    }
    2331
    24     /** the user ID (since API 0.6) */
    25     public String uid;
     32    /**
     33     * Creates a local user with the given name
     34     *
     35     * @param name the name
     36     */
     37    public static User createLocalUser(String name) {
     38        User user = new User(getNextLocalUid(), name);
     39        userMap.put(user.getId(), user);
     40        return user;
     41    }
     42
     43    /**
     44     * Creates a user known to the OSM server
     45     *
     46     * @param uid  the user id
     47     * @param name the name
     48     */
     49    public static User  createOsmUser(long uid, String name) {
     50        User user = new User(uid, name);
     51        userMap.put(user.getId(), user);
     52        return user;
     53    }
     54
     55
     56    /**
     57     * Returns the user with user id <code>uid</code> or null if this user doesn't exist
     58     *
     59     * @param uid the user id
     60     * @return the user; null, if there is no user with  this id
     61     */
     62    public static User getById(long uid) {
     63        return userMap.get(uid);
     64    }
     65
     66    /**
     67     * Returns the list of users with name <code>name</code> or the empty list if
     68     * no such users exist
     69     *
     70     * @param name the user name
     71     * @return the list of users with name <code>name</code> or the empty list if
     72     * no such users exist
     73     */
     74    public static List<User> getByName(String name) {
     75        name = name == null ? "" : name;
     76        List<User> ret = new ArrayList<User>();
     77        for (User user: userMap.values()) {
     78            if (user.getName().equals(name)) {
     79                ret.add(user);
     80            }
     81        }
     82        return ret;
     83    }
     84
     85    /** the user name */
     86    private String name;
     87    /** the user id */
     88    private long uid;
     89
     90    /**
     91     * Replies the user name
     92     *
     93     * @return the user name. Never null, but may be the empty string
     94     */
     95    public String getName() {
     96        return name == null ? "" : name;
     97    }
     98
     99    /**
     100     * Replies the user id. If this user is known to the OSM server the positive user id
     101     * from the server is replied. Otherwise, a negative local value is replied.
     102     *
     103     * A negative local is only unique during an editing session. It is lost when the
     104     * application is closed and there is no guarantee that a negative local user id is
     105     * always bound to a user with the same name.
     106     *
     107     */
     108    public long getId() {
     109        return uid;
     110    }
    26111
    27112    /** private constructor, only called from get method. */
    28     private User(String name) {
     113    private User(long uid, String name) {
     114        this.uid = uid;
    29115        this.name = name;
    30116    }
    31117
    32     /** returns a new or existing User object that represents the given name. */
    33     public static User get(String name) {
    34         User user = userMap.get(name);
    35         if (user == null) {
    36             user = new User(name);
    37             userMap.put(name, user);
    38         }
    39         return user;
     118    public boolean isOsmUser() {
     119        return uid > 0;
     120    }
     121
     122    public boolean isLocalUser() {
     123        return uid < 0;
    40124    }
    41125
     
    45129        int result = 1;
    46130        result = prime * result + ((name == null) ? 0 : name.hashCode());
    47         result = prime * result + ((uid == null) ? 0 : uid.hashCode());
     131        result = prime * result + (int) (uid ^ (uid >>> 32));
    48132        return result;
    49133    }
     
    63147        } else if (!name.equals(other.name))
    64148            return false;
    65         if (uid == null) {
    66             if (other.uid != null)
    67                 return false;
    68         } else if (!uid.equals(other.uid))
     149        if (uid != other.uid)
    69150            return false;
    70151        return true;
Note: See TracChangeset for help on using the changeset viewer.