1. /*
  2. * @(#)X-Buffer.java 1.48 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. // -- This file was mechanically generated: Do not edit! -- //
  8. package java.nio;
  9. /**
  10. * An int buffer.
  11. *
  12. * <p> This class defines four categories of operations upon
  13. * int buffers:
  14. *
  15. * <ul>
  16. *
  17. * <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and
  18. * {@link #put(int) </code><i>put</i><code>} methods that read and write
  19. * single ints; </p></li>
  20. *
  21. * <li><p> Relative {@link #get(int[]) </code><i>bulk get</i><code>}
  22. * methods that transfer contiguous sequences of ints from this buffer
  23. * into an array; and</p></li>
  24. *
  25. * <li><p> Relative {@link #put(int[]) </code><i>bulk put</i><code>}
  26. * methods that transfer contiguous sequences of ints from an
  27. * int array or some other int
  28. * buffer into this buffer; and </p></li>
  29. *
  30. *
  31. * <li><p> Methods for {@link #compact </code>compacting<code>}, {@link
  32. * #duplicate </code>duplicating<code>}, and {@link #slice
  33. * </code>slicing<code>} a int buffer. </p></li>
  34. *
  35. * </ul>
  36. *
  37. * <p> Int buffers can be created either by {@link #allocate
  38. * </code><i>allocation</i><code>}, which allocates space for the buffer's
  39. *
  40. *
  41. * content, by {@link #wrap(int[]) </code><i>wrapping</i><code>} an existing
  42. * int array into a buffer, or by creating a
  43. * <a href="ByteBuffer.html#view"><i>view</i></a> of an existing byte buffer
  44. *
  45. *
  46. *
  47. *
  48. * <p> Like a byte buffer, a int buffer is either <a
  49. * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>. A
  50. * int buffer created via the <tt>wrap</tt> methods of this class will
  51. * be non-direct. A int buffer created as a view of a byte buffer will
  52. * be direct if, and only if, the byte buffer itself is direct. Whether or not
  53. * a int buffer is direct may be determined by invoking the {@link
  54. * #isDirect isDirect} method. </p>
  55. *
  56. *
  57. *
  58. *
  59. * <p> Methods in this class that do not otherwise have a value to return are
  60. * specified to return the buffer upon which they are invoked. This allows
  61. * method invocations to be chained.
  62. *
  63. *
  64. *
  65. * @author Mark Reinhold
  66. * @author JSR-51 Expert Group
  67. * @version 1.48, 03/01/23
  68. * @since 1.4
  69. */
  70. public abstract class IntBuffer
  71. extends Buffer
  72. implements Comparable
  73. {
  74. // These fields are declared here rather than in Heap-X-Buffer in order to
  75. // reduce the number of virtual method invocations needed to access these
  76. // values, which is especially costly when coding small buffers.
  77. //
  78. final int[] hb; // Non-null only for heap buffers
  79. final int offset;
  80. boolean isReadOnly; // Valid only for heap buffers
  81. // Creates a new buffer with the given mark, position, limit, capacity,
  82. // backing array, and array offset
  83. //
  84. IntBuffer(int mark, int pos, int lim, int cap, // package-private
  85. int[] hb, int offset)
  86. {
  87. super(mark, pos, lim, cap);
  88. this.hb = hb;
  89. this.offset = offset;
  90. }
  91. // Creates a new buffer with the given mark, position, limit, and capacity
  92. //
  93. IntBuffer(int mark, int pos, int lim, int cap) { // package-private
  94. this(mark, pos, lim, cap, null, 0);
  95. }
  96. /**
  97. * Allocates a new int buffer.
  98. *
  99. * <p> The new buffer's position will be zero, its limit will be its
  100. * capacity, and its mark will be undefined. It will have a {@link #array
  101. * </code>backing array<code>}, and its {@link #arrayOffset </code>array
  102. * offset<code>} will be zero.
  103. *
  104. * @param capacity
  105. * The new buffer's capacity, in ints
  106. *
  107. * @return The new int buffer
  108. *
  109. * @throws IllegalArgumentException
  110. * If the <tt>capacity</tt> is a negative integer
  111. */
  112. public static IntBuffer allocate(int capacity) {
  113. if (capacity < 0)
  114. throw new IllegalArgumentException();
  115. return new HeapIntBuffer(capacity, capacity);
  116. }
  117. /**
  118. * Wraps a int array into a buffer.
  119. *
  120. * <p> The new buffer will be backed by the the given int array;
  121. * that is, modifications to the buffer will cause the array to be modified
  122. * and vice versa. The new buffer's capacity will be
  123. * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
  124. * will be <tt>offset + length</tt>, and its mark will be undefined. Its
  125. * {@link #array </code>backing array<code>} will be the given array, and
  126. * its {@link #arrayOffset </code>array offset<code>} will be zero. </p>
  127. *
  128. * @param array
  129. * The array that will back the new buffer
  130. *
  131. * @param offset
  132. * The offset of the subarray to be used; must be non-negative and
  133. * no larger than <tt>array.length</tt>. The new buffer's position
  134. * will be set to this value.
  135. *
  136. * @param length
  137. * The length of the subarray to be used;
  138. * must be non-negative and no larger than
  139. * <tt>array.length - offset</tt>.
  140. * The new buffer's limit will be set to <tt>offset + length</tt>.
  141. *
  142. * @return The new int buffer
  143. *
  144. * @throws IndexOutOfBoundsException
  145. * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
  146. * parameters do not hold
  147. */
  148. public static IntBuffer wrap(int[] array,
  149. int offset, int length)
  150. {
  151. try {
  152. return new HeapIntBuffer(array, offset, length);
  153. } catch (IllegalArgumentException x) {
  154. throw new IndexOutOfBoundsException();
  155. }
  156. }
  157. /**
  158. * Wraps a int array into a buffer.
  159. *
  160. * <p> The new buffer will be backed by the the given int array;
  161. * that is, modifications to the buffer will cause the array to be modified
  162. * and vice versa. The new buffer's capacity and limit will be
  163. * <tt>array.length</tt>, its position will be zero, and its mark will be
  164. * undefined. Its {@link #array </code>backing array<code>} will be the
  165. * given array, and its {@link #arrayOffset </code>array offset<code>} will
  166. * be zero. </p>
  167. *
  168. * @param array
  169. * The array that will back this buffer
  170. *
  171. * @return The new int buffer
  172. */
  173. public static IntBuffer wrap(int[] array) {
  174. return wrap(array, 0, array.length);
  175. }
  176. /**
  177. * Creates a new int buffer whose content is a shared subsequence of
  178. * this buffer's content.
  179. *
  180. * <p> The content of the new buffer will start at this buffer's current
  181. * position. Changes to this buffer's content will be visible in the new
  182. * buffer, and vice versa; the two buffers' position, limit, and mark
  183. * values will be independent.
  184. *
  185. * <p> The new buffer's position will be zero, its capacity and its limit
  186. * will be the number of ints remaining in this buffer, and its mark
  187. * will be undefined. The new buffer will be direct if, and only if, this
  188. * buffer is direct, and it will be read-only if, and only if, this buffer
  189. * is read-only. </p>
  190. *
  191. * @return The new int buffer
  192. */
  193. public abstract IntBuffer slice();
  194. /**
  195. * Creates a new int buffer that shares this buffer's content.
  196. *
  197. * <p> The content of the new buffer will be that of this buffer. Changes
  198. * to this buffer's content will be visible in the new buffer, and vice
  199. * versa; the two buffers' position, limit, and mark values will be
  200. * independent.
  201. *
  202. * <p> The new buffer's capacity, limit, position, and mark values will be
  203. * identical to those of this buffer. The new buffer will be direct if,
  204. * and only if, this buffer is direct, and it will be read-only if, and
  205. * only if, this buffer is read-only. </p>
  206. *
  207. * @return The new int buffer
  208. */
  209. public abstract IntBuffer duplicate();
  210. /**
  211. * Creates a new, read-only int buffer that shares this buffer's
  212. * content.
  213. *
  214. * <p> The content of the new buffer will be that of this buffer. Changes
  215. * to this buffer's content will be visible in the new buffer; the new
  216. * buffer itself, however, will be read-only and will not allow the shared
  217. * content to be modified. The two buffers' position, limit, and mark
  218. * values will be independent.
  219. *
  220. * <p> The new buffer's capacity, limit, position, and mark values will be
  221. * identical to those of this buffer.
  222. *
  223. * <p> If this buffer is itself read-only then this method behaves in
  224. * exactly the same way as the {@link #duplicate duplicate} method. </p>
  225. *
  226. * @return The new, read-only int buffer
  227. */
  228. public abstract IntBuffer asReadOnlyBuffer();
  229. // -- Singleton get/put methods --
  230. /**
  231. * Relative <i>get</i> method. Reads the int at this buffer's
  232. * current position, and then increments the position. </p>
  233. *
  234. * @return The int at the buffer's current position
  235. *
  236. * @throws BufferUnderflowException
  237. * If the buffer's current position is not smaller than its limit
  238. */
  239. public abstract int get();
  240. /**
  241. * Relative <i>put</i> method  <i>(optional operation)</i>.
  242. *
  243. * <p> Writes the given int into this buffer at the current
  244. * position, and then increments the position. </p>
  245. *
  246. * @param i
  247. * The int to be written
  248. *
  249. * @return This buffer
  250. *
  251. * @throws BufferOverflowException
  252. * If this buffer's current position is not smaller than its limit
  253. *
  254. * @throws ReadOnlyBufferException
  255. * If this buffer is read-only
  256. */
  257. public abstract IntBuffer put(int i);
  258. /**
  259. * Absolute <i>get</i> method. Reads the int at the given
  260. * index. </p>
  261. *
  262. * @param index
  263. * The index from which the int will be read
  264. *
  265. * @return The int at the given index
  266. *
  267. * @throws IndexOutOfBoundsException
  268. * If <tt>index</tt> is negative
  269. * or not smaller than the buffer's limit
  270. */
  271. public abstract int get(int index);
  272. /**
  273. * Absolute <i>put</i> method  <i>(optional operation)</i>.
  274. *
  275. * <p> Writes the given int into this buffer at the given
  276. * index. </p>
  277. *
  278. * @param index
  279. * The index at which the int will be written
  280. *
  281. * @param i
  282. * The int value to be written
  283. *
  284. * @return This buffer
  285. *
  286. * @throws IndexOutOfBoundsException
  287. * If <tt>index</tt> is negative
  288. * or not smaller than the buffer's limit
  289. *
  290. * @throws ReadOnlyBufferException
  291. * If this buffer is read-only
  292. */
  293. public abstract IntBuffer put(int index, int i);
  294. // -- Bulk get operations --
  295. /**
  296. * Relative bulk <i>get</i> method.
  297. *
  298. * <p> This method transfers ints from this buffer into the given
  299. * destination array. If there are fewer ints remaining in the
  300. * buffer than are required to satisfy the request, that is, if
  301. * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
  302. * ints are transferred and a {@link BufferUnderflowException} is
  303. * thrown.
  304. *
  305. * <p> Otherwise, this method copies <tt>length</tt> ints from this
  306. * buffer into the given array, starting at the current position of this
  307. * buffer and at the given offset in the array. The position of this
  308. * buffer is then incremented by <tt>length</tt>.
  309. *
  310. * <p> In other words, an invocation of this method of the form
  311. * <tt>src.get(dst, off, len)</tt> has exactly the same effect as
  312. * the loop
  313. *
  314. * <pre>
  315. * for (int i = off; i < off + len; i++)
  316. * dst[i] = src.get(); </pre>
  317. *
  318. * except that it first checks that there are sufficient ints in
  319. * this buffer and it is potentially much more efficient. </p>
  320. *
  321. * @param dst
  322. * The array into which ints are to be written
  323. *
  324. * @param offset
  325. * The offset within the array of the first int to be
  326. * written; must be non-negative and no larger than
  327. * <tt>dst.length</tt>
  328. *
  329. * @param length
  330. * The maximum number of ints to be written to the given
  331. * array; must be non-negative and no larger than
  332. * <tt>dst.length - offset</tt>
  333. *
  334. * @return This buffer
  335. *
  336. * @throws BufferUnderflowException
  337. * If there are fewer than <tt>length</tt> ints
  338. * remaining in this buffer
  339. *
  340. * @throws IndexOutOfBoundsException
  341. * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
  342. * parameters do not hold
  343. */
  344. public IntBuffer get(int[] dst, int offset, int length) {
  345. checkBounds(offset, length, dst.length);
  346. if (length > remaining())
  347. throw new BufferUnderflowException();
  348. int end = offset + length;
  349. for (int i = offset; i < end; i++)
  350. dst[i] = get();
  351. return this;
  352. }
  353. /**
  354. * Relative bulk <i>get</i> method.
  355. *
  356. * <p> This method transfers ints from this buffer into the given
  357. * destination array. An invocation of this method of the form
  358. * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
  359. *
  360. * <pre>
  361. * src.get(a, 0, a.length) </pre>
  362. *
  363. * @return This buffer
  364. *
  365. * @throws BufferUnderflowException
  366. * If there are fewer than <tt>length</tt> ints
  367. * remaining in this buffer
  368. */
  369. public IntBuffer get(int[] dst) {
  370. return get(dst, 0, dst.length);
  371. }
  372. // -- Bulk put operations --
  373. /**
  374. * Relative bulk <i>put</i> method  <i>(optional operation)</i>.
  375. *
  376. * <p> This method transfers the ints remaining in the given source
  377. * buffer into this buffer. If there are more ints remaining in the
  378. * source buffer than in this buffer, that is, if
  379. * <tt>src.remaining()</tt> <tt>></tt> <tt>remaining()</tt>,
  380. * then no ints are transferred and a {@link
  381. * BufferOverflowException} is thrown.
  382. *
  383. * <p> Otherwise, this method copies
  384. * <i>n</i> = <tt>src.remaining()</tt> ints from the given
  385. * buffer into this buffer, starting at each buffer's current position.
  386. * The positions of both buffers are then incremented by <i>n</i>.
  387. *
  388. * <p> In other words, an invocation of this method of the form
  389. * <tt>dst.put(src)</tt> has exactly the same effect as the loop
  390. *
  391. * <pre>
  392. * while (src.hasRemaining())
  393. * dst.put(src.get()); </pre>
  394. *
  395. * except that it first checks that there is sufficient space in this
  396. * buffer and it is potentially much more efficient. </p>
  397. *
  398. * @param src
  399. * The source buffer from which ints are to be read;
  400. * must not be this buffer
  401. *
  402. * @return This buffer
  403. *
  404. * @throws BufferOverflowException
  405. * If there is insufficient space in this buffer
  406. * for the remaining ints in the source buffer
  407. *
  408. * @throws IllegalArgumentException
  409. * If the source buffer is this buffer
  410. *
  411. * @throws ReadOnlyBufferException
  412. * If this buffer is read-only
  413. */
  414. public IntBuffer put(IntBuffer src) {
  415. if (src == this)
  416. throw new IllegalArgumentException();
  417. int n = src.remaining();
  418. if (n > remaining())
  419. throw new BufferOverflowException();
  420. for (int i = 0; i < n; i++)
  421. put(src.get());
  422. return this;
  423. }
  424. /**
  425. * Relative bulk <i>put</i> method  <i>(optional operation)</i>.
  426. *
  427. * <p> This method transfers ints into this buffer from the given
  428. * source array. If there are more ints to be copied from the array
  429. * than remain in this buffer, that is, if
  430. * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no
  431. * ints are transferred and a {@link BufferOverflowException} is
  432. * thrown.
  433. *
  434. * <p> Otherwise, this method copies <tt>length</tt> ints from the
  435. * given array into this buffer, starting at the given offset in the array
  436. * and at the current position of this buffer. The position of this buffer
  437. * is then incremented by <tt>length</tt>.
  438. *
  439. * <p> In other words, an invocation of this method of the form
  440. * <tt>dst.put(src, off, len)</tt> has exactly the same effect as
  441. * the loop
  442. *
  443. * <pre>
  444. * for (int i = off; i < off + len; i++)
  445. * dst.put(a[i]); </pre>
  446. *
  447. * except that it first checks that there is sufficient space in this
  448. * buffer and it is potentially much more efficient. </p>
  449. *
  450. * @param src
  451. * The array from which ints are to be read
  452. *
  453. * @param offset
  454. * The offset within the array of the first int to be read;
  455. * must be non-negative and no larger than <tt>array.length</tt>
  456. *
  457. * @param length
  458. * The number of ints to be read from the given array;
  459. * must be non-negative and no larger than
  460. * <tt>array.length - offset</tt>
  461. *
  462. * @return This buffer
  463. *
  464. * @throws BufferOverflowException
  465. * If there is insufficient space in this buffer
  466. *
  467. * @throws IndexOutOfBoundsException
  468. * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
  469. * parameters do not hold
  470. *
  471. * @throws ReadOnlyBufferException
  472. * If this buffer is read-only
  473. */
  474. public IntBuffer put(int[] src, int offset, int length) {
  475. checkBounds(offset, length, src.length);
  476. if (length > remaining())
  477. throw new BufferOverflowException();
  478. int end = offset + length;
  479. for (int i = offset; i < end; i++)
  480. this.put(src[i]);
  481. return this;
  482. }
  483. /**
  484. * Relative bulk <i>put</i> method  <i>(optional operation)</i>.
  485. *
  486. * <p> This method transfers the entire content of the given source
  487. * int array into this buffer. An invocation of this method of the
  488. * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
  489. * invocation
  490. *
  491. * <pre>
  492. * dst.put(a, 0, a.length) </pre>
  493. *
  494. * @return This buffer
  495. *
  496. * @throws BufferOverflowException
  497. * If there is insufficient space in this buffer
  498. *
  499. * @throws ReadOnlyBufferException
  500. * If this buffer is read-only
  501. */
  502. public final IntBuffer put(int[] src) {
  503. return put(src, 0, src.length);
  504. }
  505. // -- Other stuff --
  506. /**
  507. * Tells whether or not this buffer is backed by an accessible int
  508. * array.
  509. *
  510. * <p> If this method returns <tt>true</tt> then the {@link #array() array}
  511. * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
  512. * </p>
  513. *
  514. * @return <tt>true</tt> if, and only if, this buffer
  515. * is backed by an array and is not read-only
  516. */
  517. public final boolean hasArray() {
  518. return (hb != null) && !isReadOnly;
  519. }
  520. /**
  521. * Returns the int array that backs this
  522. * buffer  <i>(optional operation)</i>.
  523. *
  524. * <p> Modifications to this buffer's content will cause the returned
  525. * array's content to be modified, and vice versa.
  526. *
  527. * <p> Invoke the {@link #hasArray hasArray} method before invoking this
  528. * method in order to ensure that this buffer has an accessible backing
  529. * array. </p>
  530. *
  531. * @return The array that backs this buffer
  532. *
  533. * @throws ReadOnlyBufferException
  534. * If this buffer is backed by an array but is read-only
  535. *
  536. * @throws UnsupportedOperationException
  537. * If this buffer is not backed by an accessible array
  538. */
  539. public final int[] array() {
  540. if (hb == null)
  541. throw new UnsupportedOperationException();
  542. if (isReadOnly)
  543. throw new ReadOnlyBufferException();
  544. return hb;
  545. }
  546. /**
  547. * Returns the offset within this buffer's backing array of the first
  548. * element of the buffer  <i>(optional operation)</i>.
  549. *
  550. * <p> If this buffer is backed by an array then buffer position <i>p</i>
  551. * corresponds to array index <i>p</i> + <tt>arrayOffset()</tt>.
  552. *
  553. * <p> Invoke the {@link #hasArray hasArray} method before invoking this
  554. * method in order to ensure that this buffer has an accessible backing
  555. * array. </p>
  556. *
  557. * @return The offset within this buffer's array
  558. * of the first element of the buffer
  559. *
  560. * @throws ReadOnlyBufferException
  561. * If this buffer is backed by an array but is read-only
  562. *
  563. * @throws UnsupportedOperationException
  564. * If this buffer is not backed by an accessible array
  565. */
  566. public final int arrayOffset() {
  567. if (hb == null)
  568. throw new UnsupportedOperationException();
  569. if (isReadOnly)
  570. throw new ReadOnlyBufferException();
  571. return offset;
  572. }
  573. /**
  574. * Compacts this buffer  <i>(optional operation)</i>.
  575. *
  576. * <p> The ints between the buffer's current position and its limit,
  577. * if any, are copied to the beginning of the buffer. That is, the
  578. * int at index <i>p</i> = <tt>position()</tt> is copied
  579. * to index zero, the int at index <i>p</i> + 1 is copied
  580. * to index one, and so forth until the int at index
  581. * <tt>limit()</tt> - 1 is copied to index
  582. * <i>n</i> = <tt>limit()</tt> - <tt>1</tt> - <i>p</i>.
  583. * The buffer's position is then set to <i>n+1</i> and its limit is set to
  584. * its capacity. The mark, if defined, is discarded.
  585. *
  586. * <p> The buffer's position is set to the number of ints copied,
  587. * rather than to zero, so that an invocation of this method can be
  588. * followed immediately by an invocation of another relative <i>put</i>
  589. * method. </p>
  590. *
  591. *
  592. * @return This buffer
  593. *
  594. * @throws ReadOnlyBufferException
  595. * If this buffer is read-only
  596. */
  597. public abstract IntBuffer compact();
  598. /**
  599. * Tells whether or not this int buffer is direct. </p>
  600. *
  601. * @return <tt>true</tt> if, and only if, this buffer is direct
  602. */
  603. public abstract boolean isDirect();
  604. /**
  605. * Returns a string summarizing the state of this buffer. </p>
  606. *
  607. * @return A summary string
  608. */
  609. public String toString() {
  610. StringBuffer sb = new StringBuffer();
  611. sb.append(getClass().getName());
  612. sb.append("[pos=");
  613. sb.append(position());
  614. sb.append(" lim=");
  615. sb.append(limit());
  616. sb.append(" cap=");
  617. sb.append(capacity());
  618. sb.append("]");
  619. return sb.toString();
  620. }
  621. /**
  622. * Returns the current hash code of this buffer.
  623. *
  624. * <p> The hash code of a int buffer depends only upon its remaining
  625. * elements; that is, upon the elements from <tt>position()</tt> up to, and
  626. * including, the element at <tt>limit()</tt> - <tt>1</tt>.
  627. *
  628. * <p> Because buffer hash codes are content-dependent, it is inadvisable
  629. * to use buffers as keys in hash maps or similar data structures unless it
  630. * is known that their contents will not change. </p>
  631. *
  632. * @return The current hash code of this buffer
  633. */
  634. public int hashCode() {
  635. int h = 1;
  636. int p = position();
  637. for (int i = limit() - 1; i >= p; i--)
  638. h = 31 * h + (int)get(i);
  639. return h;
  640. }
  641. /**
  642. * Tells whether or not this buffer is equal to another object.
  643. *
  644. * <p> Two int buffers are equal if, and only if,
  645. *
  646. * <p><ol>
  647. *
  648. * <li><p> They have the same element type, </p></li>
  649. *
  650. * <li><p> They have the same number of remaining elements, and
  651. * </p></li>
  652. *
  653. * <li><p> The two sequences of remaining elements, considered
  654. * independently of their starting positions, are pointwise equal.
  655. * </p></li>
  656. *
  657. * </ol>
  658. *
  659. * <p> A int buffer is not equal to any other type of object. </p>
  660. *
  661. * @param ob The object to which this buffer is to be compared
  662. *
  663. * @return <tt>true</tt> if, and only if, this buffer is equal to the
  664. * given object
  665. */
  666. public boolean equals(Object ob) {
  667. if (!(ob instanceof IntBuffer))
  668. return false;
  669. IntBuffer that = (IntBuffer)ob;
  670. if (this.remaining() != that.remaining())
  671. return false;
  672. int p = this.position();
  673. for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) {
  674. int v1 = this.get(i);
  675. int v2 = that.get(j);
  676. if (v1 != v2) {
  677. if ((v1 != v1) && (v2 != v2)) // For float and double
  678. continue;
  679. return false;
  680. }
  681. }
  682. return true;
  683. }
  684. /**
  685. * Compares this buffer to another object.
  686. *
  687. * <p> Two int buffers are compared by comparing their sequences of
  688. * remaining elements lexicographically, without regard to the starting
  689. * position of each sequence within its corresponding buffer.
  690. *
  691. * <p> A int buffer is not comparable to any other type of object. </p>
  692. *
  693. * @return A negative integer, zero, or a positive integer as this buffer
  694. * is less than, equal to, or greater than the given buffer
  695. *
  696. * @throws ClassCastException
  697. * If the argument is not a int buffer
  698. */
  699. public int compareTo(Object ob) {
  700. IntBuffer that = (IntBuffer)ob;
  701. int n = this.position() + Math.min(this.remaining(), that.remaining());
  702. for (int i = this.position(), j = that.position(); i < n; i++, j++) {
  703. int v1 = this.get(i);
  704. int v2 = that.get(j);
  705. if (v1 == v2)
  706. continue;
  707. if ((v1 != v1) && (v2 != v2)) // For float and double
  708. continue;
  709. if (v1 < v2)
  710. return -1;
  711. return +1;
  712. }
  713. return this.remaining() - that.remaining();
  714. }
  715. // -- Other char stuff --
  716. // -- Other byte stuff: Access to binary data --
  717. /**
  718. * Retrieves this buffer's byte order.
  719. *
  720. * <p> The byte order of a int buffer created by allocation or by
  721. * wrapping an existing <tt>int</tt> array is the {@link
  722. * ByteOrder#nativeOrder </code>native order<code>} of the underlying
  723. * hardware. The byte order of a int buffer created as a <a
  724. * href="ByteBuffer.html#view">view</a> of a byte buffer is that of the
  725. * byte buffer at the moment that the view is created. </p>
  726. *
  727. * @return This buffer's byte order
  728. */
  729. public abstract ByteOrder order();
  730. }