Coverage Report - org.simpleframework.xml.util.Cache
 
Classes in this File Line Coverage Branch Coverage Complexity
Cache
N/A
N/A
1
 
 1  
 /*
 2  
  * Cache.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * 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, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.util;
 20  
 
 21  
 /**
 22  
  * The <code>Cache</code> interface is used to represent a cache
 23  
  * that will store key value pairs. The cache exposes only several
 24  
  * methods to ensure that implementations can focus on performance
 25  
  * concerns rather than how to manage the cached values.
 26  
  * 
 27  
  * @author Niall Gallagher
 28  
  */
 29  
 public interface Cache<T> {
 30  
    
 31  
    /**
 32  
     * This method is used to determine if the cache is empty. This
 33  
     * is done by checking if there are any elements in the cache.
 34  
     * If anything has been cached this will return false.
 35  
     * 
 36  
     * @return this returns true if the cache is empty
 37  
     */
 38  
    boolean isEmpty();
 39  
    
 40  
    /**
 41  
     * This method is used to insert a key value mapping in to the
 42  
     * cache. The value can later be retrieved or removed from the
 43  
     * cache if desired. If the value associated with the key is 
 44  
     * null then nothing is stored within the cache.
 45  
     * 
 46  
     * @param key this is the key to cache the provided value to
 47  
     * @param value this is the value that is to be cached
 48  
     */
 49  
    void cache(Object key, T value);
 50  
  
 51  
    /**
 52  
     * This is used to exclusively take the value mapped to the 
 53  
     * specified key from the cache. Invoking this is effectively
 54  
     * removing the value from the cache.
 55  
     * 
 56  
     * @param key this is the key to acquire the cache value with
 57  
     * 
 58  
     * @return this returns the value mapped to the specified key 
 59  
     */
 60  
    T take(Object key);
 61  
    
 62  
    /**
 63  
     * This method is used to get the value from the cache that is
 64  
     * mapped to the specified key. If there is no value mapped to
 65  
     * the specified key then this method will return a null.
 66  
     * 
 67  
     * @param key this is the key to acquire the cache value with
 68  
     * 
 69  
     * @return this returns the value mapped to the specified key 
 70  
     */
 71  
    T fetch(Object key);   
 72  
    
 73  
    /**
 74  
     * This is used to determine whether the specified key exists
 75  
     * with in the cache. Typically this can be done using the 
 76  
     * fetch method, which will acquire the object. 
 77  
     * 
 78  
     * @param key this is the key to check within this segment
 79  
     * 
 80  
     * @return true if the specified key is within the cache
 81  
     */
 82  
    boolean contains(Object key);
 83  
 }