View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.context;
21  
22  import org.apache.myfaces.tobago.context.Markup;
23  
24  public final class ThemeConfigCacheKey {
25  
26    private final ClientPropertiesKey clientPropertiesKey;
27    private final String rendererType;
28    private final String name;
29    private final Markup markup;
30    private final int hashCode;
31  
32    public ThemeConfigCacheKey(
33        final ClientPropertiesKey clientPropertiesKey, final String rendererType, final Markup markup,
34        final String name) {
35      this.clientPropertiesKey = clientPropertiesKey;
36      this.rendererType = rendererType;
37      this.markup = markup;
38      this.name = name;
39      hashCode = calcHashCode();
40    }
41  
42    @Override
43    public boolean equals(final Object o) {
44      if (this == o) {
45        return true;
46      }
47      if (o == null || getClass() != o.getClass()) {
48        return false;
49      }
50  
51      final ThemeConfigCacheKey cacheKey = (ThemeConfigCacheKey) o;
52  
53      if (!rendererType.equals(cacheKey.rendererType)) {
54        return false;
55      }
56      if (!name.equals(cacheKey.name)) {
57        return false;
58      }
59      if (markup != null ? !markup.equals(cacheKey.markup) : cacheKey.markup != null) {
60        return false;
61      }
62      if (!clientPropertiesKey.equals(cacheKey.clientPropertiesKey)) {
63        return false;
64      }
65  
66      return true;
67    }
68  
69    private int calcHashCode() {
70      int result = clientPropertiesKey.hashCode();
71      result = 31 * result + rendererType.hashCode();
72      result = 31 * result + name.hashCode();
73      result = 31 * result + (markup != null ? markup.hashCode() : 0);
74      return result;
75    }
76    
77    @Override
78    public int hashCode() {
79      return hashCode;
80    }
81    
82  
83    @Override
84    public String toString() {
85      return "ThemeConfigCacheKey(" + clientPropertiesKey
86          + "," + rendererType
87          + "," + markup
88          + "," + name + ')';
89    }
90  }