54 |
private byte[] data; |
private byte[] data; |
55 |
private byte[][] bankData; |
private byte[][] bankData; |
56 |
|
|
57 |
|
/** |
58 |
|
* Creates a new data buffer with a single data bank containing the |
59 |
|
* specified number of <code>byte</code> elements. |
60 |
|
* |
61 |
|
* @param size the number of elements in the data bank. |
62 |
|
*/ |
63 |
public DataBufferByte(int size) |
public DataBufferByte(int size) |
64 |
{ |
{ |
65 |
super(TYPE_BYTE, size); |
super(TYPE_BYTE, size); |
66 |
data = new byte[size]; |
data = new byte[size]; |
67 |
} |
} |
68 |
|
|
69 |
|
/** |
70 |
|
* Creates a new data buffer with the specified number of data banks, |
71 |
|
* each containing the specified number of <code>byte</code> elements. |
72 |
|
* |
73 |
|
* @param size the number of elements in the data bank. |
74 |
|
* @param numBanks the number of data banks. |
75 |
|
*/ |
76 |
public DataBufferByte(int size, int numBanks) |
public DataBufferByte(int size, int numBanks) |
77 |
{ |
{ |
78 |
super(TYPE_BYTE, size, numBanks); |
super(TYPE_BYTE, size, numBanks); |
80 |
data = bankData[0]; |
data = bankData[0]; |
81 |
} |
} |
82 |
|
|
83 |
|
/** |
84 |
|
* Creates a new data buffer backed by the specified data bank. |
85 |
|
* <p> |
86 |
|
* Note: there is no exception when <code>dataArray</code> is |
87 |
|
* <code>null</code>, but in that case an exception will be thrown |
88 |
|
* later if you attempt to access the data buffer. |
89 |
|
* |
90 |
|
* @param dataArray the data bank. |
91 |
|
* @param size the number of elements in the data bank. |
92 |
|
*/ |
93 |
public DataBufferByte(byte[] dataArray, int size) |
public DataBufferByte(byte[] dataArray, int size) |
94 |
{ |
{ |
95 |
super(TYPE_BYTE, size); |
super(TYPE_BYTE, size); |
96 |
data = dataArray; |
data = dataArray; |
97 |
} |
} |
98 |
|
|
99 |
|
/** |
100 |
|
* Creates a new data buffer backed by the specified data bank, with |
101 |
|
* the specified offset to the first element. |
102 |
|
* <p> |
103 |
|
* Note: there is no exception when <code>dataArray</code> is |
104 |
|
* <code>null</code>, but in that case an exception will be thrown |
105 |
|
* later if you attempt to access the data buffer. |
106 |
|
* |
107 |
|
* @param dataArray the data bank. |
108 |
|
* @param size the number of elements in the data bank. |
109 |
|
* @param offset the offset to the first element in the array. |
110 |
|
*/ |
111 |
public DataBufferByte(byte[] dataArray, int size, int offset) |
public DataBufferByte(byte[] dataArray, int size, int offset) |
112 |
{ |
{ |
113 |
super(TYPE_BYTE, size, 1, offset); |
super(TYPE_BYTE, size, 1, offset); |
114 |
data = dataArray; |
data = dataArray; |
115 |
} |
} |
116 |
|
|
117 |
|
/** |
118 |
|
* Creates a new data buffer backed by the specified data banks. |
119 |
|
* |
120 |
|
* @param dataArray the data banks. |
121 |
|
* @param size the number of elements in the data bank. |
122 |
|
* |
123 |
|
* @throws NullPointerException if <code>dataArray</code> is |
124 |
|
* <code>null</code>. |
125 |
|
*/ |
126 |
public DataBufferByte(byte[][] dataArray, int size) |
public DataBufferByte(byte[][] dataArray, int size) |
127 |
{ |
{ |
128 |
super(TYPE_BYTE, size, dataArray.length); |
super(TYPE_BYTE, size, dataArray.length); |
130 |
data = bankData[0]; |
data = bankData[0]; |
131 |
} |
} |
132 |
|
|
133 |
|
/** |
134 |
|
* Creates a new data buffer backed by the specified data banks, with |
135 |
|
* the specified offsets to the first element in each bank. |
136 |
|
* |
137 |
|
* @param dataArray the data banks. |
138 |
|
* @param size the number of elements in the data bank. |
139 |
|
* @param offsets the offsets to the first element in each data bank. |
140 |
|
* |
141 |
|
* @throws NullPointerException if <code>dataArray</code> is |
142 |
|
* <code>null</code>. |
143 |
|
*/ |
144 |
public DataBufferByte(byte[][] dataArray, int size, int[] offsets) |
public DataBufferByte(byte[][] dataArray, int size, int[] offsets) |
145 |
{ |
{ |
146 |
super(TYPE_BYTE, size, dataArray.length, offsets); |
super(TYPE_BYTE, size, dataArray.length, offsets); |
148 |
data = bankData[0]; |
data = bankData[0]; |
149 |
} |
} |
150 |
|
|
151 |
|
/** |
152 |
|
* Returns the first data bank. |
153 |
|
* |
154 |
|
* @return The first data bank. |
155 |
|
*/ |
156 |
public byte[] getData() |
public byte[] getData() |
157 |
{ |
{ |
158 |
return data; |
return data; |
159 |
} |
} |
160 |
|
|
161 |
|
/** |
162 |
|
* Returns a data bank. |
163 |
|
* |
164 |
|
* @param bank the bank index. |
165 |
|
* @return A data bank. |
166 |
|
*/ |
167 |
public byte[] getData(int bank) |
public byte[] getData(int bank) |
168 |
{ |
{ |
169 |
return bankData[bank]; |
return bankData[bank]; |
170 |
} |
} |
171 |
|
|
172 |
|
/** |
173 |
|
* Returns the array underlying this <code>DataBuffer</code>. |
174 |
|
* |
175 |
|
* @return The data banks. |
176 |
|
*/ |
177 |
public byte[][] getBankData() |
public byte[][] getBankData() |
178 |
{ |
{ |
179 |
return bankData; |
return bankData; |
180 |
} |
} |
181 |
|
|
182 |
|
/** |
183 |
|
* Returns an element from the first data bank. The offset (specified in |
184 |
|
* the constructor) is added to <code>i</code> before accessing the |
185 |
|
* underlying data array. |
186 |
|
* |
187 |
|
* @param i the element index. |
188 |
|
* @return The element. |
189 |
|
*/ |
190 |
public int getElem(int i) |
public int getElem(int i) |
191 |
{ |
{ |
192 |
return data[i+offset] & 0xff; // get unsigned byte as int |
return data[i+offset] & 0xff; // get unsigned byte as int |
193 |
} |
} |
194 |
|
|
195 |
|
/** |
196 |
|
* Returns an element from a particular data bank. The offset (specified in |
197 |
|
* the constructor) is added to <code>i</code> before accessing the |
198 |
|
* underlying data array. |
199 |
|
* |
200 |
|
* @param bank the bank index. |
201 |
|
* @param i the element index. |
202 |
|
* @return The element. |
203 |
|
*/ |
204 |
public int getElem(int bank, int i) |
public int getElem(int bank, int i) |
205 |
{ |
{ |
206 |
// get unsigned byte as int |
// get unsigned byte as int |
207 |
return bankData[bank][i+offsets[bank]] & 0xff; |
return bankData[bank][i+offsets[bank]] & 0xff; |
208 |
} |
} |
209 |
|
|
210 |
|
/** |
211 |
|
* Sets an element in the first data bank. The offset (specified in the |
212 |
|
* constructor) is added to <code>i</code> before updating the underlying |
213 |
|
* data array. |
214 |
|
* |
215 |
|
* @param i the element index. |
216 |
|
* @param val the new element value. |
217 |
|
*/ |
218 |
public void setElem(int i, int val) |
public void setElem(int i, int val) |
219 |
{ |
{ |
220 |
data[i+offset] = (byte) val; |
data[i+offset] = (byte) val; |
221 |
} |
} |
222 |
|
|
223 |
|
/** |
224 |
|
* Sets an element in a particular data bank. The offset (specified in the |
225 |
|
* constructor) is added to <code>i</code> before updating the underlying |
226 |
|
* data array. |
227 |
|
* |
228 |
|
* @param bank the data bank index. |
229 |
|
* @param i the element index. |
230 |
|
* @param val the new element value. |
231 |
|
*/ |
232 |
public void setElem(int bank, int i, int val) |
public void setElem(int bank, int i, int val) |
233 |
{ |
{ |
234 |
bankData[bank][i+offsets[bank]] = (byte) val; |
bankData[bank][i+offsets[bank]] = (byte) val; |