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.Iterator;
20  import java.util.List;
21  
22  import nl.hippo.client.api.content.Facet;
23  import nl.hippo.client.api.content.FacetValue;
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 FacetImpl implements Facet {
31  
32      private String name;
33      private ArrayList values;
34  
35      private FacetImpl() {
36      }
37  
38      public FacetImpl(String name, List values) {
39          this.name = name;
40          this.values = new ArrayList(values);
41      }
42  
43      public String getName() {
44          return name;
45      }
46  
47      public List getValues() {
48          return values;
49      }
50  
51      public String toString() {
52          ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("ValueCount",
53                  values.size()).append("Name", name);
54  
55          Iterator it = values.iterator();
56          while (it.hasNext()) {
57              FacetValue value = (FacetValue) it.next();
58              builder.append(value.toString());
59          }
60          return builder.toString();
61      }
62  
63      public boolean equals(Object obj) {
64          if (obj instanceof FacetImpl == false) {
65              return false;
66          }
67          if (this == obj) {
68              return true;
69          }
70          FacetImpl rhs = (FacetImpl) obj;
71          return new EqualsBuilder().append(values, rhs.values).append(name, rhs.name).isEquals();
72      }
73  
74      public int hashCode() {
75          return new HashCodeBuilder(77, 93).append(name).append(values).toHashCode();
76      }
77  }