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