Clover coverage report - Code Coverage for tapestry release 4.0-beta-9
Coverage timestamp: Sat Oct 1 2005 08:36:20 EDT
file stats: LOC: 71   Methods: 3
NCLOC: 32   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ObjectPoolImpl.java 100% 90% 66.7% 88.2%
coverage coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.services.impl;
 16   
 17    import java.util.HashMap;
 18    import java.util.LinkedList;
 19    import java.util.List;
 20    import java.util.Map;
 21   
 22    import org.apache.tapestry.event.ResetEventListener;
 23    import org.apache.tapestry.services.ObjectPool;
 24   
 25    /**
 26    * Implementation of the {@link org.apache.tapestry.services.ObjectPool} interface.
 27    *
 28    * <p>
 29    * This ia a minimal implementation, one that has no concept of automatically removing
 30    * unused pooled objects. Eventually, it will also register for notifications about
 31    * general cache cleaning.
 32    *
 33    * @author Howard Lewis Ship
 34    * @since 4.0
 35    */
 36    public class ObjectPoolImpl implements ObjectPool, ResetEventListener
 37    {
 38    /**
 39    * Pool of Lists (of pooled objects), keyed on arbitrary key.
 40    */
 41    private Map _pool = new HashMap();
 42   
 43  338 public synchronized Object get(Object key)
 44    {
 45  338 List pooled = (List) _pool.get(key);
 46   
 47  338 if (pooled == null || pooled.isEmpty())
 48  184 return null;
 49   
 50  154 return pooled.remove(0);
 51    }
 52   
 53  325 public synchronized void store(Object key, Object value)
 54    {
 55  325 List pooled = (List) _pool.get(key);
 56   
 57  325 if (pooled == null)
 58    {
 59  166 pooled = new LinkedList();
 60  166 _pool.put(key, pooled);
 61    }
 62   
 63  325 pooled.add(value);
 64    }
 65   
 66  0 public synchronized void resetEventDidOccur()
 67    {
 68  0 _pool.clear();
 69    }
 70   
 71    }