| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>MapCache.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Apache Shiro :: Test Coverage</a> > <a href="../index.html" class="el_bundle">shiro-cache</a> > <a href="index.source.html" class="el_package">org.apache.shiro.cache</a> > <span class="el_source">MapCache.java</span></div><h1>MapCache.java</h1><pre class="source lang-java linenums">/* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.shiro.cache; |
| |
| import java.util.Collection; |
| import java.util.Collections; |
| import java.util.Map; |
| import java.util.Set; |
| |
| /** |
| * A <code>MapCache</code> is a {@link Cache Cache} implementation that uses a backing {@link Map} instance to store |
| * and retrieve cached data. |
| * |
| * @since 1.0 |
| */ |
| public class MapCache<K, V> implements Cache<K, V> { |
| |
| /** |
| * Backing instance. |
| */ |
| private final Map<K, V> map; |
| |
| /** |
| * The name of this cache. |
| */ |
| private final String name; |
| |
| <span class="fc" id="L44"> public MapCache(String name, Map<K, V> backingMap) {</span> |
| <span class="pc bpc" id="L45" title="1 of 2 branches missed."> if (name == null) {</span> |
| <span class="nc" id="L46"> throw new IllegalArgumentException("Cache name cannot be null.");</span> |
| } |
| <span class="pc bpc" id="L48" title="1 of 2 branches missed."> if (backingMap == null) {</span> |
| <span class="nc" id="L49"> throw new IllegalArgumentException("Backing map cannot be null.");</span> |
| } |
| <span class="fc" id="L51"> this.name = name;</span> |
| <span class="fc" id="L52"> this.map = backingMap;</span> |
| <span class="fc" id="L53"> }</span> |
| |
| public V get(K key) throws CacheException { |
| <span class="fc" id="L56"> return map.get(key);</span> |
| } |
| |
| public V put(K key, V value) throws CacheException { |
| <span class="fc" id="L60"> return map.put(key, value);</span> |
| } |
| |
| public V remove(K key) throws CacheException { |
| <span class="fc" id="L64"> return map.remove(key);</span> |
| } |
| |
| public void clear() throws CacheException { |
| <span class="nc" id="L68"> map.clear();</span> |
| <span class="nc" id="L69"> }</span> |
| |
| public int size() { |
| <span class="nc" id="L72"> return map.size();</span> |
| } |
| |
| public Set<K> keys() { |
| <span class="nc" id="L76"> Set<K> keys = map.keySet();</span> |
| <span class="nc bnc" id="L77" title="All 2 branches missed."> if (!keys.isEmpty()) {</span> |
| <span class="nc" id="L78"> return Collections.unmodifiableSet(keys);</span> |
| } |
| <span class="nc" id="L80"> return Collections.emptySet();</span> |
| } |
| |
| public Collection<V> values() { |
| <span class="nc" id="L84"> Collection<V> values = map.values();</span> |
| <span class="nc bnc" id="L85" title="All 2 branches missed."> if (!map.isEmpty()) {</span> |
| <span class="nc" id="L86"> return Collections.unmodifiableCollection(values);</span> |
| } |
| <span class="nc" id="L88"> return Collections.emptySet();</span> |
| } |
| |
| public String toString() { |
| <span class="nc" id="L92"> return new StringBuilder("MapCache '")</span> |
| <span class="nc" id="L93"> .append(name).append("' (")</span> |
| <span class="nc" id="L94"> .append(map.size())</span> |
| <span class="nc" id="L95"> .append(" entries)")</span> |
| <span class="nc" id="L96"> .toString();</span> |
| } |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html> |