View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
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" BASIS,
12   *  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  
17  package net.sf.ehcache;
18  
19  /***
20   * Helper class to tie a key to an element.
21   * <p/>
22   * This is used for operations that are identified by a key but that could benefit from additional information that's
23   * available in an element when it can be found in the cache. If the element isn't available, it will be {@code null}.
24   *
25   * @author Geert Bevin
26   * @version $Id: CacheEntry.html 13146 2011-08-01 17:12:39Z oletizi $
27   */
28  public class CacheEntry {
29      private final Object key;
30      private final Element element;
31  
32      /***
33       * Creates a new cache entry.
34       *
35       * @param key the key of the entry
36       * @param element the element of the entry or {@code null} if no element corresponds to the key at this time
37       */
38      public CacheEntry(Object key, Element element) {
39          this.key = key;
40          this.element = element;
41      }
42  
43      /***
44       * Retrieves the key of this cache entry.
45       *
46       * @return the request key
47       */
48      public Object getKey() {
49          return key;
50      }
51  
52      /***
53       * Retrieves the element of this cache entry.
54       *
55       * @return the element that corresponds to this key or {@code null} if the cache entry didn't have an element that
56       * belong to the key at the time of creation.
57       */
58      public Element getElement() {
59          return element;
60      }
61  }