1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.util.Comparator ; 22 23 import cowsultants.itracker.ejb.client.util.*; 24 25 public class IssueHistoryModel extends GenericModel implements Comparator { 26 private String description; 27 private int status; 28 29 private Integer issueId; 30 private Integer userId; 31 32 private UserModel user; 33 34 public IssueHistoryModel() { 35 userId = new Integer (-1); 36 } 37 38 public IssueHistoryModel(String description) { 39 this(); 40 this.setDescription(description); 41 this.setStatus(IssueUtilities.HISTORY_STATUS_AVAILABLE); 42 } 43 44 public IssueHistoryModel(String description, int status, Integer issueId, Integer userId) { 45 this(); 46 this.setDescription(description); 47 this.setIssueId(issueId); 48 this.setUserId(userId); 49 this.setStatus(status); 50 } 51 52 public String getDescription() { 53 return description; 54 } 55 56 public void setDescription(String value) { 57 description = value; 58 } 59 60 public int getStatus() { 61 return status; 62 } 63 64 public void setStatus(int value) { 65 status = value; 66 } 67 68 public UserModel getUser() { 69 return user; 70 } 71 72 public void setUser(UserModel value) { 73 user = value; 74 } 75 76 public Integer getUserId() { 77 return (user == null ? userId : user.getId()); 78 } 79 80 public void setUserId(Integer value) { 81 userId = value; 82 } 83 84 public String getUserLogin() { 85 return (user == null ? "" : user.getLogin()); 86 } 87 88 public String getUserFirstName() { 89 return (user == null ? "" : user.getFirstName()); 90 } 91 92 public String getUserLastName() { 93 return (user == null ? "" : user.getLastName()); 94 } 95 96 public String getUserEmail() { 97 return (user == null ? "" : user.getEmail()); 98 } 99 100 public Integer getIssueId() { 101 return issueId; 102 } 103 104 public void setIssueId(Integer value) { 105 issueId = value; 106 } 107 108 public int compare(Object a, Object b) { 109 return this.new CompareByDate().compare(a, b); 110 } 111 112 public boolean equals(Object obj) { 113 return this.new CompareByDate().equals(obj); 114 } 115 116 public int hashCode() { 117 return this.new CompareByDate().hashCode(); 118 } 119 120 public String toString() { 121 return "IssueHistory [" + this.getId() + "] Issue: " + this.getIssueId() + " Creator: " + this.getUserId() + " Description: " + this.getDescription(); 122 } 123 124 public class CompareByDate implements Comparator { 125 protected boolean isAscending = true; 126 127 public CompareByDate() { 128 } 129 130 public CompareByDate(boolean isAscending) { 131 setAscending(isAscending); 132 } 133 134 public void setAscending(boolean value) { 135 this.isAscending = value; 136 } 137 138 public int compare(Object a, Object b) { 139 int result = 0; 140 141 if(! (a instanceof IssueHistoryModel) || ! (b instanceof IssueHistoryModel)) { 142 throw new ClassCastException (); 143 } 144 145 IssueHistoryModel ma = (IssueHistoryModel) a; 146 IssueHistoryModel mb = (IssueHistoryModel) b; 147 148 if(ma.getCreateDate() == null && mb.getCreateDate() == null) { 149 result = 0; 150 } else if(ma.getCreateDate() == null) { 151 result = 1; 152 } else if(mb.getCreateDate() == null) { 153 result = -1; 154 } else { 155 if(ma.getCreateDate().equals(mb.getCreateDate())) { 156 result = 0; 157 } else if(ma.getCreateDate().before(mb.getCreateDate())) { 158 result = -1; 159 } else { 160 result = 1; 161 } 162 } 163 164 return (isAscending ? result : result * -1); 165 } 166 167 public boolean equals(Object obj) { 168 if(! (obj instanceof IssueHistoryModel)) { 169 return false; 170 } 171 172 try { 173 IssueHistoryModel mo = (IssueHistoryModel) obj; 174 if(IssueHistoryModel.this.getCreateDate().equals(mo.getCreateDate()) && 175 IssueHistoryModel.this.getUserLogin().equals(mo.getUserLogin()) && 176 IssueHistoryModel.this.getDescription().equals(mo.getDescription())) { 177 return true; 178 } 179 } catch(ClassCastException cce) { 180 } 181 182 return false; 183 } 184 185 public int hashCode() { 186 return ((IssueHistoryModel.this.getCreateDate() == null ? 1 : IssueHistoryModel.this.getCreateDate().hashCode()) ^ 187 IssueHistoryModel.this.getUserLogin().hashCode() ^ 188 (IssueHistoryModel.this.getDescription() == null ? 1 : IssueHistoryModel.this.getDescription().hashCode())); 189 } 190 } 191 } | Popular Tags |