1 26 27 29 package de.nava.informa.impl.basic; 30 31 import java.util.Collection ; 32 import java.util.ArrayList ; 33 34 import de.nava.informa.core.CategoryIF; 35 36 41 public class Category implements CategoryIF, java.io.Serializable { 42 43 private long id; 44 private String title; 45 private CategoryIF parent; 46 private Collection children; 47 48 public Category() { 49 this("[Unnamed Category]"); 50 } 51 52 public Category(String title) { 53 this(null, title); 54 } 55 56 public Category(CategoryIF parent, String title) { 57 this.id = IdGenerator.getInstance().getId(); 58 this.title = title; 59 this.parent = parent; 60 this.children = new ArrayList (); 61 } 62 63 67 public long getId() { 68 return id; 69 } 70 71 public void setId(long id) { 72 this.id = id; 73 } 74 75 public String getTitle() { 76 return title; 77 } 78 79 public void setTitle(String title) { 80 this.title = title; 81 } 82 83 public CategoryIF getParent() { 84 return parent; 85 } 86 87 public void setParent(CategoryIF parent) { 88 this.parent = parent; 89 } 90 91 public Collection getChildren() { 92 return children; 93 } 94 95 public void addChild(CategoryIF child) { 96 children.add(child); 97 child.setParent(this); 98 } 99 100 public void removeChild(CategoryIF child) { 101 children.remove(child); 102 } 103 104 108 public boolean equals(Object obj) { 109 if (!(obj instanceof CategoryIF)) { 110 return false; 111 } 112 CategoryIF cmp = (CategoryIF) obj; 113 114 return cmp.getTitle().equals(title) 115 && (cmp.getId() == id); 116 } 117 118 public int hashCode() { 119 return title.hashCode() + new Long (id).hashCode(); 120 } 121 122 public String toString() { 123 return "[Category (" + id + "): " + title + "]"; 124 } 125 126 } 127 | Popular Tags |