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