Coverage Report - org.simpleframework.xml.util.ConcurrentCache
 
Classes in this File Line Coverage Branch Coverage Complexity
ConcurrentCache
85%
6/7
N/A
1
 
 1  
 /*
 2  
  * ConcurrentCache.java July 2012
 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  
 import java.util.concurrent.ConcurrentHashMap;
 22  
 
 23  
 /**
 24  
  * The <code>ConcurrentCache</code> interface is used to represent a 
 25  
  * cache that will store key value pairs. This implementation is
 26  
  * backed by a <code>ConcurrentHashMap</code> for best performance.
 27  
  * 
 28  
  * @author Niall Gallagher
 29  
  */
 30  
 public class ConcurrentCache<T> extends ConcurrentHashMap<Object, T> implements Cache<T> {
 31  
    
 32  
    /**
 33  
     * Constructor for the <code>ConcurrentCache</code> object. This
 34  
     * is an implementation of a cache that uses the conventional
 35  
     * concurrent hash map from the Java collections API.
 36  
     */
 37  
    public ConcurrentCache() {
 38  15012
       super();
 39  15012
    }
 40  
    
 41  
    /**
 42  
     * This method is used to insert a key value mapping in to the
 43  
     * cache. The value can later be retrieved or removed from the
 44  
     * cache if desired. If the value associated with the key is 
 45  
     * null then nothing is stored within the cache.
 46  
     * 
 47  
     * @param key this is the key to cache the provided value to
 48  
     * @param value this is the value that is to be cached
 49  
     */
 50  
    public void cache(Object key, T value) {
 51  32616
       put(key, value);
 52  32616
    }
 53  
 
 54  
    /**
 55  
     * This is used to exclusively take the value mapped to the 
 56  
     * specified key from the cache. Invoking this is effectively
 57  
     * removing the value from the cache.
 58  
     * 
 59  
     * @param key this is the key to acquire the cache value with
 60  
     * 
 61  
     * @return this returns the value mapped to the specified key 
 62  
     */
 63  
    public T take(Object key) {
 64  0
       return remove(key);
 65  
    }
 66  
 
 67  
    /**
 68  
     * This method is used to get the value from the cache that is
 69  
     * mapped to the specified key. If there is no value mapped to
 70  
     * the specified key then this method will return a null.
 71  
     * 
 72  
     * @param key this is the key to acquire the cache value with
 73  
     * 
 74  
     * @return this returns the value mapped to the specified key 
 75  
     */
 76  
    public T fetch(Object key) {
 77  5507618
       return get(key);
 78  
    }
 79  
 
 80  
    /**
 81  
     * This is used to determine whether the specified key exists
 82  
     * with in the cache. Typically this can be done using the 
 83  
     * fetch method, which will acquire the object. 
 84  
     * 
 85  
     * @param key this is the key to check within this segment
 86  
     * 
 87  
     * @return true if the specified key is within the cache
 88  
     */
 89  
    public boolean contains(Object key) {
 90  3421577
       return containsKey(key);
 91  
    }
 92  
 }