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.facets;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  
22  import nl.hippo.client.api.content.Facet;
23  import nl.hippo.client.api.content.FacetCollection;
24  
25  import org.apache.commons.lang.builder.EqualsBuilder;
26  import org.apache.commons.lang.builder.HashCodeBuilder;
27  import org.apache.commons.lang.builder.ToStringBuilder;
28  import org.apache.commons.lang.builder.ToStringStyle;
29  
30  public class FacetCollectionImpl implements FacetCollection {
31  
32      HashMap facetsMap;
33  
34      private FacetCollectionImpl() {
35      }
36  
37      public FacetCollectionImpl(HashMap facets) {
38          this.facetsMap = facets;
39      }
40  
41      public List getFacets() {
42          return new ArrayList(facetsMap.values());
43      }
44  
45      public Facet getFacet(String name) {
46          return (Facet) facetsMap.get(name);
47      }
48  
49      public String toString() {
50          return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("FacetCount", facetsMap.size()).append(
51                  "Facets", facetsMap).toString();
52      }
53  
54      public boolean equals(Object obj) {
55          if (obj instanceof FacetCollectionImpl == false) {
56              return false;
57          }
58          if (this == obj) {
59              return true;
60          }
61          FacetCollectionImpl rhs = (FacetCollectionImpl) obj;
62          return new EqualsBuilder().append(facetsMap, rhs.facetsMap).isEquals();
63      }
64  
65      public int hashCode() {
66          return new HashCodeBuilder(71, 33).append(facetsMap).toHashCode();
67      }
68  
69  }