BrightSide Workbench Full Report + Source Code
Elephant/elephant/src/main/java/org/turro/plugin/contacts/ContactList.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.plugin.contacts;
19 
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.stream.Collectors;
24 import org.turro.action.Contacts;
25 import org.turro.elephant.security.IUser;
26 import org.turro.util.PhraseBuilder;
27 
32 public class ContactList extends ArrayList<IContact> {
33 
34  @Override
35  public boolean add(IContact e) {
36  if(e == null || !e.isValid()) return false;
37  if(!contains(e)) {
38  return super.add(e);
39  }
40  return false;
41  }
42 
43  public boolean addObject(Object e) {
44  if(e == null) return false;
45  return super.add(Contacts.getContact(e));
46  }
47 
48  @Override
49  public boolean addAll(Collection<? extends IContact> collection) {
50  for(IContact c : collection) {
51  add(c);
52  }
53  return true;
54  }
55 
56  public String getCommaSeparatedId() {
57  PhraseBuilder pb = new PhraseBuilder();
58  for(IContact c : this) {
59  pb.addWord("'" + c.getId() + "'");
60  pb.addPendingSeparator(",");
61  }
62  return pb.toString();
63  }
64 
65  public String getCommaSeparatedEmails() {
66  PhraseBuilder pb = new PhraseBuilder();
67  for(IContact c : this) {
68  if(c != null && c.isWebUser()) {
69  pb.addWord(c.getConnector(IUser.CONNECTOR_EMAIL));
70  pb.addPendingSeparator(",");
71  }
72  }
73  return pb.toString();
74  }
75 
76  public List<IContact> getCompanies() {
77  return this.stream().filter(c -> c.isCompany()).collect(Collectors.toList());
78  }
79 
80  public List<IContact> getWorkers() {
81  return this.stream().filter(c -> c.isWorker()).collect(Collectors.toList());
82  }
83 
84  public List<IContact> getCenters() {
85  return this.stream().filter(c -> c.isCenter()).collect(Collectors.toList());
86  }
87 
88  public List<IContact> getStudents() {
89  return this.stream().filter(c -> c.isStudent()).collect(Collectors.toList());
90  }
91 
92  public Collection<IContact> getBusiness() {
93  ContactList list = new ContactList();
94  for(IContact contact : this) {
95  List<IContact> l = contact.getBusinessList();
96  if(l == null || l.isEmpty()) {
97  l.add(contact);
98  }
99  list.addAll(l);
100  }
101  return list;
102  }
103 
104  public Collection<IContact> getCoworkers() {
105  ContactList list = new ContactList();
106  for(IContact contact : getBusiness()) {
107  list.addAll(contact.getCoworkers());
108  }
109  return list;
110  }
111 
112 }
static IContact getContact(Object object)
Definition: Contacts.java:109
static final String CONNECTOR_EMAIL
Definition: IUser.java:27
List< IContact > getBusinessList()