1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.util.Comparator ; 22 23 public class ComponentModel extends GenericModel implements Comparator { 24 private String name; 25 private String description; 26 private Integer projectId; 27 28 public ComponentModel() { 29 name = ""; 30 description = ""; 31 projectId = new Integer (-1); 32 } 33 34 public String getName() { 35 return name; 36 } 37 38 public void setName(String value) { 39 name = value; 40 } 41 42 public String getDescription() { 43 return (description == null ? "" : description); 44 } 45 46 public void setDescription(String value) { 47 description = value; 48 } 49 50 public Integer getProjectId() { 51 return projectId; 52 } 53 54 public void setProjectId(Integer value) { 55 projectId = value; 56 } 57 58 public int compare(Object a, Object b) { 59 return this.new CompareByName().compare(a, b); 60 } 61 62 public boolean equals(Object obj) { 63 return this.new CompareByName().equals(obj); 64 } 65 66 public int hashCode() { 67 return this.new CompareByName().hashCode(); 68 } 69 70 public String toString() { 71 return "Component [" + this.getId() + "] Project: " + this.getProjectId() + " Name: " + this.getName(); 72 } 73 74 public class CompareByName implements Comparator { 75 public int compare(Object a, Object b) { 76 if(! (a instanceof ComponentModel) || ! (b instanceof ComponentModel)) { 77 throw new ClassCastException (); 78 } 79 80 ComponentModel ma = (ComponentModel) a; 81 ComponentModel mb = (ComponentModel) b; 82 83 if(ma.getName() == null && mb.getName() == null) { 84 return 0; 85 } else if(ma.getName() == null) { 86 return 1; 87 } else if(mb.getName() == null) { 88 return -1; 89 } 90 91 return ma.getName().compareTo(mb.getName()); 92 } 93 94 public boolean equals(Object obj) { 95 if(! (obj instanceof ComponentModel)) { 96 return false; 97 } 98 99 try { 100 ComponentModel mo = (ComponentModel) obj; 101 if(ComponentModel.this.getName() == mo.getName()) { 102 return true; 103 } 104 } catch(ClassCastException cce) { 105 } 106 107 return false; 108 } 109 110 public int hashCode() { 111 return (ComponentModel.this.getName() == null ? 1 : ComponentModel.this.getName().hashCode()); 112 } 113 } 114 115 } | Popular Tags |