Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 107   Methods: 11
NCLOC: 77   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
MapCopy.java 50% 82.4% 81.8% 80%
coverage coverage
 1    package org.jboss.cache.util;
 2   
 3    import java.io.IOException;
 4    import java.io.Serializable;
 5    import java.util.AbstractMap;
 6    import java.util.AbstractSet;
 7    import java.util.ArrayList;
 8    import java.util.HashMap;
 9    import java.util.Iterator;
 10    import java.util.List;
 11    import java.util.Map;
 12    import java.util.Set;
 13   
 14    /**
 15    * Contains a fixed array of read-only map entries, from a copy of an existing map.
 16    * This class is more lightweight for places where the copied map will just be iterated over.
 17    * <p/>
 18    * This map is strictly read-only, and map modification methods (as well as modifications over iterators) will throw
 19    * {@link UnsupportedOperationException}s.
 20    *
 21    * @author Elias Ross
 22    */
 23    public class MapCopy<K, V> extends AbstractMap<K, V> implements Serializable
 24    {
 25   
 26    private static final long serialVersionUID = -958813082188242956L;
 27   
 28    private List<Entry<K, V>> data = new ArrayList<Entry<K, V>>();
 29   
 30    private transient Set<Map.Entry<K, V>> entrySet;
 31   
 32    /**
 33    * Copies the supplied map to an internal array.
 34    *
 35    * @param m map to copy
 36    */
 37  1612647 public MapCopy(Map<K, V> m)
 38    {
 39  1612643 int i = 0;
 40  1612647 for (Map.Entry<K, V> me : m.entrySet())
 41    {
 42  204524994 if (me == null)
 43  0 throw new NullPointerException();
 44  204524994 data.add(new SimpleEntry<K, V>(me));
 45    }
 46  1612647 init();
 47    }
 48   
 49  0 public MapCopy()
 50    {
 51  0 this(new HashMap<K, V>());
 52    }
 53   
 54  1624477 private void init()
 55    {
 56  1624469 this.entrySet = new AbstractSet<Map.Entry<K, V>>()
 57    {
 58  0 public int size()
 59    {
 60  0 return data.size();
 61    }
 62   
 63  1207917 public Iterator<Map.Entry<K, V>> iterator()
 64    {
 65  1207917 return new EntryIterator();
 66    }
 67    };
 68    }
 69   
 70    private class EntryIterator implements Iterator<Entry<K, V>>
 71    {
 72    private int index;
 73   
 74  1484100 public boolean hasNext()
 75    {
 76  1484100 return index < data.size();
 77    }
 78   
 79  276774 public Entry<K, V> next()
 80    {
 81  276774 return data.get(index++);
 82    }
 83   
 84  6 public void remove()
 85    {
 86  6 throw new UnsupportedOperationException();
 87    }
 88    }
 89   
 90  1207917 @Override
 91    public Set<Map.Entry<K, V>> entrySet()
 92    {
 93  1207917 return entrySet;
 94    }
 95   
 96  1137535 @Override
 97    public int size()
 98    {
 99  1137535 return data.size();
 100    }
 101   
 102  11830 private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
 103    {
 104  11830 in.defaultReadObject();
 105  11830 init();
 106    }
 107    }