Package org.openstreetmap.josm.data.osm
Class User
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.User
-
public final class User extends java.lang.Object
A simple class to keep a list of user names. Instead of storing user names as strings with every OSM primitive, we store a reference to an user object, and make sure that for each username there is only one user object.- Since:
- 227
-
-
Field Summary
Fields Modifier and Type Field Description private static User
ANONYMOUS
The anonymous user is a local user used in places where no user is known.private static User
lastUser
private java.util.LinkedHashSet<java.lang.String>
names
the user nameprivate long
uid
the user idprivate static long
uidCounter
private static java.util.Map<java.lang.Long,User>
userMap
the map of known users
-
Constructor Summary
Constructors Modifier Constructor Description private
User(long uid, java.lang.String name)
Private constructor, only called from get method.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addName(java.lang.String name)
Adds a user name to the list if it is not there, yet.static void
clearUserMap()
clears the static map of user ids to user objectsstatic User
createLocalUser(java.lang.String name)
Creates a local user with the given namestatic User
createOsmUser(long uid, java.lang.String name)
Creates a user known to the OSM serverboolean
equals(java.lang.Object obj)
static User
getAnonymous()
Replies the anonymous userstatic User
getById(long uid)
Returns the user with user iduid
or null if this user doesn't existstatic java.util.List<User>
getByName(java.lang.String name)
Returns the list of users with namename
or the empty list if no such users existlong
getId()
Replies the user id.java.lang.String
getName()
Replies the user namejava.util.List<java.lang.String>
getNames()
Returns the list of user namesprivate static long
getNextLocalUid()
int
hashCode()
boolean
hasName(java.lang.String name)
Returns true if the name is in the names listboolean
isLocalUser()
Determines if this user is localboolean
isOsmUser()
Determines if this user is known to OSMvoid
setPreferredName(java.lang.String name)
Sets the preferred user name, i.e., the one that will be returned when callinggetName()
.java.lang.String
toString()
-
-
-
Field Detail
-
uidCounter
private static long uidCounter
-
ANONYMOUS
private static final User ANONYMOUS
The anonymous user is a local user used in places where no user is known.- See Also:
getAnonymous()
-
names
private final java.util.LinkedHashSet<java.lang.String> names
the user name
-
uid
private final long uid
the user id
-
-
Constructor Detail
-
User
private User(long uid, java.lang.String name)
Private constructor, only called from get method.- Parameters:
uid
- user idname
- user name
-
-
Method Detail
-
getNextLocalUid
private static long getNextLocalUid()
-
createLocalUser
public static User createLocalUser(java.lang.String name)
Creates a local user with the given name- Parameters:
name
- the name- Returns:
- a new local user with the given name
-
createOsmUser
public static User createOsmUser(long uid, java.lang.String name)
Creates a user known to the OSM server- Parameters:
uid
- the user idname
- the name- Returns:
- a new OSM user with the given name and uid
-
clearUserMap
public static void clearUserMap()
clears the static map of user ids to user objects
-
getById
public static User getById(long uid)
Returns the user with user iduid
or null if this user doesn't exist- Parameters:
uid
- the user id- Returns:
- the user; null, if there is no user with this id
-
getByName
public static java.util.List<User> getByName(java.lang.String name)
Returns the list of users with namename
or the empty list if no such users exist- Parameters:
name
- the user name- Returns:
- the list of users with name
name
or the empty list if no such users exist
-
getAnonymous
public static User getAnonymous()
Replies the anonymous user- Returns:
- The anonymous user
-
getName
public java.lang.String getName()
Replies the user name- Returns:
- the user name. Never
null
, but may be the empty string - See Also:
getByName(String)
,createOsmUser(long, String)
,createLocalUser(String)
-
getNames
public java.util.List<java.lang.String> getNames()
Returns the list of user names- Returns:
- list of names
-
addName
public void addName(java.lang.String name)
Adds a user name to the list if it is not there, yet.- Parameters:
name
- User name- Throws:
java.lang.NullPointerException
- if name is null
-
setPreferredName
public void setPreferredName(java.lang.String name)
Sets the preferred user name, i.e., the one that will be returned when callinggetName()
. Rationale: A user can change its name multiple times and after reading various (outdated w.r.t. user name) data files it is unclear which is the up-to-date user name.- Parameters:
name
- the preferred user name to set- Throws:
java.lang.NullPointerException
- if name is null
-
hasName
public boolean hasName(java.lang.String name)
Returns true if the name is in the names list- Parameters:
name
- User name- Returns:
true
if the name is in the names list
-
getId
public long getId()
Replies the user id. If this user is known to the OSM server the positive user id from the server is replied. Otherwise, a negative local value is replied. A negative local is only unique during an editing session. It is lost when the application is closed and there is no guarantee that a negative local user id is always bound to a user with the same name.- Returns:
- the user id
-
isOsmUser
public boolean isOsmUser()
Determines if this user is known to OSM- Returns:
true
if this user is known to OSM,false
otherwise
-
isLocalUser
public boolean isLocalUser()
Determines if this user is local- Returns:
true
if this user is local,false
otherwise
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-