BrightSide Workbench Full Report + Source Code
AddressMap.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.contacts;
19 
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.HashSet;
23 import java.util.Map;
24 import java.util.Map.Entry;
25 import java.util.Set;
26 
31 public class AddressMap implements Map<String, Address>{
32 
33  private final Contact contact;
34 
35  public AddressMap(Contact contact) {
36  this.contact = contact;
37  }
38 
39  @Override
40  public int size() {
41  return contact.getAddresses().size();
42  }
43 
44  @Override
45  public boolean isEmpty() {
46  return contact.getAddresses().isEmpty();
47  }
48 
49  @Override
50  public boolean containsKey(Object key) {
51  for(Address a : contact.getAddresses()) {
52  if(a.getDescription().equalsIgnoreCase(key.toString())) {
53  return true;
54  }
55  }
56  return false;
57  }
58 
59  @Override
60  public boolean containsValue(Object value) {
61  throw new UnsupportedOperationException("Not supported yet.");
62  }
63 
64  @Override
65  public Address get(Object key) {
66  for(Address a : contact.getAddresses()) {
67  if(a.getDescription().equalsIgnoreCase(key.toString())) {
68  return a;
69  }
70  }
71  return null;
72  }
73 
74  @Override
75  public Address put(String key, Address value) {
76  throw new UnsupportedOperationException("Not supported yet.");
77  }
78 
79  @Override
80  public Address remove(Object key) {
81  throw new UnsupportedOperationException("Not supported yet.");
82  }
83 
84  @Override
85  public void putAll(Map<? extends String, ? extends Address> m) {
86  throw new UnsupportedOperationException("Not supported yet.");
87  }
88 
89  @Override
90  public void clear() {
91  throw new UnsupportedOperationException("Not supported yet.");
92  }
93 
94  @Override
95  public Set<String> keySet() {
96  Set<String> set = new HashSet<>();
97  for(Address a : contact.getAddresses()) {
98  set.add(a.getDescription());
99  }
100  return set;
101  }
102 
103  @Override
104  public Collection<Address> values() {
105  Collection<Address> list = new ArrayList<>();
106  for(Address a : contact.getAddresses()) {
107  list.add(a);
108  }
109  return list;
110  }
111 
112  @Override
113  public Set<Entry<String, Address>> entrySet() {
114  HashSet<Entry<String, Address>> set = new HashSet();
115  for(final Address a : contact.getAddresses()) {
116  set.add(new Entry<String, Address>() {
117  @Override
118  public String getKey() {
119  return a.getDescription();
120  }
121  @Override
122  public Address getValue() {
123  return a;
124  }
125  @Override
126  public Address setValue(Address value) {
127  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
128  }
129  });
130  }
131  return set;
132  }
133 
134 }
Set< Entry< String, Address > > entrySet()
boolean containsKey(Object key)
Definition: AddressMap.java:50
Collection< Address > values()
boolean containsValue(Object value)
Definition: AddressMap.java:60
Address put(String key, Address value)
Definition: AddressMap.java:75
void putAll(Map<? extends String, ? extends Address > m)
Definition: AddressMap.java:85
AddressMap(Contact contact)
Definition: AddressMap.java:35
Set< Address > getAddresses()
Definition: Contact.java:355