1 package gr.grnet.pithos.web.client.catalog;
3 import gr.grnet.pithos.web.client.Helpers;
5 import java.util.HashMap;
6 import java.util.Iterator;
10 * Holds one-to-one mappings from user IDs to respective user display names.
12 * The iterator returns map entries with id as the key and name as the value.
14 public class UserCatalogs implements Iterable<Map.Entry<String, String>>{
15 private HashMap<String, String> id2name = new HashMap<String, String>();
16 private HashMap<String, String> name2id = new HashMap<String, String>();
18 public UserCatalogs() {
19 this(new HashMap<String, String>(), new HashMap<String, String>());
22 private UserCatalogs(HashMap<String, String> id2name, HashMap<String, String> name2id) {
23 this.id2name = id2name;
24 this.name2id = name2id;
27 public UserCatalogs updateWithIDAndName(String id, String name) {
28 this.id2name.put(id, name);
29 this.name2id.put(name, id);
34 public UserCatalogs updateFrom(UserCatalogs other) {
35 for(Map.Entry<String, String> otherIDAndName : other) {
36 this.updateWithIDAndName(otherIDAndName.getKey(), otherIDAndName.getValue());
41 public UserCatalogs copy() {
42 return new UserCatalogs(
43 Helpers.copyHashMap(id2name),
44 Helpers.copyHashMap(name2id)
48 public boolean hasID(String id) {
49 return id2name.containsKey(id);
52 public boolean hasName(String name) {
53 return name2id.containsKey(name);
56 public String getDisplayName(String id) {
57 return id2name.get(id);
60 public String getUserID(String name) {
61 return name2id.get(name);
65 public Iterator<Map.Entry<String, String>> iterator() {
66 return id2name.entrySet().iterator();