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