BrightSide Workbench Full Report + Source Code
CommentMap.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.Set;
25 
30 public class CommentMap implements Map<String, Comment>{
31 
32  private final Contact contact;
33 
34  public CommentMap(Contact contact) {
35  this.contact = contact;
36  }
37 
38  @Override
39  public int size() {
40  return contact.getComments().size();
41  }
42 
43  @Override
44  public boolean isEmpty() {
45  return contact.getComments().isEmpty();
46  }
47 
48  @Override
49  public boolean containsKey(Object key) {
50  for(Comment c : contact.getComments()) {
51  if(c.getComment().contains(key.toString())) {
52  return true;
53  }
54  }
55  return false;
56  }
57 
58  @Override
59  public boolean containsValue(Object value) {
60  throw new UnsupportedOperationException("Not supported yet.");
61  }
62 
63  @Override
64  public Comment get(Object key) {
65  for(Comment c : contact.getComments()) {
66  if(!c.isEmpty() && c.getComment().contains(key.toString())) {
67  return c;
68  }
69  }
70  return null;
71  }
72 
73  @Override
74  public Comment put(String key, Comment value) {
75  throw new UnsupportedOperationException("Not supported yet.");
76  }
77 
78  @Override
79  public Comment remove(Object key) {
80  throw new UnsupportedOperationException("Not supported yet.");
81  }
82 
83  @Override
84  public void putAll(Map<? extends String, ? extends Comment> m) {
85  throw new UnsupportedOperationException("Not supported yet.");
86  }
87 
88  @Override
89  public void clear() {
90  throw new UnsupportedOperationException("Not supported yet.");
91  }
92 
93  @Override
94  public Set<String> keySet() {
95  throw new UnsupportedOperationException("Not supported yet.");
96  }
97 
98  @Override
99  public Collection<Comment> values() {
100  Collection<Comment> list = new ArrayList<>();
101  for(Comment c : contact.getComments()) {
102  list.add(c);
103  }
104  return list;
105  }
106 
107  @Override
108  public Set<Entry<String, Comment>> entrySet() {
109  HashSet<Entry<String, Comment>> set = new HashSet();
110  for(final Comment c : contact.getComments()) {
111  set.add(new Entry<String, Comment>() {
112  @Override
113  public String getKey() {
114  return c.getComment();
115  }
116  @Override
117  public Comment getValue() {
118  return c;
119  }
120  @Override
121  public Comment setValue(Comment value) {
122  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
123  }
124  });
125  }
126  return set;
127  }
128 
129 }
Set< Entry< String, Comment > > entrySet()
Collection< Comment > values()
Definition: CommentMap.java:99
CommentMap(Contact contact)
Definition: CommentMap.java:34
boolean containsKey(Object key)
Definition: CommentMap.java:49
Comment put(String key, Comment value)
Definition: CommentMap.java:74
void putAll(Map<? extends String, ? extends Comment > m)
Definition: CommentMap.java:84
boolean containsValue(Object value)
Definition: CommentMap.java:59
Set< Comment > getComments()
Definition: Contact.java:415