1 16 17 package org.apache.commons.betwixt; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 27 public class ListOfNames { 28 29 private List names = new ArrayList (); 30 31 public ListOfNames() {} 32 33 public void addName(NameBean name) { 34 names.add(name); 35 } 36 37 public List getNames() { 38 return names; 39 } 40 41 public String toString() { 42 StringBuffer buffer = new StringBuffer ("["); 43 buffer.append("ListOfNames: "); 44 boolean first = true; 45 Iterator it = names.iterator(); 46 while ( it.hasNext() ) { 47 if ( first ) { 48 first = !first; 49 } else { 50 buffer.append(','); 51 } 52 buffer.append("'"); 53 buffer.append( ((NameBean) it.next()).getName() ); 54 buffer.append("'"); 55 } 56 57 buffer.append("]"); 58 59 return buffer.toString(); 60 } 61 62 public boolean equals( Object obj ) { 63 if ( obj == null ) return false; 64 if (obj instanceof ListOfNames) { 65 ListOfNames otherList = (ListOfNames) obj; 66 int count = 0; 67 Iterator it = otherList.getNames().iterator(); 68 while (it.hasNext()) { 69 if (! names.get(count++).equals(it.next())) { 70 return false; 71 } 72 } 73 74 return true; 75 } 76 77 return false; 78 } 79 } 80 | Popular Tags |