BrightSide Workbench Full Report + Source Code
ConnectorMap.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 import java.util.TreeMap;
27 import org.turro.contacts.util.TypeByValues;
28 
33 public class ConnectorMap extends TreeMap<String, Connector>{
34 
35  private final Contact contact;
36 
37  public ConnectorMap(Contact contact) {
38  this.contact = contact;
39  }
40 
41  public Connector getByType(String type) {
42  for(final Connector c : contact.getConnectors()) {
43  if(type.equals(TypeByValues.getType(c.getDescription()))) {
44  return c;
45  }
46  }
47  return null;
48  }
49 
50  @Override
51  public int size() {
52  return contact.getConnectors().size();
53  }
54 
55  @Override
56  public boolean isEmpty() {
57  return contact.getConnectors().isEmpty();
58  }
59 
60  @Override
61  public boolean containsKey(Object key) {
62  for(Connector c : contact.getConnectors()) {
63  if(c.getDescription().equalsIgnoreCase(key.toString())) {
64  return true;
65  }
66  }
67  return false;
68  }
69 
70  @Override
71  public boolean containsValue(Object value) {
72  throw new UnsupportedOperationException("Not supported yet.");
73  }
74 
75  @Override
76  public Connector get(Object key) {
77  for(Connector c : contact.getConnectors()) {
78  if(!c.isEmpty() && c.getDescription().equalsIgnoreCase(key.toString())) {
79  return c;
80  }
81  }
82  return null;
83  }
84 
85  @Override
86  public Connector put(String key, Connector value) {
87  throw new UnsupportedOperationException("Not supported yet.");
88  }
89 
90  @Override
91  public Connector remove(Object key) {
92  throw new UnsupportedOperationException("Not supported yet.");
93  }
94 
95  @Override
96  public void putAll(Map<? extends String, ? extends Connector> m) {
97  throw new UnsupportedOperationException("Not supported yet.");
98  }
99 
100  @Override
101  public void clear() {
102  throw new UnsupportedOperationException("Not supported yet.");
103  }
104 
105  @Override
106  public Set<String> keySet() {
107  Set<String> set = new HashSet<>();
108  for(Connector c : contact.getConnectors()) {
109  if(!c.isEmpty()) {
110  set.add(c.getDescription());
111  }
112  }
113  return set;
114  }
115 
116  @Override
117  public Collection<Connector> values() {
118  Collection<Connector> list = new ArrayList<>();
119  for(Connector c : contact.getConnectors()) {
120  list.add(c);
121  }
122  return list;
123  }
124 
125  @Override
126  public Set<Entry<String, Connector>> entrySet() {
127  HashSet<Entry<String, Connector>> set = new HashSet();
128  for(final Connector c : contact.getConnectors()) {
129  set.add(new Entry<String, Connector>() {
130  @Override
131  public String getKey() {
132  return c.getDescription();
133  }
134  @Override
135  public Connector getValue() {
136  return c;
137  }
138  @Override
139  public Connector setValue(Connector value) {
140  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
141  }
142  });
143  }
144  return set;
145  }
146 
147 }
Set< Entry< String, Connector > > entrySet()
boolean containsKey(Object key)
Connector put(String key, Connector value)
Connector getByType(String type)
Collection< Connector > values()
void putAll(Map<? extends String, ? extends Connector > m)
boolean containsValue(Object value)
Set< Connector > getConnectors()
Definition: Contact.java:367
static String getType(String value)