Coverage Report - org.webslinger.collections.ArrayWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
ArrayWrapper
0%
0/9
0%
0/1
1.5
 
 1  
 package org.webslinger.collections;
 2  
 
 3  
 import java.lang.reflect.Array;
 4  
 import java.util.AbstractList;
 5  
 
 6  
 /**
 7  
  * Utility class used to make an array look like a list.  This class is
 8  
  * part of the wrapper collection.
 9  
  * @deprecated Use {@link java.util.Arrays#asList(Object[])}
 10  
  * @author Adam Heath <a href="mailto:doogie@brainfood.com">doogie@brainfood.com</a>
 11  
  */
 12  
 public class ArrayWrapper extends AbstractList {
 13  
     /** the wrapped array */
 14  
     protected Object array;
 15  
 
 16  
     /**
 17  
      * Wraps an array to make it look like a list.
 18  
      * @param array The array to wrap.
 19  
      * @throws ClassCastException if array is not actually an array. 
 20  
      */
 21  0
     public ArrayWrapper(Object array) {
 22  0
         if (!array.getClass().isArray()) throw new ClassCastException(array + " is not an array!");
 23  0
         this.array = array;
 24  0
     }
 25  
 
 26  
     /**
 27  
      * Returns the element at the specified position in the {@link
 28  
      * #array}.
 29  
      * @param i index of element to return.
 30  
      * @throws IndexOutOfBoundsException if the index if out of range (i
 31  
      * &lt; 0 || i &gt; {@link #array}.length).  
 32  
      * @return the element at the specified position in the {@link
 33  
      * #array}.
 34  
      */
 35  
     public Object get(int i) {
 36  0
         return Array.get(array, i);
 37  
     }
 38  
 
 39  
     /**
 40  
      * Replaces the element at the specified position in this list with
 41  
      * the specified element
 42  
      * @param i index of element to replace.
 43  
      * @param o object to be stored at the specified position.
 44  
      * @throws ClassCastException if the class of the specified element
 45  
      * prevents it from being added to the {@link #array}. 
 46  
      * @throws NullPointerException if the specified element is null and
 47  
      * the {@link #array} does not support null elements. 
 48  
      * @throws IllegalArgumentException if some aspect of the specified
 49  
      * element prevents it from being added to the {@link #array}.
 50  
      * @throws IndexOutOfBoundsException if the index if out of range (i
 51  
      * &lt; 0 || i &gt; {@link #array}.length).  
 52  
      * @return the element previously at the specified position.
 53  
      */
 54  
     public Object set(int i, Object o) {
 55  0
         Object old = Array.get(array, i);
 56  0
         Array.set(array, i, o);
 57  0
         return old;
 58  
     }
 59  
 
 60  
     /**
 61  
      * Returns the number of elements in the {@link #array}.
 62  
      * @return the number of elements in the {@link #array}.
 63  
      */
 64  
     public int size() {
 65  0
         return Array.getLength(array);
 66  
     }
 67  
 }