1 |
/* FloatBuffer.java -- |
/* FloatBuffer.java -- |
2 |
Copyright (C) 2002 Free Software Foundation, Inc. |
Copyright (C) 2002, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
39 |
|
|
40 |
import gnu.java.nio.FloatBufferImpl; |
import gnu.java.nio.FloatBufferImpl; |
41 |
|
|
42 |
public abstract class FloatBuffer extends Buffer implements Comparable |
/** |
43 |
|
* @since 1.4 |
44 |
|
*/ |
45 |
|
public abstract class FloatBuffer extends Buffer |
46 |
|
implements Comparable |
47 |
{ |
{ |
48 |
protected float [] backing_buffer; |
protected float [] backing_buffer; |
49 |
protected int array_offset; |
protected int array_offset; |
76 |
return wrap(buffer, 0, len); |
return wrap(buffer, 0, len); |
77 |
} |
} |
78 |
|
|
79 |
final public static FloatBuffer wrap(float[] array) |
/** |
80 |
|
* Wraps a <code>float</code> array into a <code>FloatBuffer</code> |
81 |
|
* object. |
82 |
|
*/ |
83 |
|
final public static FloatBuffer wrap (float[] array) |
84 |
{ |
{ |
85 |
return wrap(array, 0, array.length); |
return wrap (array, 0, array.length); |
86 |
} |
} |
87 |
|
|
88 |
protected FloatBuffer (int capacity, int limit, int position, int mark) |
protected FloatBuffer (int capacity, int limit, int position, int mark) |
91 |
array_offset = 0; |
array_offset = 0; |
92 |
} |
} |
93 |
|
|
94 |
|
/** |
95 |
|
* This method transfers <code>floats<code> from this buffer into the given |
96 |
|
* destination array. |
97 |
|
* |
98 |
|
* @param dst The destination array |
99 |
|
* @param offset The offset within the array of the first <code>float</code> |
100 |
|
* to be written; must be non-negative and no larger than dst.length. |
101 |
|
* @param length The maximum number of bytes to be written to the given array; |
102 |
|
* must be non-negative and no larger than dst.length - offset. |
103 |
|
* |
104 |
|
* @exception BufferUnderflowException If there are fewer than length |
105 |
|
* <code>floats</code> remaining in this buffer. |
106 |
|
* @exception IndexOutOfBoundsException If the preconditions on the offset |
107 |
|
* and length parameters do not hold. |
108 |
|
*/ |
109 |
public FloatBuffer get (float[] dst, int offset, int length) |
public FloatBuffer get (float[] dst, int offset, int length) |
110 |
{ |
{ |
111 |
for (int i = offset; i < offset + length; i++) |
for (int i = offset; i < offset + length; i++) |
112 |
{ |
{ |
113 |
dst[i] = get(); |
dst [i] = get (); |
114 |
} |
} |
115 |
|
|
116 |
return this; |
return this; |
117 |
} |
} |
118 |
|
|
119 |
|
/** |
120 |
|
* This method transfers <code>floats<code> from this buffer into the given |
121 |
|
* destination array. |
122 |
|
* |
123 |
|
* @param dst The byte array to write into. |
124 |
|
* |
125 |
|
* @exception BufferUnderflowException If there are fewer than dst.length |
126 |
|
* <code>floats</code> remaining in this buffer. |
127 |
|
*/ |
128 |
public FloatBuffer get (float[] dst) |
public FloatBuffer get (float[] dst) |
129 |
{ |
{ |
130 |
return get(dst, 0, dst.length); |
return get (dst, 0, dst.length); |
131 |
} |
} |
132 |
|
|
133 |
|
/** |
134 |
|
* Writes the content of the the <code>FloatBUFFER</code> src |
135 |
|
* into the buffer. |
136 |
|
* |
137 |
|
* @param src The source data. |
138 |
|
* |
139 |
|
* @exception BufferOverflowException If there is insufficient space in this |
140 |
|
* buffer for the remaining <code>floats<code> in the source buffer. |
141 |
|
* @exception IllegalArgumentException If the source buffer is this buffer. |
142 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
143 |
|
*/ |
144 |
public FloatBuffer put (FloatBuffer src) |
public FloatBuffer put (FloatBuffer src) |
145 |
{ |
{ |
146 |
while (src.hasRemaining()) |
while (src.hasRemaining()) |
149 |
return this; |
return this; |
150 |
} |
} |
151 |
|
|
152 |
|
/** |
153 |
|
* Writes the content of the the <code>float array</code> src |
154 |
|
* into the buffer. |
155 |
|
* |
156 |
|
* @param src The array to copy into the buffer. |
157 |
|
* @param offset The offset within the array of the first byte to be read; |
158 |
|
* must be non-negative and no larger than src.length. |
159 |
|
* @param length The number of bytes to be read from the given array; |
160 |
|
* must be non-negative and no larger than src.length - offset. |
161 |
|
* |
162 |
|
* @exception BufferOverflowException If there is insufficient space in this |
163 |
|
* buffer for the remaining <code>floats<code> in the source array. |
164 |
|
* @exception IndexOutOfBoundsException If the preconditions on the offset |
165 |
|
* and length parameters do not hold |
166 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
167 |
|
*/ |
168 |
public FloatBuffer put (float[] src, int offset, int length) |
public FloatBuffer put (float[] src, int offset, int length) |
169 |
{ |
{ |
170 |
for (int i = offset; i < offset + length; i++) |
for (int i = offset; i < offset + length; i++) |
171 |
put(src[i]); |
put (src [i]); |
172 |
|
|
173 |
return this; |
return this; |
174 |
} |
} |
175 |
|
|
176 |
public final FloatBuffer put(float[] src) |
/** |
177 |
{ |
* Writes the content of the the <code>float array</code> src |
178 |
return put(src, 0, src.length); |
* into the buffer. |
179 |
} |
* |
180 |
|
* @param src The array to copy into the buffer. |
181 |
public final boolean hasArray() |
* |
182 |
|
* @exception BufferOverflowException If there is insufficient space in this |
183 |
|
* buffer for the remaining <code>floats<code> in the source array. |
184 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
185 |
|
*/ |
186 |
|
public final FloatBuffer put (float[] src) |
187 |
|
{ |
188 |
|
return put (src, 0, src.length); |
189 |
|
} |
190 |
|
|
191 |
|
/** |
192 |
|
* Tells whether ot not this buffer is backed by an accessible |
193 |
|
* <code>float</code> array. |
194 |
|
*/ |
195 |
|
public final boolean hasArray () |
196 |
{ |
{ |
197 |
return (backing_buffer != null |
return (backing_buffer != null |
198 |
&& !isReadOnly ()); |
&& !isReadOnly ()); |
199 |
} |
} |
200 |
|
|
201 |
public final float[] array() |
/** |
202 |
|
* Returns the <code>float</code> array that backs this buffer. |
203 |
|
* |
204 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
205 |
|
* @exception UnsupportedOperationException If this buffer is not backed |
206 |
|
* by an accessible array. |
207 |
|
*/ |
208 |
|
public final float[] array () |
209 |
{ |
{ |
210 |
if (backing_buffer == null) |
if (backing_buffer == null) |
211 |
throw new UnsupportedOperationException (); |
throw new UnsupportedOperationException (); |
216 |
return backing_buffer; |
return backing_buffer; |
217 |
} |
} |
218 |
|
|
219 |
public final int arrayOffset() |
/** |
220 |
|
* Returns the offset within this buffer's backing array of the first element. |
221 |
|
* |
222 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
223 |
|
* @exception UnsupportedOperationException If this buffer is not backed |
224 |
|
* by an accessible array. |
225 |
|
*/ |
226 |
|
public final int arrayOffset () |
227 |
{ |
{ |
228 |
if (backing_buffer == null) |
if (backing_buffer == null) |
229 |
throw new UnsupportedOperationException (); |
throw new UnsupportedOperationException (); |
234 |
return array_offset; |
return array_offset; |
235 |
} |
} |
236 |
|
|
237 |
public int hashCode() |
/** |
238 |
{ |
* Calculates a hash code for this buffer. |
239 |
return super.hashCode(); |
*/ |
240 |
|
public int hashCode () |
241 |
|
{ |
242 |
|
// FIXME: Check what SUN calculates here. |
243 |
|
return super.hashCode (); |
244 |
} |
} |
245 |
|
|
246 |
public boolean equals(Object obj) |
/** |
247 |
|
* Checks if this buffer is equal to obj. |
248 |
|
*/ |
249 |
|
public boolean equals (Object obj) |
250 |
{ |
{ |
251 |
if (obj instanceof FloatBuffer) |
if (obj instanceof FloatBuffer) |
252 |
{ |
{ |
253 |
return compareTo(obj) == 0; |
return compareTo (obj) == 0; |
254 |
} |
} |
255 |
|
|
256 |
return false; |
return false; |
257 |
} |
} |
258 |
|
|
259 |
public int compareTo(Object ob) |
/** |
260 |
|
* Compares two <code>FloatBuffer</code> objects. |
261 |
|
* |
262 |
|
* @exception ClassCastException If obj is not an object derived from |
263 |
|
* <code>FloatBuffer</code>. |
264 |
|
*/ |
265 |
|
public int compareTo (Object obj) |
266 |
{ |
{ |
267 |
FloatBuffer a = (FloatBuffer) ob; |
FloatBuffer a = (FloatBuffer) obj; |
268 |
|
|
269 |
if (a.remaining() != remaining()) |
if (a.remaining () != remaining ()) |
270 |
return 1; |
return 1; |
271 |
|
|
272 |
if (! hasArray() || |
if (! hasArray () || |
273 |
! a.hasArray()) |
! a.hasArray ()) |
274 |
{ |
{ |
275 |
return 1; |
return 1; |
276 |
} |
} |
277 |
|
|
278 |
int r = remaining(); |
int r = remaining (); |
279 |
int i1 = position (); |
int i1 = position (); |
280 |
int i2 = a.position (); |
int i2 = a.position (); |
281 |
|
|
282 |
for (int i=0;i<r;i++) |
for (int i = 0; i < r; i++) |
283 |
{ |
{ |
284 |
int t = (int) (get(i1)- a.get(i2)); |
int t = (int) (get (i1) - a.get (i2)); |
285 |
|
|
286 |
if (t != 0) |
if (t != 0) |
287 |
{ |
{ |
288 |
return (int) t; |
return (int) t; |
292 |
return 0; |
return 0; |
293 |
} |
} |
294 |
|
|
295 |
|
/** |
296 |
|
* Returns the byte order of this buffer. |
297 |
|
*/ |
298 |
public abstract ByteOrder order (); |
public abstract ByteOrder order (); |
299 |
public abstract float get(); |
|
300 |
public abstract java.nio. FloatBuffer put(float b); |
/** |
301 |
public abstract float get(int index); |
* Reads the <code>float</code> at this buffer's current position, |
302 |
public abstract java.nio. FloatBuffer put(int index, float b); |
* and then increments the position. |
303 |
public abstract FloatBuffer compact(); |
* |
304 |
public abstract boolean isDirect(); |
* @exception BufferUnderflowException If there are no remaining |
305 |
public abstract FloatBuffer slice(); |
* <code>floats</code> in this buffer. |
306 |
public abstract FloatBuffer duplicate(); |
*/ |
307 |
public abstract FloatBuffer asReadOnlyBuffer(); |
public abstract float get (); |
308 |
|
|
309 |
|
/** |
310 |
|
* Writes the <code>float</code> at this buffer's current position, |
311 |
|
* and then increments the position. |
312 |
|
* |
313 |
|
* @exception BufferOverflowException If there no remaining |
314 |
|
* <code>floats</code> in this buffer. |
315 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
316 |
|
*/ |
317 |
|
public abstract FloatBuffer put (float b); |
318 |
|
|
319 |
|
/** |
320 |
|
* Absolute get method. |
321 |
|
* |
322 |
|
* @exception IndexOutOfBoundsException If index is negative or not smaller |
323 |
|
* than the buffer's limit. |
324 |
|
*/ |
325 |
|
public abstract float get (int index); |
326 |
|
|
327 |
|
/** |
328 |
|
* Absolute put method. |
329 |
|
* |
330 |
|
* @exception IndexOutOfBoundsException If index is negative or not smaller |
331 |
|
* than the buffer's limit. |
332 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
333 |
|
*/ |
334 |
|
public abstract FloatBuffer put (int index, float b); |
335 |
|
|
336 |
|
/** |
337 |
|
* Compacts this buffer. |
338 |
|
* |
339 |
|
* @exception ReadOnlyBufferException If this buffer is read-only. |
340 |
|
*/ |
341 |
|
public abstract FloatBuffer compact (); |
342 |
|
|
343 |
|
/** |
344 |
|
* Tells wether or not this buffer is direct. |
345 |
|
*/ |
346 |
|
public abstract boolean isDirect (); |
347 |
|
|
348 |
|
/** |
349 |
|
* Creates a new <code>FloatBuffer</code> whose content is a shared |
350 |
|
* subsequence of this buffer's content. |
351 |
|
*/ |
352 |
|
public abstract FloatBuffer slice (); |
353 |
|
|
354 |
|
/** |
355 |
|
* Creates a new <code>FloatBuffer</code> that shares this buffer's |
356 |
|
* content. |
357 |
|
*/ |
358 |
|
public abstract FloatBuffer duplicate (); |
359 |
|
|
360 |
|
/** |
361 |
|
* Creates a new read-only <code>FloatBuffer</code> that shares this |
362 |
|
* buffer's content. |
363 |
|
*/ |
364 |
|
public abstract FloatBuffer asReadOnlyBuffer (); |
365 |
} |
} |