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