BrightSide Workbench Full Report + Source Code
ProfileBusiness.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.contacts.profile;
20 
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.TreeSet;
25 import org.amic.util.date.Dates;
26 import org.turro.contacts.BusinessRelation;
27 import org.turro.contacts.Contact;
28 import org.turro.contacts.relation.Workers;
29 
34 public class ProfileBusiness extends TreeSet<BusinessRelation> {
35 
36  private final Contact contact;
37  private final Date now;
38 
39  public ProfileBusiness(Contact contact) {
40  this.contact = contact;
41  this.now = new Date();
42  load();
43  }
44 
46  return getPrincipal(now);
47  }
48 
49  public BusinessRelation getPrincipal(Date date) {
50  for(BusinessRelation br : this) {
51  if(br.isPreferential() && Dates.inRange(br.getStartDate(), br.getEndDate(), date)) {
52  return br;
53  }
54  }
55  for(BusinessRelation br : this) {
56  if(Dates.inRange(br.getStartDate(), br.getEndDate(), date)) {
57  return br;
58  }
59  }
60  return null;
61  }
62 
63  public List<BusinessRelation> getList() {
64  return getList(now);
65  }
66 
67  public List<BusinessRelation> getList(Date date) {
68  List<BusinessRelation> brs = new ArrayList<>();
69  for(BusinessRelation br : this) {
70  if(Dates.inRange(br.getStartDate(), br.getEndDate(), date)) {
71  brs.add(br);
72  }
73  }
74  return brs;
75  }
76 
77  public List<BusinessRelation> getOutdated() {
78  return getOutdated(now);
79  }
80 
81  public List<BusinessRelation> getOutdated(Date date) {
82  List<BusinessRelation> brs = new ArrayList<>();
83  for(BusinessRelation br : this) {
84  if(!Dates.inRange(br.getStartDate(), br.getEndDate(), date)) {
85  brs.add(br);
86  }
87  }
88  return brs;
89  }
90 
91  public List<BusinessRelation> getCoworkers() {
92  return getCoworkers(now);
93  }
94 
95  public List<BusinessRelation> getCoworkers(Date date) {
96  List<BusinessRelation> brs = new ArrayList<>();
97  for(BusinessRelation br : this) {
98  Workers workers = new Workers(br.getBusiness());
99  brs.addAll(workers);
100  }
101  return brs;
102  }
103 
104  private void load() {
105  addAll(contact.getBusinessRelations());
106  }
107 
108 }
Set< BusinessRelation > getBusinessRelations()
Definition: Contact.java:379
List< BusinessRelation > getList(Date date)
List< BusinessRelation > getOutdated(Date date)
List< BusinessRelation > getCoworkers(Date date)
BusinessRelation getPrincipal(Date date)