54 |
private int[] data; |
private int[] data; |
55 |
private int[][] bankData; |
private int[][] bankData; |
56 |
|
|
57 |
|
/** |
58 |
|
* Creates a new data buffer with a single data bank containing the |
59 |
|
* specified number of <code>int</code> elements. |
60 |
|
* |
61 |
|
* @param size the number of elements in the data bank. |
62 |
|
*/ |
63 |
public DataBufferInt(int size) |
public DataBufferInt(int size) |
64 |
{ |
{ |
65 |
super(TYPE_INT, size); |
super(TYPE_INT, size); |
66 |
data = new int[size]; |
data = new int[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>int</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 DataBufferInt(int size, int numBanks) |
public DataBufferInt(int size, int numBanks) |
77 |
{ |
{ |
78 |
super(TYPE_INT, size, numBanks); |
super(TYPE_INT, 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 DataBufferInt(int[] dataArray, int size) |
public DataBufferInt(int[] dataArray, int size) |
94 |
{ |
{ |
95 |
super(TYPE_INT, size); |
super(TYPE_INT, 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 DataBufferInt(int[] dataArray, int size, int offset) |
public DataBufferInt(int[] dataArray, int size, int offset) |
112 |
{ |
{ |
113 |
super(TYPE_INT, size, 1, offset); |
super(TYPE_INT, 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 DataBufferInt(int[][] dataArray, int size) |
public DataBufferInt(int[][] dataArray, int size) |
127 |
{ |
{ |
128 |
super(TYPE_INT, size, dataArray.length); |
super(TYPE_INT, 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 DataBufferInt(int[][] dataArray, int size, int[] offsets) |
public DataBufferInt(int[][] dataArray, int size, int[] offsets) |
145 |
{ |
{ |
146 |
super(TYPE_INT, size, dataArray.length, offsets); |
super(TYPE_INT, 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 int[] getData() |
public int[] 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 int[] getData(int bank) |
public int[] 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 int[][] getBankData() |
public int[][] getBankData() |
178 |
{ |
{ |
179 |
return bankData; |
return bankData; |
180 |
} |
} |
181 |
|
|
182 |
|
/** |
183 |
|
* Returns an element from the first data bank. The <code>offset</code> is |
184 |
|
* added to the specified index before accessing the underlying data array. |
185 |
|
* |
186 |
|
* @param i the element index. |
187 |
|
* @return The element. |
188 |
|
*/ |
189 |
public int getElem(int i) |
public int getElem(int i) |
190 |
{ |
{ |
191 |
return data[i+offset]; |
return data[i+offset]; |
192 |
} |
} |
193 |
|
|
194 |
|
/** |
195 |
|
* Returns an element from a particular data bank. The <code>offset</code> |
196 |
|
* is added to the specified index before accessing the underlying data |
197 |
|
* array. |
198 |
|
* |
199 |
|
* @param bank the bank index. |
200 |
|
* @param i the element index. |
201 |
|
* @return The element. |
202 |
|
*/ |
203 |
public int getElem(int bank, int i) |
public int getElem(int bank, int i) |
204 |
{ |
{ |
205 |
// get unsigned int as int |
// get unsigned int as int |
206 |
return bankData[bank][i+offsets[bank]]; |
return bankData[bank][i+offsets[bank]]; |
207 |
} |
} |
208 |
|
|
209 |
|
/** |
210 |
|
* Sets an element in the first data bank. The offset (specified in the |
211 |
|
* constructor) is added to <code>i</code> before updating the underlying |
212 |
|
* data array. |
213 |
|
* |
214 |
|
* @param i the element index. |
215 |
|
* @param val the new element value. |
216 |
|
*/ |
217 |
public void setElem(int i, int val) |
public void setElem(int i, int val) |
218 |
{ |
{ |
219 |
data[i+offset] = (int) val; |
data[i+offset] = val; |
220 |
} |
} |
221 |
|
|
222 |
|
/** |
223 |
|
* Sets an element in a particular data bank. The offset (specified in the |
224 |
|
* constructor) is added to <code>i</code> before updating the underlying |
225 |
|
* data array. |
226 |
|
* |
227 |
|
* @param bank the data bank index. |
228 |
|
* @param i the element index. |
229 |
|
* @param val the new element value. |
230 |
|
*/ |
231 |
public void setElem(int bank, int i, int val) |
public void setElem(int bank, int i, int val) |
232 |
{ |
{ |
233 |
bankData[bank][i+offsets[bank]] = (int) val; |
bankData[bank][i+offsets[bank]] = val; |
234 |
} |
} |
235 |
} |
} |