1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.util.Comparator ; 22 23 public class NotificationModel extends GenericModel implements Comparator { 24 private int type; 25 private String login; 26 private String firstName; 27 private String lastName; 28 private String email; 29 private Integer userId; 30 private Integer issueId; 31 32 public NotificationModel() { 33 login = ""; 34 firstName = ""; 35 lastName = ""; 36 email = ""; 37 userId = new Integer (-1); 38 issueId = new Integer (-1); 39 } 40 41 public NotificationModel(int type) { 42 this.setNotificationRole(type); 43 } 44 45 public NotificationModel(UserModel user, Integer issueId, int type) { 46 this.setUserLogin(user.getLogin()); 47 this.setUserFirstName(user.getFirstName()); 48 this.setUserLastName(user.getLastName()); 49 this.setUserEmail(user.getEmail()); 50 this.setUserId(user.getId()); 51 this.setIssueId(issueId); 52 this.setNotificationRole(type); 53 } 54 55 public int getNotificationRole() { 56 return type; 57 } 58 59 public void setNotificationRole(int value) { 60 type = value; 61 } 62 63 public String getUserLogin() { 64 return login; 65 } 66 67 public void setUserLogin(String value) { 68 login = value; 69 } 70 71 public String getUserFirstName() { 72 return firstName; 73 } 74 75 public void setUserFirstName(String value) { 76 firstName = value; 77 } 78 79 public String getUserLastName() { 80 return lastName; 81 } 82 83 public void setUserLastName(String value) { 84 lastName = value; 85 } 86 87 public String getUserEmail() { 88 return email; 89 } 90 91 public void setUserEmail(String value) { 92 email = value; 93 } 94 95 public Integer getIssueId() { 96 return issueId; 97 } 98 99 public void setIssueId(Integer value) { 100 issueId = value; 101 } 102 103 public Integer getUserId() { 104 return userId; 105 } 106 107 public void setUserId(Integer value) { 108 userId = value; 109 } 110 111 public int compare(Object a, Object b) { 112 return this.new CompareByName().compare(a, b); 113 } 114 115 public boolean equals(Object obj) { 116 return this.new CompareByName().equals(obj); 117 } 118 119 public int hashCode() { 120 return this.new CompareByName().hashCode(); 121 } 122 123 public abstract class NotificationModelComparator implements Comparator { 124 protected boolean isAscending = true; 125 126 public NotificationModelComparator() { 127 } 128 129 public NotificationModelComparator(boolean isAscending) { 130 setAscending(isAscending); 131 } 132 133 public void setAscending(boolean value) { 134 this.isAscending = value; 135 } 136 137 protected abstract int doComparison(NotificationModel ma, NotificationModel mb); 138 139 public final boolean equals(Object obj) { 140 if(! (obj instanceof NotificationModel)) { 141 return false; 142 } 143 144 try { 145 NotificationModel mo = (NotificationModel) obj; 146 if(NotificationModel.this.getUserLogin().equals(mo.getUserLogin())) { 147 return true; 148 } 149 } catch(ClassCastException cce) { 150 } 151 152 return false; 153 } 154 155 public int hashCode() { 156 return ((NotificationModel.this.getUserLogin() == null ? 1 : NotificationModel.this.getUserLogin().hashCode())); 157 } 158 159 public final int compare(Object a, Object b) { 160 if(! (a instanceof NotificationModel) || ! (b instanceof NotificationModel)) { 161 throw new ClassCastException (); 162 } 163 164 NotificationModel ma = (NotificationModel) a; 165 NotificationModel mb = (NotificationModel) b; 166 167 int result = doComparison(ma, mb); 168 if(! isAscending) { 169 result = result * -1; 170 } 171 return result; 172 } 173 } 174 175 176 public class CompareByName extends NotificationModelComparator { 177 public CompareByName(){ 178 super(); 179 } 180 181 public CompareByName(boolean isAscending) { 182 super(isAscending); 183 } 184 185 protected int doComparison(NotificationModel ma, NotificationModel mb) { 186 if(ma.getUserLastName() == null && mb.getUserLastName() == null) { 187 return 0; 188 } else if(ma.getUserLastName() == null) { 189 return 1; 190 } else if(mb.getUserLastName() == null) { 191 return -1; 192 } 193 194 return (ma.getUserLastName().compareTo(mb.getUserLastName()) == 0 ? 195 ma.getUserFirstName().compareTo(mb.getUserFirstName()) : 196 ma.getUserLastName().compareTo(mb.getUserLastName())); 197 } 198 } 199 200 public class CompareByType extends NotificationModelComparator { 201 public CompareByType(){ 202 super(); 203 } 204 205 public CompareByType(boolean isAscending) { 206 super(isAscending); 207 } 208 209 protected int doComparison(NotificationModel ma, NotificationModel mb) { 210 if(ma.getNotificationRole() == mb.getNotificationRole()) { 211 return 0; 212 } else if(ma.getNotificationRole() < mb.getNotificationRole()) { 213 return -1; 214 } else { 215 return 1; 216 } 217 } 218 } 219 220 } | Popular Tags |