1 9 package org.apache.ojb.odmg.shared; 10 11 import org.apache.commons.lang.builder.ToStringBuilder; 12 import org.apache.commons.lang.builder.ToStringStyle; 13 14 import java.io.Serializable ; 15 import java.util.ArrayList ; 16 import java.util.Arrays ; 17 18 public class PersonImpl implements Person, Serializable 19 { 20 private int id; 22 private int motherId; 23 private int fatherId; 24 25 private String firstname; 27 private String lastname; 28 private Person mother; 29 private Person father; 30 private Person[] children; 31 32 public PersonImpl() 33 { 34 } 35 36 public String getFirstname() 37 { 38 return firstname; 39 } 40 41 public String getLastname() 42 { 43 return lastname; 44 } 45 46 public Person getMother() 47 { 48 return mother; 49 } 50 51 public Person getFather() 52 { 53 return father; 54 } 55 56 public Person[] getChildren() 57 { 58 return children; 59 } 60 61 public void setFirstname(String pFirstname) 62 { 63 firstname = pFirstname; 64 } 65 66 public void setLastname(String pLastname) 67 { 68 lastname = pLastname; 69 } 70 71 public void setMother(Person pMother) 72 { 73 mother = pMother; 74 } 75 76 public void setFather(Person pFather) 77 { 78 father = pFather; 79 } 80 81 public void setChildren(Person[] pChildren) 82 { 83 children = pChildren; 84 } 85 86 public void addChild(Person pChild) 87 { 88 int numOfChildren = ((children == null) ? 0 : children.length); 89 Person[] newKids = new Person[numOfChildren + 1]; 90 ArrayList list = new ArrayList (Arrays.asList(children)); 91 list.add(pChild); 92 list.toArray(newKids); 93 } 94 95 99 public int getFatherId() 100 { 101 return fatherId; 102 } 103 104 108 public void setFatherId(int fatherId) 109 { 110 this.fatherId = fatherId; 111 } 112 113 117 public int getId() 118 { 119 return id; 120 } 121 122 126 public void setId(int id) 127 { 128 this.id = id; 129 } 130 131 135 public int getMotherId() 136 { 137 return motherId; 138 } 139 140 144 public void setMotherId(int motherId) 145 { 146 this.motherId = motherId; 147 } 148 149 public String toString() 150 { 151 ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); 152 buf.append("id", id); 153 buf.append("firstname", firstname); 154 buf.append("lastname", lastname); 155 buf.append("motherId", motherId); 156 buf.append("mother", mother != null ? "PersonImpl@" + System.identityHashCode(mother) + "(" + motherId + ")" : null); 157 buf.append("fatherId", fatherId); 158 buf.append("father", father != null ? "PersonImpl@" + System.identityHashCode(father) + "(" + fatherId + ")" : null); 159 return buf.toString(); 160 } 161 } 162 | Popular Tags |