KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > ListOfNames


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.commons.betwixt;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 /** <p>A simple collection of <code>NameBean</code>'s.</p>
24   *
25   * @author <a HREF="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
26   */

27 public class ListOfNames {
28     
29     private List JavaDoc names = new ArrayList JavaDoc();
30     
31     public ListOfNames() {}
32     
33     public void addName(NameBean name) {
34         names.add(name);
35     }
36     
37     public List JavaDoc getNames() {
38         return names;
39     }
40     
41     public String JavaDoc toString() {
42         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("[");
43         buffer.append("ListOfNames: ");
44         boolean first = true;
45         Iterator JavaDoc 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 JavaDoc obj ) {
63         if ( obj == null ) return false;
64         if (obj instanceof ListOfNames) {
65             ListOfNames otherList = (ListOfNames) obj;
66             int count = 0;
67             Iterator JavaDoc 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