Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 108   Methods: 12
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FIFOQueue.java 75% 90% 91.7% 88.9%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.eviction;
 8   
 9    import org.jboss.cache.Fqn;
 10   
 11    import java.util.Iterator;
 12    import java.util.LinkedHashMap;
 13    import java.util.Map;
 14   
 15    /**
 16    * FIFO Eviction Queue implementation for FIFO Policy.
 17    *
 18    * @author Daniel Huang (dhuang@jboss.org)
 19    * @version $Revision: 1.5 $
 20    */
 21    public class FIFOQueue implements EvictionQueue
 22    {
 23    private Map<Fqn, NodeEntry> nodeMap;
 24    private int numElements = 0;
 25   
 26  27 FIFOQueue()
 27    {
 28  27 nodeMap = new LinkedHashMap<Fqn, NodeEntry>();
 29    // We use a LinkedHashMap here because we want to maintain FIFO ordering and still get the benefits of
 30    // O(n) = 1 for add/remove/search.
 31    }
 32   
 33  315650 public NodeEntry getFirstNodeEntry()
 34    {
 35    /* Iterator it = nodeMap.keySet().iterator();
 36    if(it.hasNext()) {
 37    return (NodeEntry) nodeMap.get(it.next());
 38    }
 39   
 40    return null; */
 41   
 42    // this code path is *slightly* faster when profiling. 20ms faster iterating over 200000 entries in queue.
 43  315650 if (nodeMap.size() > 0)
 44    {
 45  315607 return nodeMap.values().iterator().next();
 46    }
 47   
 48  43 return null;
 49    }
 50   
 51  681908 public NodeEntry getNodeEntry(Fqn fqn)
 52    {
 53  681908 return nodeMap.get(fqn);
 54    }
 55   
 56  14 public NodeEntry getNodeEntry(String fqn)
 57    {
 58  14 return this.getNodeEntry(Fqn.fromString(fqn));
 59    }
 60   
 61  580636 public boolean containsNodeEntry(NodeEntry entry)
 62    {
 63  580636 Fqn fqn = entry.getFqn();
 64  580636 return this.getNodeEntry(fqn) != null;
 65    }
 66   
 67  515602 public void removeNodeEntry(NodeEntry entry)
 68    {
 69  515602 NodeEntry e = nodeMap.remove(entry.getFqn());
 70  515602 this.numElements -= e.getNumberOfElements();
 71    }
 72   
 73  580634 public void addNodeEntry(NodeEntry entry)
 74    {
 75  580634 if (!this.containsNodeEntry(entry))
 76    {
 77  580634 entry.queue = this;
 78  580634 nodeMap.put(entry.getFqn(), entry);
 79  580634 this.numElements += entry.getNumberOfElements();
 80    }
 81    }
 82   
 83  15641 public int getNumberOfNodes()
 84    {
 85  15641 return nodeMap.size();
 86    }
 87   
 88  6 public int getNumberOfElements()
 89    {
 90  6 return this.numElements;
 91    }
 92   
 93  1 public void modifyElementCount(int difference)
 94    {
 95  1 this.numElements += difference;
 96    }
 97   
 98  0 public void clear()
 99    {
 100  0 nodeMap.clear();
 101  0 this.numElements = 0;
 102    }
 103   
 104  4 public Iterator<NodeEntry> iterate()
 105    {
 106  4 return nodeMap.values().iterator();
 107    }
 108    }