Changeset 8155 in josm for trunk/src/org
- Timestamp:
- 2015-03-27T22:39:33+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/User.java
r7005 r8155 10 10 import java.util.Map; 11 11 import java.util.Set; 12 import java.util.concurrent.atomic.AtomicLong;13 12 14 13 import org.openstreetmap.josm.tools.Utils; … … 25 24 public final class User { 26 25 27 private static AtomicLong uidCounter = new AtomicLong();26 private static long uidCounter = 0; 28 27 29 28 /** … … 31 30 */ 32 31 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 */ 33 37 private static final User anonymous = createLocalUser(tr("<anonymous>")); 34 38 35 39 private static long getNextLocalUid() { 36 return uidCounter.decrementAndGet(); 40 uidCounter--; 41 return uidCounter; 37 42 } 38 43 … … 43 48 * @return a new local user with the given name 44 49 */ 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) 47 52 { 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; 51 56 } 52 57 User user = new User(getNextLocalUid(), name); … … 62 67 * @return a new OSM user with the given name and uid 63 68 */ 64 public static User createOsmUser(long uid, String name) {69 public static synchronized User createOsmUser(long uid, String name) { 65 70 User user = userMap.get(uid); 66 71 if (user == null) { … … 74 79 /** 75 80 * clears the static map of user ids to user objects 76 * 77 */ 78 public static void clearUserMap() { 81 */ 82 public static synchronized void clearUserMap() { 79 83 userMap.clear(); 80 84 } … … 86 90 * @return the user; null, if there is no user with this id 87 91 */ 88 public static User getById(long uid) {92 public static synchronized User getById(long uid) { 89 93 return userMap.get(uid); 90 94 } … … 98 102 * no such users exist 99 103 */ 100 public static List<User> getByName(String name) {104 public static synchronized List<User> getByName(String name) { 101 105 if (name == null) { 102 106 name = "";
Note:
See TracChangeset
for help on using the changeset viewer.