1 16 17 package info.jtrac.domain; 18 19 import java.io.Serializable ; 20 21 32 public class ItemItem implements Serializable { 33 34 private long id; 35 private Item item; 36 private Item relatedItem; 37 private int type; 38 39 public static int RELATED = 0; 40 public static int DUPLICATE_OF = 1; 41 public static int DEPENDS_ON = 2; 42 43 public static String getRelationText(int type) { 45 if (type == RELATED) { 46 return "relatedTo"; 47 } else if (type == DUPLICATE_OF) { 48 return "duplicateOf"; 49 } else if (type == DEPENDS_ON) { 50 return "dependsOn"; 51 } else { 52 throw new RuntimeException ("unknown type: " + type); 53 } 54 } 55 56 public ItemItem() { 57 } 59 60 public ItemItem(Item item, Item relatedItem, int type) { 61 this.item = item; 62 this.relatedItem = relatedItem; 63 this.type = type; 64 } 65 66 public String getRelationText() { 67 return getRelationText(type); 68 } 69 70 72 public long getId() { 73 return id; 74 } 75 76 public void setId(long id) { 77 this.id = id; 78 } 79 80 public Item getItem() { 81 return item; 82 } 83 84 public void setItem(Item item) { 85 this.item = item; 86 } 87 88 public Item getRelatedItem() { 89 return relatedItem; 90 } 91 92 public void setRelatedItem(Item relatedItem) { 93 this.relatedItem = relatedItem; 94 } 95 96 public int getType() { 97 return type; 98 } 99 100 public void setType(int type) { 101 this.type = type; 102 } 103 104 @Override 105 public String toString() { 106 StringBuffer sb = new StringBuffer (); 107 sb.append("id [").append(id); 108 sb.append("]; item [").append(item); 109 sb.append("]; type [").append(type); 110 sb.append("]"); 111 return sb.toString(); 112 } 113 114 @Override 115 public boolean equals(Object o) { 116 if (this == o) { 117 return true; 118 } 119 if (!(o instanceof ItemItem)) { 120 return false; 121 } 122 final ItemItem ii = (ItemItem) o; 123 return (item.equals(ii.getItem()) && type == ii.getType()); 124 } 125 126 @Override 127 public int hashCode() { 128 int hash = 7; 129 hash = hash * 31 + item.hashCode(); 130 hash = hash * 31 + type; 131 return hash; 132 } 133 134 } 135 | Popular Tags |