View Javadoc

1   /*
2    * Copyright 2007 Hippo
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" 
12   * BASIS, 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  package nl.hippo.client.webdav.binding.content;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import nl.hippo.client.api.content.DocumentCollection;
23  
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  import org.apache.commons.lang.builder.ToStringStyle;
26  
27  /**
28   * Java binding for a searchresult XML fragment
29   */
30  public class DocumentCollectionImpl implements DocumentCollection {
31  
32      private static final long serialVersionUID = 1L;
33  
34      private ArrayList documents;
35  
36      private DocumentCollectionImpl() {
37      }
38  
39      public DocumentCollectionImpl(List documents) {
40          this.documents = new ArrayList(documents);
41      }
42  
43      public List getDocuments() {
44          return documents;
45      }
46  
47      public String toString() {
48          ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("ResourceCount",
49                  documents.size());
50  
51          Iterator it = documents.iterator();
52          while (it.hasNext()) {
53              DocumentImpl resource = (DocumentImpl) it.next();
54              builder.append(resource.toString());
55          }
56          return builder.toString();
57      }
58  
59      public boolean equals(Object obj) {
60          boolean eq;
61          if (obj == null) {
62              eq = false;
63          } else if (!(obj instanceof DocumentCollectionImpl)) {
64              eq = false;
65          } else if (this == obj) {
66              eq = true;
67          } else {
68              DocumentCollectionImpl rhs = (DocumentCollectionImpl) obj;
69              if (documents == null) {
70                  eq = (rhs.documents == null);
71              } else {
72                  eq = (documents.equals(rhs.documents));
73              }
74          }
75          return eq;
76      }
77  
78      public int hashCode() {
79          int result;
80          if (documents == null) {
81              result = 0;
82          } else {
83              result = documents.hashCode();
84          }
85          return result;
86      }
87  
88  }