BrightSide Workbench Full Report + Source Code
ParticipantComparator.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.dossier.dossier;
19 
20 import java.util.Comparator;
21 import org.turro.dossier.entity.CategoryParticipant;
22 import org.turro.dossier.entity.IDossierParticipant;
23 import org.turro.dossier.entity.IssueParticipant;
24 import org.turro.dossier.entity.Participant;
25 import org.turro.util.CompareUtil;
26 
31 public class ParticipantComparator implements Comparator {
32 
33  @Override
34  public int compare(Object o1, Object o2) {
35  long id1 = 0L, id2 = 0L;
36  String n1 = null, n2 = null, d1 = null, d2 = null;
37  int r1 = 0, r2 = 0;
38  if(o1 instanceof CategoryParticipant) {
39  id1 = zeroIfNull(((CategoryParticipant) o1).getId());
40  } else if(o1 instanceof Participant) {
41  id1 = zeroIfNull(((Participant) o1).getId());
42  } else if(o1 instanceof IssueParticipant) {
43  id1 = zeroIfNull(((IssueParticipant) o1).getId());
44  }
45  if(o1 instanceof IDossierParticipant) {
46  n1 = ((IDossierParticipant) o1).getName();
47  d1 = ((IDossierParticipant) o1).getDiscriminator();
48  r1 = convertToInt((IDossierParticipant) o1);
49  } else if(o1 instanceof IssueParticipant) {
50  n1 = ((IssueParticipant) o1).getName();
51  r1 = convertToInt((IssueParticipant) o1);
52  }
53  if(o2 instanceof CategoryParticipant) {
54  id2 = zeroIfNull(((CategoryParticipant) o2).getId());
55  } else if(o2 instanceof Participant) {
56  id2 = zeroIfNull(((Participant) o2).getId());
57  } else if(o2 instanceof IssueParticipant) {
58  id2 = zeroIfNull(((IssueParticipant) o2).getId());
59  }
60  if(o2 instanceof IDossierParticipant) {
61  n2 = ((IDossierParticipant) o2).getName();
62  d2 = ((IDossierParticipant) o2).getDiscriminator();
63  r2 = convertToInt((IDossierParticipant) o2);
64  } else if(o2 instanceof IssueParticipant) {
65  n2 = ((IssueParticipant) o2).getName();
66  r2 = convertToInt((IssueParticipant) o2);
67  }
68  int result = CompareUtil.compare(r1, r2);
69  if(result == 0) result = CompareUtil.compare(n1, n2);
70  if(result == 0) result = CompareUtil.compare(d1, d2);
71  if(result == 0) result = CompareUtil.compare(id1, id2);
72  return result;
73  }
74 
75  private int convertToInt(IDossierParticipant participant) {
76  int result = 0;
77  switch (participant.getRole()) {
78  case PARTICIPANT_SUBJECT:
79  result = 5000;
80  break;
81  case PARTICIPANT_OWNER:
82  result = 6000;
83  break;
84  case PARTICIPANT_ASSISTANT:
85  result = 7000;
86  break;
87  default:
88  break;
89  }
90  if(participant.isShowAllIssues()) {
91  result -= 13;
92  }
93  if(participant.isShowAllAttachments()) {
94  result -= 12;
95  }
96  if(participant.isShowParticipants()) {
97  result -= 11;
98  }
99  if(participant.isAdmin()) {
100  result -= 10;
101  }
102  if(participant.isDriver()) {
103  result -= 9;
104  }
105  if(participant.isCoordinator()) {
106  result -= 8;
107  }
108  if(participant.isBeneficiary()) {
109  result -= 7;
110  }
111  if(participant.isOfferer()) {
112  result -= 6;
113  }
114  if(participant.isBindingVote()) {
115  result -= 5;
116  }
117  if(participant.isReceiveAllEmails()) {
118  result -= 4;
119  }
120  if(participant.isSupport()) {
121  result -= 3;
122  }
123  if(participant.isResearch()) {
124  result -= 2;
125  }
126  if(participant.isFunding()) {
127  result -= 1;
128  }
129  return result;
130  }
131 
132  private int convertToInt(IssueParticipant participant) {
133  int result = 0;
134  switch (participant.getRole()) {
135  case ISSUE_REPORTER:
136  result = 1000;
137  break;
138  case ISSUE_RESPONSIBLE:
139  result = 2000;
140  break;
141  case ISSUE_QA:
142  result = 3000;
143  break;
144  case ISSUE_ASSISTANT:
145  result = 4000;
146  break;
147  default:
148  break;
149  }
150  return result;
151  }
152 
153  private long zeroIfNull(Long value) {
154  if(value == null) {
155  return 0;
156  }
157  return value;
158  }
159 
160 }