1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.cache.internal

File MapCache.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

0
5
5
1
71
33
5
1
1
5
1

Classes

Class Line # Actions
MapCache 36 5 0% 5 2
0.880%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.cache.internal;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.xwiki.cache.Cache;
26    import org.xwiki.cache.util.AbstractCache;
27   
28    /**
29    * Implementation of {@link Cache} based on a simple Map.
30    * <p>
31    * Does not support eviction.
32    *
33    * @param <T> the class of the data stored in the cache.
34    * @version $Id: 82431da13a6eeaa7520f5fbf7a25d63e7de58a23 $
35    */
 
36    public class MapCache<T> extends AbstractCache<T>
37    {
38    private Map<String, T> map = new HashMap<>();
39   
40    /**
41    * Default constructor.
42    */
 
43  7 toggle public MapCache()
44    {
45  7 super(null);
46    }
47   
 
48  9 toggle @Override
49    public void set(String key, T value)
50    {
51  9 this.map.put(key, value);
52    }
53   
 
54  20 toggle @Override
55    public T get(String key)
56    {
57  20 return this.map.get(key);
58    }
59   
 
60  1 toggle @Override
61    public void remove(String key)
62    {
63  1 this.map.remove(key);
64    }
65   
 
66  0 toggle @Override
67    public void removeAll()
68    {
69  0 this.map.clear();
70    }
71    }