Source Code Cross Referenced for FloatBuffer.java in  » 6.0-JDK-Modules » j2me » java » nio » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.nio 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation.
008:         * 
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt).
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA
019:         * 
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:
025:        package java.nio;
026:
027:        /** 
028:         * A float buffer.
029:         *
030:         * <p> This class is provided as part of the JSR 239 NIO Buffer
031:         * building block. It is a subset of the
032:         * <code>java.nio.FloatBuffer</code> class in Java(TM) Standard Edition
033:         * version 1.4.2.  Differences are noted in <b><i>bold italic</i></b>.
034:         * The class documentation may make reference to classes that are not
035:         * present in the building block.
036:         *
037:         * <p><b><i> I/O channels, marking and resetting, and read-only buffers
038:         * are not supported.  Allocation of non-direct float buffers,
039:         * compaction, and duplication are not supported.  
040:         * The following methods are omitted:
041:         *
042:         * <ul>
043:         * <li><code>FloatBuffer allocate(int capacity)</code></li>
044:         * <li><code>FloatBuffer compact()</code></li>
045:         * <li><code>FloatBuffer duplicate()</code></li>
046:         * <li><code>Buffer mark()</code></li>
047:         * <li><code>Buffer reset()</code></li>
048:         * <li><code>boolean isReadOnly()</code></li>
049:         * <li><code>FloatBuffer asReadOnlyBuffer()</code></li>
050:         * </ul>
051:         * </i></b>
052:         *
053:         * <p> This class defines four categories of operations upon
054:         * float buffers:
055:         *
056:         * <ul>
057:         *
058:         *   <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and
059:         *   {@link #put(float) </code><i>put</i><code>} methods that read and write
060:         *   single floats; </p></li>
061:         *
062:         *   <li><p> Relative {@link #get(float[]) </code><i>bulk get</i><code>}
063:         *   methods that transfer contiguous sequences of floats from this buffer
064:         *   into an array;</li>
065:         *
066:         *   <li><p> Relative {@link #put(float[]) </code><i>bulk put</i><code>}
067:         *   methods that transfer contiguous sequences of floats from a
068:         *   float array or some other float
069:         *   buffer into this buffer; &#32;and </p></li>
070:         * 
071:         *   <li><p> Methods for compacting, duplicating, and {@link #slice
072:         *   slicing} a float buffer.  <b><i>JSR 239 does
073:         *   not support compacting and duplicating buffers.</i></b> </p></li>
074:         *
075:         * </ul>
076:         *
077:         * <p> Float buffers can be created either by <i>allocation</i>, which
078:         * allocates space for the buffer's content, by {@link #wrap(float[])
079:         * </code><i>wrapping</i><code>} an existing float array into a
080:         * buffer, or by creating a <a
081:         * href="ByteBuffer.html#view"><i>view</i></a> of an existing byte
082:         * buffer. <b><i>JSR 239 supports allocation of
083:         * <code>ByteBuffer</code>s only.</i></b>
084:         *
085:         * <p> Like a byte buffer, a float buffer is either <a
086:         * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>.  A
087:         * float buffer created via the <tt>wrap</tt> methods of this class will
088:         * be non-direct.  A float buffer created as a view of a byte buffer will
089:         * be direct if, and only if, the byte buffer itself is direct.  Whether or not
090:         * a float buffer is direct may be determined by invoking the {@link
091:         * #isDirect isDirect} method.  </p>
092:         *
093:         * <p> Methods in this class that do not otherwise have a value to return are
094:         * specified to return the buffer upon which they are invoked.  This allows
095:         * method invocations to be chained.
096:         */
097:        public abstract class FloatBuffer extends Buffer implements  Comparable {
098:
099:            ByteBufferImpl parent;
100:
101:            float[] array;
102:            int arrayOffset;
103:
104:            boolean isDirect;
105:
106:            boolean disposed = false;
107:
108:            /**
109:             * Constructs a new <code>FloatBuffer</code>.
110:             */
111:            FloatBuffer() {
112:            }
113:
114:            /**
115:             * Wraps a float array into a buffer.
116:             *
117:             * <p> The new buffer will be backed by the given float array;
118:             * that is, modifications to the buffer will cause the array to be modified
119:             * and vice versa.  The new buffer's capacity will be
120:             * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
121:             * will be <tt>offset + length</tt>, and its mark will be undefined.  Its
122:             * {@link #array </code>backing array<code>} will be the given array, and
123:             * its {@link #arrayOffset </code>array offset<code>} will be zero.  </p>
124:             *
125:             * @param  array
126:             *         The array that will back the new buffer
127:             *
128:             * @param  offset
129:             *         The offset of the subarray to be used; must be non-negative and
130:             *         no larger than <tt>array.length</tt>.  The new buffer's position
131:             *         will be set to this value.
132:             *
133:             * @param  length
134:             *         The length of the subarray to be used;
135:             *         must be non-negative and no larger than
136:             *         <tt>array.length - offset</tt>.
137:             *         The new buffer's limit will be set to <tt>offset + length</tt>.
138:             *
139:             * @return  The new float buffer
140:             *
141:             * @throws  IndexOutOfBoundsException
142:             *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
143:             *          parameters do not hold
144:             */
145:            public static FloatBuffer wrap(float[] array, int offset, int length) {
146:                if (offset < 0 || offset > array.length || length < 0
147:                        || length > array.length - offset) {
148:                    throw new IndexOutOfBoundsException();
149:                }
150:
151:                FloatBufferImpl fbi = new FloatBufferImpl(null, array.length,
152:                        array, 0, false);
153:                fbi.position(offset);
154:                fbi.limit(offset + length);
155:                return fbi;
156:            }
157:
158:            /**
159:             * Wraps a float array into a buffer.
160:             *
161:             * <p> The new buffer will be backed by the given float array;
162:             * that is, modifications to the buffer will cause the array to be modified
163:             * and vice versa.  The new buffer's capacity and limit will be
164:             * <tt>array.length</tt>, its position will be zero, and its mark will be
165:             * undefined.  Its {@link #array </code>backing array<code>} will be the
166:             * given array, and its {@link #arrayOffset </code>array offset<code>} will
167:             * be zero.  </p> 
168:             *
169:             * @param  array
170:             *         The array that will back this buffer
171:             *
172:             * @return  The new float buffer
173:             */
174:            public static FloatBuffer wrap(float[] array) {
175:                return wrap(array, 0, array.length);
176:            }
177:
178:            /**
179:             * Creates a new float buffer whose content is a shared
180:             * subsequence of this buffer's content.
181:             *
182:             * <p> The content of the new buffer will start at this buffer's
183:             * current position.  Changes to this buffer's content will be
184:             * visible in the new buffer, and vice versa; the two buffers'
185:             * position, limit, and mark values will be independent. <b><i>JSR
186:             * 239 does not support the mark.</i></b>
187:             *
188:             * <p> The new buffer's position will be zero, its capacity and
189:             * its limit will be the number of floats remaining in this
190:             * buffer, and its mark will be undefined.  The new buffer will be
191:             * direct if, and only if, this buffer is direct, and it will be
192:             * read-only if, and only if, this buffer is read-only. <b><i>JSR
193:             * 239 does not support the mark or read-only buffers.</i></b>
194:             * </p>
195:             *
196:             * @return The new float buffer.
197:             */
198:            public abstract FloatBuffer slice();
199:
200:            /**
201:             * Relative <i>get</i> method.  Reads the float at this
202:             * buffer's current position, and then increments the
203:             * position. </p>
204:             *
205:             * @return The float at the buffer's current position.
206:             *
207:             * @throws BufferUnderflowException If the buffer's current
208:             * position is not smaller than its limit.
209:             */
210:            public abstract float get();
211:
212:            /**
213:             * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional
214:             * operation)</i>.
215:             * 
216:             * <p> Writes the given float into this buffer at the current
217:             * position, and then increments the position. </p>
218:             *
219:             * @param f The float to be written.
220:             *
221:             * @return This buffer.
222:             *
223:             * @throws BufferOverflowException If this buffer's current
224:             * position is not smaller than its limit.
225:             *
226:             * @throws ReadOnlyBufferException If this buffer is
227:             * read-only. <b><i>JSR 239 does not support read-only buffer or
228:             * the <code>ReadOnlyBufferException</code> class.</i></b>
229:             */
230:            public abstract FloatBuffer put(float f);
231:
232:            /**
233:             * Absolute <i>get</i> method.  Reads the float at the given
234:             * index. </p>
235:             *
236:             * @param  index The index from which the float will be read.
237:             *
238:             * @return  The float at the given index.
239:             *
240:             * @throws IndexOutOfBoundsException If <tt>index</tt> is negative
241:             * or not smaller than the buffer's limit.
242:             */
243:            public abstract float get(int index);
244:
245:            /**
246:             * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
247:             * 
248:             * <p> Writes the given float into this buffer at the given
249:             * index. </p>
250:             *
251:             * @param index The index at which the float will be written.
252:             *
253:             * @param f The float value to be written.
254:             *
255:             * @return This buffer.
256:             *
257:             * @throws IndexOutOfBoundsException If <tt>index</tt> is negative
258:             * or not smaller than the buffer's limit.
259:             *
260:             * @throws ReadOnlyBufferException If this buffer is
261:             * read-only. <b><i>JSR 239 does not support read-only buffer or
262:             * the <code>ReadOnlyBufferException</code> class.</i></b>
263:             */
264:            public abstract FloatBuffer put(int index, float f);
265:
266:            /**
267:             * Relative bulk <i>get</i> method.
268:             *
269:             * <p> This method transfers floats from this buffer into the
270:             * given destination array.  If there are fewer floats
271:             * remaining in the buffer than are required to satisfy the
272:             * request, that is, if
273:             * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
274:             * then no floats are transferred and a {@link
275:             * BufferUnderflowException} is thrown.
276:             *
277:             * <p> Otherwise, this method copies <tt>length</tt> floats
278:             * from this buffer into the given array, starting at the current
279:             * position of this buffer and at the given offset in the array.
280:             * The position of this buffer is then incremented by
281:             * <tt>length</tt>.
282:             *
283:             * <p> In other words, an invocation of this method of the form
284:             * <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same
285:             * effect as the loop
286:             *
287:             * <pre>
288:             *     for (int i = off; i < off + len; i++)
289:             *         dst[i] = src.get(); </pre>
290:             *
291:             * except that it first checks that there are sufficient
292:             * floats in this buffer and it is potentially much more
293:             * efficient. </p>
294:             *
295:             * @param dst The array into which floats are to be written.
296:             *
297:             * @param offset The offset within the array of the first
298:             * float to be written; must be non-negative and no larger
299:             * than <tt>dst.length</tt>.
300:             *
301:             * @param length The maximum number of floats to be written
302:             * to the given array; must be non-negative and no larger than
303:             * <tt>dst.length - offset</tt>.
304:             *
305:             * @return This buffer.
306:             *
307:             * @throws BufferUnderflowException If there are fewer than
308:             * <tt>dst.length</tt> floats remaining in this buffer.
309:             *
310:             * @throws IndexOutOfBoundsException If the preconditions on the
311:             * <tt>offset</tt> and <tt>length</tt> parameters do not hold.
312:             */
313:            public FloatBuffer get(float[] dst, int offset, int length) {
314:                if (offset < 0 || offset > dst.length || length < 0
315:                        || length > dst.length - offset) {
316:                    throw new IndexOutOfBoundsException();
317:                }
318:                if (limit - position < length) {
319:                    throw new BufferUnderflowException();
320:                }
321:
322:                int bytePtr = arrayOffset + (position << 2);
323:                if (isDirect) {
324:                    ByteBufferImpl._getFloats(bytePtr, dst, offset, length);
325:                } else if (array != null) {
326:                    System.arraycopy(array, arrayOffset + position, dst,
327:                            offset, length);
328:                } else {
329:                    for (int i = 0; i < length; i++) {
330:                        dst[offset++] = parent.getFloat(bytePtr);
331:                        bytePtr += 4;
332:                    }
333:                }
334:                position += length;
335:                return this ;
336:            }
337:
338:            /**
339:             * Relative bulk <i>get</i> method.
340:             *
341:             * <p> This method transfers floats from this buffer into the
342:             * given destination array.  An invocation of this method of the
343:             * form <tt>src.get(a)</tt> behaves in exactly the same way as the
344:             * invocation
345:             *
346:             * <pre>
347:             *     src.get(a, 0, a.length) </pre>
348:             *
349:             * @return This buffer.
350:             *
351:             * @throws BufferUnderflowException If there are fewer than
352:             * <tt>length</tt> floats remaining in this buffer.
353:             */
354:            public FloatBuffer get(float[] dst) {
355:                return get(dst, 0, dst.length);
356:            }
357:
358:            /**
359:             * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional
360:             * operation)</i>.
361:             *
362:             * <p> This method transfers the floats remaining in the
363:             * given source buffer into this buffer.  If there are more
364:             * floats remaining in the source buffer than in this buffer,
365:             * that is, if
366:             * <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
367:             * then no floats are transferred and a {@link
368:             * BufferOverflowException} is thrown.
369:             *
370:             * <p> Otherwise, this method copies
371:             * <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> floats from
372:             * the given buffer into this buffer, starting at each buffer's
373:             * current position.  The positions of both buffers are then
374:             * incremented by <i>n</i>.
375:             *
376:             * <p> In other words, an invocation of this method of the form
377:             * <tt>dst.put(src)</tt> has exactly the same effect as the loop
378:             *
379:             * <pre>
380:             *     while (src.hasRemaining())
381:             *         dst.put(src.get()); </pre>
382:             *
383:             * except that it first checks that there is sufficient space in
384:             * this buffer and it is potentially much more efficient. </p>
385:             *
386:             * @param src The source buffer from which floats are to be
387:             * read; must not be this buffer.
388:             *
389:             * @return This buffer.
390:             *
391:             * @throws BufferOverflowException If there is insufficient space
392:             * in this buffer for the remaining floats in the source
393:             * buffer.
394:             *
395:             * @throws IllegalArgumentException If the source buffer is this buffer.
396:             *
397:             * @throws ReadOnlyBufferException If this buffer is
398:             * read-only. <b><i>JSR 239 does not support read-only buffer or
399:             * the <code>ReadOnlyBufferException</code> class.</i></b>
400:             */
401:            public FloatBuffer put(FloatBuffer src) {
402:                if (src == this ) {
403:                    throw new IllegalArgumentException();
404:                }
405:
406:                FloatBufferImpl srci = (FloatBufferImpl) src;
407:
408:                int length = srci.limit - srci.position;
409:                if (length > this .limit - this .position) {
410:                    throw new BufferOverflowException();
411:                }
412:                if (isDirect && srci.isDirect) {
413:                    ByteBufferImpl._copyBytes(srci.arrayOffset
414:                            + (srci.position << 2), this .arrayOffset
415:                            + (this .position << 2), (length << 2));
416:                } else if (isDirect && !srci.isDirect) {
417:                    if (array != null) {
418:                        ByteBufferImpl._putFloats(this .arrayOffset
419:                                + (this .position << 2), srci.array,
420:                                srci.arrayOffset + srci.position, length);
421:                    } else {
422:                        byte[] srcArray = srci.parent.array;
423:                        int srciArrayOffset = srci.parent.arrayOffset
424:                                + srci.arrayOffset + (srci.position << 2);
425:
426:                        ByteBufferImpl._putBytes(this .arrayOffset
427:                                + (this .position << 2), srcArray,
428:                                srciArrayOffset, 4 * length);
429:                    }
430:                } else if (!isDirect && srci.isDirect) {
431:                    if (array != null) {
432:                        ByteBufferImpl._getFloats(srci.arrayOffset
433:                                + (srci.position << 2), this .array,
434:                                this .arrayOffset + this .position, length);
435:                    } else {
436:                        byte[] dstArray = parent.array;
437:                        int dstArrayOffset = parent.arrayOffset + arrayOffset
438:                                + (position << 2);
439:
440:                        ByteBufferImpl._getBytes(srci.arrayOffset
441:                                + (srci.position << 2), dstArray,
442:                                dstArrayOffset, 4 * length);
443:                    }
444:                } else if (!isDirect && !srci.isDirect) {
445:                    if (array != null && srci.array != null) {
446:                        System.arraycopy(srci.array, srci.arrayOffset
447:                                + srci.position, this .array, this .arrayOffset
448:                                + this .position, length);
449:                    } else {
450:                        for (int i = 0; i < length; i++) {
451:                            put(i, srci.get(i));
452:                        }
453:                    }
454:                }
455:
456:                srci.position += length;
457:                this .position += length;
458:                return this ;
459:            }
460:
461:            /**
462:             * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional
463:             * operation)</i>.
464:             *
465:             * <p> This method transfers floats into this buffer from the
466:             * given source array.  If there are more floats to be copied
467:             * from the array than remain in this buffer, that is, if
468:             * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
469:             * then no floats are transferred and a {@link
470:             * BufferOverflowException} is thrown.
471:             *
472:             * <p> Otherwise, this method copies <tt>length</tt> floats
473:             * from the given array into this buffer, starting at the given
474:             * offset in the array and at the current position of this buffer.
475:             * The position of this buffer is then incremented by
476:             * <tt>length</tt>.
477:             *
478:             * <p> In other words, an invocation of this method of the form
479:             * <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same
480:             * effect as the loop
481:             *
482:             * <pre>
483:             *     for (int i = off; i < off + len; i++)
484:             *         dst.put(a[i]); </pre>
485:             *
486:             * except that it first checks that there is sufficient space in
487:             * this buffer and it is potentially much more efficient. </p>
488:             *
489:             * @param src The array from which floats are to be read.
490:             *
491:             * @param offset The offset within the array of the first
492:             * float to be read; must be non-negative and no larger than
493:             * <tt>array.length</tt>.
494:             *
495:             * @param length The number of floats to be read from the
496:             * given array; must be non-negative and no larger than
497:             * <tt>array.length - offset</tt>.
498:             *
499:             * @return This buffer.
500:             *
501:             * @throws BufferOverflowException If there is insufficient space
502:             * in this buffer.
503:             *
504:             * @throws IndexOutOfBoundsException If the preconditions on the
505:             * <tt>offset</tt> and <tt>length</tt> parameters do not hold.
506:             *
507:             * @throws ReadOnlyBufferException If this buffer is
508:             * read-only. <b><i>JSR 239 does not support read-only buffer or
509:             * the <code>ReadOnlyBufferException</code> class.</i></b>
510:             */
511:            public FloatBuffer put(float[] src, int offset, int length) {
512:                if (offset < 0 || offset > src.length || length < 0
513:                        || length > src.length - offset) {
514:                    throw new IndexOutOfBoundsException();
515:                }
516:                if (length > limit - position) {
517:                    throw new BufferOverflowException();
518:                }
519:
520:                int bytePtr = arrayOffset + (position << 2);
521:                if (isDirect) {
522:                    ByteBufferImpl._putFloats(bytePtr, src, offset, length);
523:                } else if (array != null) {
524:                    System.arraycopy(src, offset, array,
525:                            arrayOffset + position, length);
526:                } else {
527:                    for (int i = 0; i < length; i++) {
528:                        parent.putFloat(bytePtr, src[offset++]);
529:                        bytePtr += 4;
530:                    }
531:                }
532:                position += length;
533:                return this ;
534:            }
535:
536:            /**
537:             * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
538:             *
539:             * <p> This method transfers the entire content of the given
540:             * source float array into this buffer.  An invocation of
541:             * this method of the form <tt>dst.put(a)</tt> behaves in exactly
542:             * the same way as the invocation
543:             *
544:             * <pre>
545:             *     dst.put(a, 0, a.length) </pre>
546:             *
547:             * @return This buffer.
548:             *
549:             * @throws BufferOverflowException If there is insufficient space
550:             * in this buffer.
551:             *
552:             * @throws ReadOnlyBufferException If this buffer is
553:             * read-only. <b><i>JSR 239 does not support read-only buffer or
554:             * the <code>ReadOnlyBufferException</code> class.</i></b>
555:             */
556:            public final FloatBuffer put(float[] src) {
557:                return put(src, 0, src.length);
558:            }
559:
560:            /**
561:             * Tells whether or not this buffer is backed by an accessible
562:             * float array.
563:             *
564:             * <p> If this method returns <tt>true</tt> then the {@link
565:             * #array() array} and {@link #arrayOffset() arrayOffset} methods
566:             * may safely be invoked.  </p>
567:             *
568:             * @return <tt>true</tt> if, and only if, this buffer is backed by
569:             * an array and is not read-only. <b><i>JSR 239 does not support
570:             * read-only buffers.</i></b>
571:             */
572:            public final boolean hasArray() {
573:                return array != null;
574:            }
575:
576:            /**
577:             * Returns the float array that backs this
578:             * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
579:             *
580:             * <p> Modifications to this buffer's content will cause the returned
581:             * array's content to be modified, and vice versa.
582:             *
583:             * <p> Invoke the {@link #hasArray hasArray} method before
584:             * invoking this method in order to ensure that this buffer has an
585:             * accessible backing array.  </p>
586:             *
587:             * @return The array that backs this buffer.
588:             *
589:             * @throws ReadOnlyBufferException If this buffer is
590:             * read-only. <b><i>JSR 239 does not support read-only buffer or
591:             * the <code>ReadOnlyBufferException</code> class.</i></b>
592:             *
593:             * @throws UnsupportedOperationException If this buffer is not
594:             * backed by an accessible array.
595:             */
596:            public final float[] array() {
597:                if (array == null) {
598:                    throw new UnsupportedOperationException();
599:                }
600:                return array;
601:            }
602:
603:            /**
604:             * Returns the offset within this buffer's backing array of the
605:             * first element of the buffer&nbsp;&nbsp;<i>(optional
606:             * operation)</i>.
607:             *
608:             * <p> If this buffer is backed by an array then buffer position
609:             * <i>p</i> corresponds to array index
610:             * <i>p</i>&nbsp;+&nbsp;<tt>arrayOffset()</tt>.
611:             *
612:             * <p> Invoke the {@link #hasArray hasArray} method before
613:             * invoking this method in order to ensure that this buffer has an
614:             * accessible backing array.  </p>
615:             *
616:             * @return The offset within this buffer's array of the first
617:             * element of the buffer.
618:             *
619:             * @throws ReadOnlyBufferException If this buffer is
620:             * read-only. <b><i>JSR 239 does not support read-only buffer or
621:             * the <code>ReadOnlyBufferException</code> class.</i></b>
622:             *
623:             * @throws UnsupportedOperationException If this buffer is not
624:             * backed by an accessible array.
625:             */
626:            public final int arrayOffset() {
627:                if (array == null) {
628:                    throw new UnsupportedOperationException();
629:                }
630:                return arrayOffset;
631:
632:            }
633:
634:            /**
635:             * Tells whether or not this float buffer is direct. </p>
636:             *
637:             * @return  <tt>true</tt> if, and only if, this buffer is direct.
638:             */
639:            public abstract boolean isDirect();
640:
641:            /**
642:             * Returns a string summarizing the state of this buffer.
643:             *
644:             * @return A summary string
645:             */
646:            public String toString() {
647:                return "java.nio.ShortBuffer[" + "pos=" + position() + "lim="
648:                        + limit() + "cap=" + capacity() + "]";
649:            }
650:
651:            /**
652:             * Returns the current hash code of this buffer.
653:             *
654:             * <p> The hash code of a float buffer depends only upon its remaining
655:             * elements; that is, upon the elements from <tt>position()</tt> up to, and
656:             * including, the element at <tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>.
657:             *
658:             * <p> Because buffer hash codes are content-dependent, it is inadvisable
659:             * to use buffers as keys in hash maps or similar data structures unless it
660:             * is known that their contents will not change.  </p>
661:             *
662:             * @return  The current hash code of this buffer
663:             */
664:            public int hashCode() {
665:                int h = 1;
666:                int p = position();
667:                for (int i = limit() - 1; i >= p; i--)
668:                    h = 31 * h + (int) get(i);
669:                return h;
670:            }
671:
672:            /**
673:             * Tells whether or not this buffer is equal to another object.
674:             *
675:             * <p> Two float buffers are equal if, and only if,
676:             *
677:             * <p><ol>
678:             *
679:             *   <li><p> They have the same element type,  </p></li>
680:             *
681:             *   <li><p> They have the same number of remaining elements, and
682:             *   </p></li>
683:             *
684:             *   <li><p> The two sequences of remaining elements, considered
685:             *   independently of their starting positions, are pointwise equal.
686:             *   </p></li>
687:             *
688:             * </ol>
689:             *
690:             * <p> A float buffer is not equal to any other type of object.  </p>
691:             *
692:             * @param  ob  The object to which this buffer is to be compared.
693:             *
694:             * @return  <tt>true</tt> if, and only if, this buffer is equal to the
695:             *           given object.
696:             */
697:            public boolean equals(Object ob) {
698:                if (!(ob instanceof  FloatBuffer))
699:                    return false;
700:                FloatBuffer that = (FloatBuffer) ob;
701:                if (this .remaining() != that.remaining())
702:                    return false;
703:                int p = this .position();
704:                for (int i = this .limit() - 1, j = that.limit() - 1; i >= p; i--, j--) {
705:                    float v1 = this .get(i);
706:                    float v2 = that.get(j);
707:                    if (v1 != v2) {
708:                        if ((v1 != v1) && (v2 != v2)) // For float and double
709:                            continue;
710:                        return false;
711:                    }
712:                }
713:                return true;
714:            }
715:
716:            /**
717:             * Compares this buffer to another.
718:             *
719:             * <p> Two float buffers are compared by comparing their sequences of
720:             * remaining elements lexicographically, without regard to the starting
721:             * position of each sequence within its corresponding buffer.
722:             *
723:             * <p> A float buffer is not comparable to any other type of object.
724:             *
725:             * @return  A negative integer, zero, or a positive integer as this buffer
726:             *		is less than, equal to, or greater than the given buffer.
727:             * @throws  ClassCastException If the argument is not a float buffer.
728:             */
729:            public int compareTo(Object ob) {
730:                FloatBuffer that = (FloatBuffer) ob;
731:                int n = this .position()
732:                        + Math.min(this .remaining(), that.remaining());
733:                for (int i = this .position(), j = that.position(); i < n; i++, j++) {
734:                    float v1 = this .get(i);
735:                    float v2 = that.get(j);
736:                    if (v1 == v2)
737:                        continue;
738:                    if ((v1 != v1) && (v2 != v2)) // For float and double
739:                        continue;
740:                    if (v1 < v2)
741:                        return -1;
742:                    return +1;
743:                }
744:                return this.remaining() - that.remaining();
745:            }
746:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.