BrightSide Workbench Full Report + Source Code
AssistantSet.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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 
19 package org.turro.assistant;
20 
21 import java.util.Collection;
22 import java.util.HashSet;
23 import org.turro.string.Strings;
24 import org.turro.elephant.security.IUser;
25 import org.turro.plugin.contacts.IContact;
26 import org.turro.util.PhraseBuilder;
27 
32 public class AssistantSet extends HashSet<Assistant> {
33 
34  private final HashSet<String> subject = new HashSet<>();
35 
36  public void addContacts(Collection<IContact> contacts) {
37  for(IContact c : contacts) {
38  addContact(c, null);
39  }
40  }
41 
42  public void addContact(IContact contact, Object relationEntity) {
43  if(contact != null && contact.isWebUser()) {
44  add(new Assistant(contact.getName(), contact.getConnector(IUser.CONNECTOR_EMAIL), contact, relationEntity));
45  }
46  }
47 
48  public void addUser(String name, String email, Object relationEntity) {
49  if(!Strings.isBlank(email)) {
50  add(new Assistant(Strings.isBlank(name, email), email, null, relationEntity));
51  }
52  }
53 
54  public void addSubject(String value) {
55  subject.add(value);
56  }
57 
58  public String getSubject() {
59  PhraseBuilder pb = new PhraseBuilder();
60  for(String s : subject) {
61  pb.addWord(s);
62  pb.addPendingSeparator(",");
63  }
64  return pb.toString();
65  }
66 
67  public boolean exists(IContact contact) {
68  return contains(new Assistant(contact.getName(), contact.getConnector(IUser.CONNECTOR_EMAIL), contact, null));
69  }
70 
71 }
boolean exists(IContact contact)
void addUser(String name, String email, Object relationEntity)
void addContacts(Collection< IContact > contacts)
void addContact(IContact contact, Object relationEntity)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27