1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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      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  }