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  public final class RendererCacheKey {
23    private final ClientPropertiesKey cacheKey;
24    private final String name;
25    private final int hashCode;
26  
27    public RendererCacheKey(final ClientPropertiesKey cacheKey, final String name) {
28      this.cacheKey = cacheKey;
29      this.name = name;
30      hashCode = calcHashCode();
31    }
32  
33    @Override
34    public boolean equals(final Object o) {
35      if (this == o) {
36        return true;
37      }
38      if (o == null || getClass() != o.getClass()) {
39        return false;
40      }
41  
42      final RendererCacheKey that = (RendererCacheKey) o;
43  
44      return cacheKey.equals(that.cacheKey) && name.equals(that.name);
45    }
46  
47    private int calcHashCode() {
48      int result;
49      result = cacheKey.hashCode();
50      result = 31 * result + name.hashCode();
51      return result;
52    }
53  
54    @Override
55    public int hashCode() {
56      return hashCode;
57    }
58  
59    @Override
60    public String toString() {
61      return "RendererCacheKey(" + cacheKey + "," + name + "," + hashCode + ')';
62    }
63  }