1 22 23 package com.sosnoski.util.array; 24 25 36 37 public class ByteArray extends ArrayBase 38 { 39 40 protected byte[] m_baseArray; 41 42 48 49 public ByteArray(int size, int growth) { 50 super(size, growth, byte.class); 51 } 52 53 58 59 public ByteArray(int size) { 60 super(size, byte.class); 61 } 62 63 66 67 public ByteArray() { 68 this(DEFAULT_SIZE); 69 } 70 71 76 77 public ByteArray(ByteArray 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 = (byte[])array; 101 } 102 103 109 110 public final int add(int value) { 111 int index = getAddIndex(); 112 m_baseArray[index] = (byte)value; 113 return index; 114 } 115 116 122 123 public void add(int index, int value) { 124 makeInsertSpace(index); 125 m_baseArray[index] = (byte)value; 126 } 127 128 134 135 public final byte 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] = (byte)value; 153 } else { 154 throw new ArrayIndexOutOfBoundsException ("Invalid index value"); 155 } 156 } 157 158 164 165 public byte[] toArray() { 166 return (byte[])buildArray(byte.class, 0, m_countPresent); 167 } 168 169 177 178 public byte[] toArray(int offset, int length) { 179 return (byte[])buildArray(byte.class, offset, length); 180 } 181 182 187 188 public Object clone() { 189 return new ByteArray(this); 190 } 191 } 192 | Popular Tags |