BrightSide Workbench Full Report + Source Code
TypedRelationComparator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.util;
20 
21 import java.util.Comparator;
22 import org.turro.contacts.BusinessRelation;
23 import org.turro.contacts.organigram.RelationType;
24 import org.turro.util.CompareUtil;
25 
30 public class TypedRelationComparator implements Comparator<BusinessRelation> {
31 
32  @Override
34  int result = -CompareUtil.compareNull(o1.getContact(), o2.getContact());
35  if(result == 0) {
36  result = -CompareUtil.compareNull(o1.getBusiness(), o2.getBusiness());
37  }
38  if(result == 0) {
41  if(rt1 != null && rt2 != null) {
42  result = CompareUtil.compare((rt1.getGroup() * 10000) + rt1.getLevel(), (rt2.getGroup() * 10000) + rt2.getLevel());
43  }
44  }
45  if(result == 0) {
46  result = CompareUtil.compare(o1.getFormattedDescription(), o2.getFormattedDescription());
47  }
48  if(result == 0) {
49  String id1 = o1.getContact() == null ? null : o1.getContact().getId(),
50  id2 = o2.getContact() == null ? null : o2.getContact().getId();
51  result = CompareUtil.compare(id1, id2);
52  }
53  if(result == 0) {
54  String id1 = o1.getBusiness()== null ? null : o1.getBusiness().getId(),
55  id2 = o2.getBusiness()== null ? null : o2.getBusiness().getId();
56  result = CompareUtil.compare(id1, id2);
57  }
58  if(result == 0) {
59  result = CompareUtil.compare(o1.getId(), o2.getId());
60  }
61  return result;
62  }
63 
64 }
int compare(BusinessRelation o1, BusinessRelation o2)
static RelationType getFromString(String relation)