Line | |
---|
1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.HashMap;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * A simple class to keep a list of user names.
|
---|
8 | *
|
---|
9 | * Instead of storing user names as strings with every OSM primitive, we store
|
---|
10 | * a reference to an user object, and make sure that for each username there
|
---|
11 | * is only one user object.
|
---|
12 | *
|
---|
13 | * @author fred
|
---|
14 | *
|
---|
15 | */
|
---|
16 | public class User {
|
---|
17 |
|
---|
18 | /** storage for existing User objects. */
|
---|
19 | private static HashMap<String,User> userMap = new HashMap<String,User>();
|
---|
20 |
|
---|
21 | /** the username. */
|
---|
22 | public String name;
|
---|
23 |
|
---|
24 | /** the user ID (since API 0.6) */
|
---|
25 | public String uid;
|
---|
26 |
|
---|
27 | /** private constructor, only called from get method. */
|
---|
28 | private User(String name) {
|
---|
29 | this.name = name;
|
---|
30 | }
|
---|
31 |
|
---|
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;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public int hashCode() {
|
---|
44 | final int prime = 31;
|
---|
45 | int result = 1;
|
---|
46 | result = prime * result + ((name == null) ? 0 : name.hashCode());
|
---|
47 | result = prime * result + ((uid == null) ? 0 : uid.hashCode());
|
---|
48 | return result;
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public boolean equals(Object obj) {
|
---|
53 | if (this == obj)
|
---|
54 | return true;
|
---|
55 | if (obj == null)
|
---|
56 | return false;
|
---|
57 | if (getClass() != obj.getClass())
|
---|
58 | return false;
|
---|
59 | User other = (User) obj;
|
---|
60 | if (name == null) {
|
---|
61 | if (other.name != null)
|
---|
62 | return false;
|
---|
63 | } else if (!name.equals(other.name))
|
---|
64 | return false;
|
---|
65 | if (uid == null) {
|
---|
66 | if (other.uid != null)
|
---|
67 | return false;
|
---|
68 | } else if (!uid.equals(other.uid))
|
---|
69 | return false;
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.