BrightSide Workbench Full Report + Source Code
IssueDetailComparator.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.issue;
19 
20 import java.util.Comparator;
21 import java.util.Date;
22 import org.turro.attach.entity.Attachment;
23 import org.turro.contacts.CommentIt;
24 import org.turro.contacts.StarIt;
25 import org.turro.contacts.VoteIt;
26 import org.turro.dossier.entity.IssueComment;
27 import org.turro.dossier.entity.IssuePredecessor;
28 import org.turro.util.CompareUtil;
29 
34 public class IssueDetailComparator implements Comparator {
35 
36  @Override
37  public int compare(Object o1, Object o2) {
38  int result = CompareUtil.compare(getDate(o1), getDate(o2));
39  if(result == 0) {
40  result = CompareUtil.compare(getDescription(o1), getDescription(o2));
41  }
42  if(result == 0) {
43  result = CompareUtil.compare(getId(o1), getId(o2));
44  }
45  return result;
46  }
47 
48  private long getId(Object obj) {
49  if(obj instanceof IssueComment) {
50  return ((IssueComment) obj).getId();
51  } else if(obj instanceof IssuePredecessor) {
52  return ((IssuePredecessor) obj).getId();
53  } else if(obj instanceof Attachment) {
54  return ((Attachment) obj).getId();
55  } else if(obj instanceof CommentIt) {
56  return ((CommentIt) obj).getDateCreation().getTime();
57  } else if(obj instanceof StarIt) {
58  return ((StarIt) obj).getDateCreation().getTime();
59  } else if(obj instanceof VoteIt) {
60  return ((VoteIt) obj).getDateCreation().getTime();
61  }
62  return 0;
63  }
64 
65  private Date getDate(Object obj) {
66  if(obj instanceof IssueComment) {
67  return ((IssueComment) obj).getModification();
68  } else if(obj instanceof IssuePredecessor) {
69  return ((IssuePredecessor) obj).getCreation();
70  } else if(obj instanceof Attachment) {
71  return ((Attachment) obj).getModification();
72  } else if(obj instanceof CommentIt) {
73  return ((CommentIt) obj).getDateCreation();
74  } else if(obj instanceof StarIt) {
75  return ((StarIt) obj).getDateCreation();
76  } else if(obj instanceof VoteIt) {
77  return ((VoteIt) obj).getDateCreation();
78  }
79  return null;
80  }
81 
82  private String getDescription(Object obj) {
83  if(obj instanceof IssueComment) {
84  return ((IssueComment) obj).getComment();
85  } else if(obj instanceof IssuePredecessor) {
86  return ((IssuePredecessor) obj).getFullDescription();
87  } else if(obj instanceof Attachment) {
88  return ((Attachment) obj).getFileName();
89  } else if(obj instanceof CommentIt) {
90  return ((CommentIt) obj).getId();
91  } else if(obj instanceof StarIt) {
92  return ((StarIt) obj).getId();
93  } else if(obj instanceof VoteIt) {
94  return ((VoteIt) obj).getId();
95  }
96  return null;
97  }
98 
99 }