1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.util.Comparator ; 22 23 public class ProjectModel extends GenericModel implements Comparator { 24 private String name; 25 private String description; 26 private int status; 27 private int options; 28 private CustomFieldModel[] fields; 29 private ComponentModel[] components = null; 30 private VersionModel[] versions = null; 31 private UserModel[] owners = null; 32 33 public ProjectModel() { 34 name = ""; 35 description = ""; 36 } 37 38 public String getName() { 39 return name; 40 } 41 42 public void setName(String value) { 43 name = value; 44 } 45 46 public String getDescription() { 47 return (description == null ? "" : description); 48 } 49 50 public void setDescription(String value) { 51 description = value; 52 } 53 54 public int getStatus() { 55 return status; 56 } 57 58 public void setStatus(int value) { 59 status = value; 60 } 61 62 public int getOptions() { 63 return (options < 0 ? 0 : options); 64 } 65 66 public void setOptions(int value) { 67 options = (value < 0 ? 0 : value); 68 } 69 70 public CustomFieldModel[] getCustomFields() { 71 return (fields == null ? new CustomFieldModel[0] : fields); 72 } 73 74 public void setCustomFields(CustomFieldModel[] value) { 75 fields = (value == null ? new CustomFieldModel[0] : value); 76 } 77 78 public ComponentModel[] getComponents() { 79 return (components == null ? new ComponentModel[0] : components); 80 } 81 82 public void setComponents(ComponentModel[] value) { 83 if(value != null ) { 84 components = new ComponentModel[value.length]; 85 System.arraycopy((Object ) value, 0, (Object ) components, 0, components.length); 86 } 87 } 88 89 public VersionModel[] getVersions() { 90 return (versions == null ? new VersionModel[0] : versions); 91 } 92 93 public void setVersions(VersionModel[] value) { 94 if(value != null ) { 95 versions = new VersionModel[value.length]; 96 System.arraycopy((Object ) value, 0, (Object ) versions, 0, versions.length); 97 } 98 } 99 100 public UserModel[] getOwners() { 101 return (owners == null ? new UserModel[0] : owners); 102 } 103 104 public void setOwners(UserModel[] value) { 105 if(value != null) { 106 owners = new UserModel[value.length]; 107 System.arraycopy((Object ) value, 0, (Object ) owners, 0, owners.length); 108 } 109 } 110 111 public String toString() { 112 return "Project [" + getId() + "] Name: " + getName() + " Description: " + getDescription() + 113 " Num Components: " + getComponents().length + " Num Versions: " + getVersions().length + 114 " Num Custom Fields: " + getCustomFields().length + " Num Owners: " + getOwners().length; 115 } 116 117 public int compare(Object a, Object b) { 118 return this.new CompareByName().compare(a, b); 119 } 120 121 public boolean equals(Object obj) { 122 return this.new CompareByName().equals(obj); 123 } 124 125 public int hashCode() { 126 return this.new CompareByName().hashCode(); 127 } 128 129 public class CompareByName implements Comparator { 130 protected boolean isAscending = true; 131 132 public CompareByName() { 133 } 134 135 public CompareByName(boolean isAscending) { 136 setAscending(isAscending); 137 } 138 139 public void setAscending(boolean value) { 140 this.isAscending = value; 141 } 142 143 public int compare(Object a, Object b) { 144 int result = 0; 145 if(! (a instanceof ProjectModel) || ! (b instanceof ProjectModel)) { 146 throw new ClassCastException (); 147 } 148 149 ProjectModel ma = (ProjectModel) a; 150 ProjectModel mb = (ProjectModel) b; 151 152 if(ma.getName() == null && mb.getName() == null) { 153 result = 0; 154 } else if(ma.getName() == null) { 155 result = 1; 156 } else if(mb.getName() == null) { 157 result = -1; 158 } else { 159 result = ma.getName().compareTo(mb.getName()); 160 } 161 162 return (isAscending ? result : result * -1); 163 } 164 165 public boolean equals(Object obj) { 166 if(! (obj instanceof ProjectModel)) { 167 return false; 168 } 169 170 try { 171 ProjectModel mo = (ProjectModel) obj; 172 if(ProjectModel.this.getId().equals(mo.getId())) { 173 return true; 174 } 175 } catch(ClassCastException cce) { 176 } 177 178 return false; 179 } 180 181 public int hashCode() { 182 return (ProjectModel.this.getId() == null ? 1 : ProjectModel.this.getId().intValue()); 183 } 184 } 185 186 } | Popular Tags |