BrightSide Workbench Full Report + Source Code
NameAttribute.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.proposal;
19 
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Map;
23 import org.turro.string.Strings;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.i18n.I_;
27 
32 public class NameAttribute extends GenericAttribute<Contact> {
33 
35  super(attribute);
37  }
38 
39  @Override
40  protected List<Contact> generateRelated() {
41  ContactsPU cpu = new ContactsPU();
42  List<Contact> list = new ArrayList<Contact>();
43  NamesMap nm = new NamesMap();
44  Map<String, NameEntry> names = nm.getCoincidences(attribute.getName());
45  for(NameEntry ne : names.values()) {
46  Contact c = cpu.find(Contact.class, ne.getId());
47  if(c != null) {
48  list.add(c);
49  }
50  }
51  return list;
52  }
53 
54  @Override
55  public void addToContact(Contact contact) {
56  contact.setName(attribute.getName());
57  contact.getComplexName().setFull(attribute.getName());
58  }
59 
60  @Override
61  public String getAsString() {
62  return attribute.getName();
63  }
64 
65  @Override
66  public Contact getContact() {
67  return attribute;
68  }
69 
70  @Override
71  public String getAttributeName() {
72  return I_.get("Name");
73  }
74 
75  @Override
77  return new IAttribute() {
78 
79  @Override
80  public String getAsString() {
81  return a.getName();
82  }
83 
84  @Override
85  public Contact getContact() {
86  return a;
87  }
88 
89  @Override
90  public Object getValue() {
91  return a;
92  }
93  };
94  }
95 
96  private void capitalize() {
97  attribute.setName(Strings.capitalize(attribute.getName()));
98  }
99 
100 }
void setName(String name)
Definition: Contact.java:217
ComplexName getComplexName()
Definition: Contact.java:152
IAttribute generateAttributeAdapter(final Contact a)
Map< String, NameEntry > getCoincidences(String name)
Definition: NamesMap.java:39
static String get(String msg)
Definition: I_.java:41