Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 188   Methods: 15
NCLOC: 155   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CachedListAbstract.java 78.6% 86.8% 93.3% 85%
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.pojo.collection;
 8   
 9    import org.jboss.cache.pojo.annotation.Reentrant;
 10   
 11    import java.util.Collection;
 12    import java.util.Iterator;
 13    import java.util.List;
 14   
 15    /**
 16    * Abstract class for CachedList.
 17    *
 18    * @author Scott Marlow
 19    */
 20   
 21    @Reentrant
 22    abstract class CachedListAbstract implements List
 23    {
 24  5 public void clear()
 25    {
 26    // TODO Can use optimization here
 27  5 for (int i = size() - 1; i >= 0; i--)
 28    {
 29  13 remove(i);
 30    }
 31    }
 32   
 33  6 public boolean isEmpty()
 34    {
 35  6 return size() == 0;
 36    }
 37   
 38  14 public Object[] toArray()
 39    {
 40  14 Object[] objs = new Object[size()];
 41  14 for (int i = 0; i < size(); i++)
 42    {
 43  48 objs[i] = get(i);
 44    }
 45  14 return objs;
 46    }
 47   
 48  2 public Object[] toArray(Object a[])
 49    {
 50  2 int actualLength = size();
 51  2 if (actualLength > a.length) // need to allocate a larger array
 52  1 a = new Object[actualLength];
 53  2 int looper;
 54  2 for (looper = 0; looper < actualLength; looper++)
 55    {
 56  10 a[looper] = get(looper);
 57    }
 58  2 for (; looper < a.length; looper++)
 59  5 a[looper] = null; // if the array is larger than needed, set extra slots to null
 60  2 return a;
 61    }
 62   
 63  3246 public boolean add(Object o)
 64    {
 65  3246 add(size(), o);
 66  3246 return true;
 67    }
 68   
 69  40 public boolean contains(Object o)
 70    {
 71  16 if (indexOf(o) != -1) return true;
 72  24 return false;
 73    }
 74   
 75  19 public boolean remove(Object o)
 76    {
 77  19 int i = indexOf(o);
 78  19 if (i == -1)
 79  0 return false;
 80   
 81  19 remove(i);
 82  19 return true;
 83    }
 84   
 85  0 public boolean addAll(int index, Collection c)
 86    {
 87  0 if (c.size() == 0)
 88  0 return false;
 89    // should optimize this
 90  0 for (Object o : c)
 91    {
 92  0 add(index++, o);
 93    }
 94  0 return true;
 95    }
 96   
 97  8 public boolean addAll(Collection c)
 98    {
 99  8 if (c.size() == 0)
 100  0 return false;
 101  8 for (Object o : c)
 102    {
 103  34 add(o);
 104    }
 105  8 return true;
 106    }
 107   
 108  2 public boolean containsAll(Collection c)
 109    {
 110  2 for (Object aC : c)
 111    {
 112  5 if (!contains(aC))
 113    {
 114  1 return false;
 115    }
 116    }
 117  1 return true;
 118    }
 119   
 120  3 public boolean removeAll(Collection c)
 121    {
 122  3 for (Object o : c)
 123    {
 124  8 remove(o);
 125    }
 126  3 return true;
 127    }
 128   
 129  2 public int hashCode()
 130    {
 131  2 int result = 1;
 132  2 for (int i = 0; i < size(); i++)
 133    {
 134  4 Object o = get(i);
 135  4 result = 31 * result + (o == null ? 0 : o.hashCode());
 136    }
 137  2 return result;
 138    }
 139   
 140  59 public boolean equals(Object object)
 141    {
 142  59 if (object == this)
 143  0 return true;
 144  59 if (object == null || !(object instanceof List))
 145  0 return false;
 146  59 List list = (List) object;
 147  59 if (size() != list.size())
 148  0 return false;
 149  59 for (int i = 0; i < list.size(); i++)
 150    {
 151  114 Object value1 = get(i);
 152  114 Object value2 = list.get(i);
 153  114 if ((value1 == null && value2 != null) ||
 154    (value1 != null && !(value1.equals(value2))))
 155  6 return false;
 156    }
 157  53 return true;
 158    }
 159   
 160  2 public String toString()
 161    {
 162  2 StringBuffer buf = new StringBuffer();
 163  2 int size = size();
 164  2 for (int i = 0; i < size; i++)
 165    {
 166  5 Object key = get(i);
 167  5 buf.append("[").append(key).append("]");
 168  5 if (i <= size) buf.append(", ");
 169    }
 170   
 171  2 return buf.toString();
 172    }
 173   
 174  1 public boolean retainAll(Collection c)
 175    {
 176  1 boolean changedAnything = false;
 177  1 Iterator iter = iterator();
 178  1 while (iter.hasNext())
 179    {
 180  5 if (!c.contains(iter.next()))
 181    {
 182  4 iter.remove();
 183  4 changedAnything = true;
 184    }
 185    }
 186  1 return changedAnything;
 187    }
 188    }