1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.util.Comparator ; 22 23 import cowsultants.itracker.ejb.client.util.ReportUtilities; 24 25 public class ReportModel extends GenericModel implements Comparator { 26 private String name; 27 private String nameKey; 28 private String description; 29 private int dataType; 30 private int reportType; 31 private byte[] fileData; 32 private String className; 33 34 public ReportModel() { 35 name = ""; 36 nameKey = null; 37 description = ""; 38 dataType = 0; 39 reportType = 0; 40 fileData = new byte[0]; 41 className = null; 42 } 43 44 public String getName() { 45 return name; 46 } 47 48 public void setName(String value) { 49 name = value; 50 } 51 52 public String getNameKey() { 53 return nameKey; 54 } 55 56 public void setNameKey(String value) { 57 nameKey = value; 58 } 59 60 public String getDescription() { 61 return description; 62 } 63 64 public void setDescription(String value) { 65 description = value; 66 } 67 68 public int getDataType() { 69 return dataType; 70 } 71 72 public void setDataType(int value) { 73 dataType = value; 74 } 75 76 public int getReportType() { 77 return reportType; 78 } 79 80 public void setReportType(int value) { 81 reportType = value; 82 } 83 84 public byte[] getFileData() { 85 return fileData; 86 } 87 88 public void setFileData(byte[] value) { 89 fileData = (value != null && value.length > 0 ? value : new byte[0]); 90 } 91 92 public String getClassName() { 93 return className; 94 } 95 96 public void setClassName(String value) { 97 className = value; 98 } 99 100 public String toString() { 101 return "Report [" + getId() + "] Name: " + getName() + " Name Key: " + getNameKey() + " Data Type: " + getDataType() + 102 " Report Type: " + getReportType() + " Class: " + getClassName() + " Definition Size: " + getFileData().length; 103 } 104 105 public int compare(Object a, Object b) { 106 return this.new CompareById().compare(a, b); 107 } 108 109 public boolean equals(Object obj) { 110 return this.new CompareById().equals(obj); 111 } 112 113 public int hashCode() { 114 return this.new CompareById().hashCode(); 115 } 116 117 public abstract class ReportModelComparator implements Comparator { 118 protected boolean isAscending = true; 119 120 public ReportModelComparator() { 121 } 122 123 public ReportModelComparator(boolean isAscending) { 124 setAscending(isAscending); 125 } 126 127 public void setAscending(boolean value) { 128 this.isAscending = value; 129 } 130 131 public boolean equals(Object obj) { 132 if(! (obj instanceof ReportModel)) { 133 return false; 134 } 135 136 try { 137 ReportModel mo = (ReportModel) obj; 138 if(ReportModel.this.getId() == mo.getId()) { 139 return true; 140 } 141 } catch(ClassCastException cce) { 142 } 143 144 return false; 145 } 146 147 public int hashCode() { 148 return (ReportModel.this.getId() == null ? 1 : ReportModel.this.getId().intValue()); 149 } 150 151 public final int compare(Object a, Object b) { 152 if(! (a instanceof ReportModel) || ! (b instanceof ReportModel)) { 153 throw new ClassCastException (); 154 } 155 156 ReportModel ma = (ReportModel) a; 157 ReportModel mb = (ReportModel) b; 158 159 int result = doComparison(ma, mb); 160 if(! isAscending) { 161 result = result * -1; 162 } 163 return result; 164 } 165 166 protected int doComparison(ReportModel ma, ReportModel mb) { 167 if(ma.getId() == null) { 168 return -1; 169 } else if(mb.getId() == null) { 170 return 1; 171 } 172 173 return ma.getId().compareTo(mb.getId()); 174 } 175 } 176 177 public class CompareById extends ReportModelComparator { 178 public CompareById(){ 179 super(); 180 } 181 182 public CompareById(boolean isAscending) { 183 super(isAscending); 184 } 185 } 186 187 public class CompareByDefinition extends ReportModelComparator { 188 public CompareByDefinition(){ 189 super(); 190 } 191 192 public CompareByDefinition(boolean isAscending) { 193 super(isAscending); 194 } 195 196 public boolean equals(Object obj) { 197 if(! (obj instanceof ReportModel)) { 198 return false; 199 } 200 201 try { 202 ReportModel mo = (ReportModel) obj; 203 if(ReportModel.this.getName().equals(mo.getName()) && 204 ReportModel.this.getDescription().equals(mo.getDescription()) && 205 ReportModel.this.getNameKey().equals(mo.getNameKey())) { 206 return true; 207 } 208 } catch(Exception e) { 209 } 210 211 return false; 212 } 213 214 public int hashCode() { 215 return ((ReportModel.this.getName() == null ? 1 : ReportModel.this.getName().hashCode()) ^ 216 (ReportModel.this.getDescription() == null ? 1 : ReportModel.this.getDescription().hashCode()) ^ 217 (ReportModel.this.getNameKey() == null ? 1 : ReportModel.this.getNameKey().hashCode())); 218 } 219 } 220 } | Popular Tags |