1 22 23 package com.sosnoski.util.array; 24 25 import java.util.Iterator ; 26 27 import com.sosnoski.util.ArrayRangeIterator; 28 29 40 41 public class ObjectArray extends ArrayBase 42 { 43 44 protected Object [] m_baseArray; 45 46 53 54 public ObjectArray(int size, int growth) { 55 super(size, growth, Object .class); 56 } 57 58 63 64 public ObjectArray(int size) { 65 super(size, Object .class); 66 } 67 68 71 72 public ObjectArray() { 73 this(DEFAULT_SIZE); 74 } 75 76 81 82 public ObjectArray(ObjectArray base) { 83 super(base); 84 } 85 86 92 93 protected final Object getArray() { 94 return m_baseArray; 95 } 96 97 103 104 protected final void setArray(Object array) { 105 m_baseArray = (Object [])array; 106 } 107 108 114 115 public final int add(Object value) { 116 int index = getAddIndex(); 117 m_baseArray[index] = value; 118 return index; 119 } 120 121 127 128 public void add(int index, Object value) { 129 makeInsertSpace(index); 130 m_baseArray[index] = (Object )value; 131 } 132 133 139 140 public final Object get(int index) { 141 if (index < m_countPresent) { 142 return m_baseArray[index]; 143 } else { 144 throw new ArrayIndexOutOfBoundsException ("Invalid index value"); 145 } 146 } 147 148 157 158 public final void set(int index, Object value) { 159 if (index < m_countPresent) { 160 m_baseArray[index] = value; 161 } else { 162 throw new ArrayIndexOutOfBoundsException ("Invalid index value"); 163 } 164 } 165 166 175 176 public final Iterator iterator() { 177 return ArrayRangeIterator.buildIterator(m_baseArray, 0, m_countPresent); 178 } 179 180 186 187 public Object [] toArray() { 188 return (Object []) buildArray(Object .class, 0, m_countPresent); 189 } 190 191 199 200 public Object [] toArray(Class type) { 201 return (Object []) buildArray(type, 0, m_countPresent); 202 } 203 204 212 213 public Object [] toArray(int offset, int length) { 214 return (Object [])buildArray(Object .class, offset, length); 215 } 216 217 228 229 public Object [] toArray(Class type, int offset, int length) { 230 return (Object [])buildArray(type, offset, length); 231 } 232 233 238 239 public Object clone() { 240 return new ObjectArray(this); 241 } 242 } 243 | Popular Tags |