BrightSide Workbench Full Report + Source Code
GenericAttribute.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.io.Serializable;
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.turro.contacts.Contact;
24 
29 public abstract class GenericAttribute<A> implements Serializable {
30 
31  protected A attribute;
32  protected transient List<IAttribute> related;
34  protected boolean active;
35 
37  this.attribute = attribute;
38  }
39 
40  public boolean isActive() {
41  return active;
42  }
43 
44  public void setActive(boolean active) {
45  this.active = active;
46  }
47 
48  public A getValue() {
49  return attribute;
50  }
51 
52  public List<IAttribute> getRelated() {
53  if(related == null) {
54  related = adaptAttribute(generateRelated());
55  }
56  return related;
57  }
58 
59  public void checkActive(Contact destination) {
60  active = true;
61  for(IAttribute a : getRelated()) {
62  if(a.getContact().getId().equals(destination.getId())) {
63  active = false;
64  }
65  }
66  }
67 
68  protected abstract List<A> generateRelated();
69 
70  public abstract void addToContact(Contact contact);
71  public abstract String getAsString();
72  public abstract Contact getContact();
73  public abstract String getAttributeName();
74  public abstract IAttribute generateAttributeAdapter(A a);
75 
76  private List<IAttribute> adaptAttribute(List<A> l) {
77  List<IAttribute> list = new ArrayList<IAttribute>();
78  for(A a : l) {
79  list.add(generateAttributeAdapter(a));
80  }
81  return list;
82  }
83 
84 }
abstract void addToContact(Contact contact)
abstract IAttribute generateAttributeAdapter(A a)