01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: /** <p>A simple collection of <code>NameBean</code>'s.</p>
25: *
26: * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
27: */
28: public class ListOfNames {
29:
30: private List names = new ArrayList();
31:
32: public ListOfNames() {
33: }
34:
35: public void addName(NameBean name) {
36: names.add(name);
37: }
38:
39: public List getNames() {
40: return names;
41: }
42:
43: public String toString() {
44: StringBuffer buffer = new StringBuffer("[");
45: buffer.append("ListOfNames: ");
46: boolean first = true;
47: Iterator it = names.iterator();
48: while (it.hasNext()) {
49: if (first) {
50: first = !first;
51: } else {
52: buffer.append(',');
53: }
54: buffer.append("'");
55: buffer.append(((NameBean) it.next()).getName());
56: buffer.append("'");
57: }
58:
59: buffer.append("]");
60:
61: return buffer.toString();
62: }
63:
64: public boolean equals(Object obj) {
65: if (obj == null)
66: return false;
67: if (obj instanceof ListOfNames) {
68: ListOfNames otherList = (ListOfNames) obj;
69: int count = 0;
70: Iterator it = otherList.getNames().iterator();
71: while (it.hasNext()) {
72: if (!names.get(count++).equals(it.next())) {
73: return false;
74: }
75: }
76:
77: return true;
78: }
79:
80: return false;
81: }
82: }
|