1 22 23 package com.sosnoski.util.array; 24 25 36 37 public class CharArray extends ArrayBase 38 { 39 40 protected char[] m_baseArray; 41 42 48 49 public CharArray(int size, int growth) { 50 super(size, growth, char.class); 51 } 52 53 58 59 public CharArray(int size) { 60 super(size, char.class); 61 } 62 63 66 67 public CharArray() { 68 this(DEFAULT_SIZE); 69 } 70 71 76 77 public CharArray(CharArray base) { 78 super(base); 79 } 80 81 87 88 protected final Object getArray() { 89 return m_baseArray; 90 } 91 92 98 99 protected final void setArray(Object array) { 100 m_baseArray = (char[])array; 101 } 102 103 109 110 public final int add(int value) { 111 int index = getAddIndex(); 112 m_baseArray[index] = (char)value; 113 return index; 114 } 115 116 122 123 public void add(int index, int value) { 124 makeInsertSpace(index); 125 m_baseArray[index] = (char)value; 126 } 127 128 134 135 public final char get(int index) { 136 if (index < m_countPresent) { 137 return m_baseArray[index]; 138 } else { 139 throw new ArrayIndexOutOfBoundsException ("Invalid index value"); 140 } 141 } 142 143 149 150 public final void set(int index, int value) { 151 if (index < m_countPresent) { 152 m_baseArray[index] = (char)value; 153 } else { 154 throw new ArrayIndexOutOfBoundsException ("Invalid index value"); 155 } 156 } 157 158 164 165 public char[] toArray() { 166 return (char[])buildArray(char.class, 0, m_countPresent); 167 } 168 169 177 178 public char[] toArray(int offset, int length) { 179 return (char[])buildArray(char.class, offset, length); 180 } 181 182 187 188 public Object clone() { 189 return new CharArray(this); 190 } 191 } 192 | Popular Tags |