LongBuffer.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* LongBuffer.java --
  2. Copyright (C) 2002 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.nio;
  32. import gnu.java.nio.LongBufferImpl;
  33. public abstract class LongBuffer extends Buffer implements Comparable
  34. {
  35. protected long [] backing_buffer;
  36. protected int array_offset;
  37. public static LongBuffer allocateDirect(int capacity)
  38. {
  39. throw new Error ("direct buffers not implemented");
  40. }
  41. public static LongBuffer allocate(int capacity)
  42. {
  43. return new LongBufferImpl(capacity, 0, capacity);
  44. }
  45. final public static LongBuffer wrap(long[] array, int offset, int length)
  46. {
  47. return new LongBufferImpl (array, offset, length);
  48. }
  49. final public static LongBuffer wrap(String a)
  50. {
  51. int len = a.length();
  52. long[] buffer = new long[len];
  53. for (int i=0;i<len;i++)
  54. {
  55. buffer[i] = (long) a.charAt(i);
  56. }
  57. return wrap(buffer, 0, len);
  58. }
  59. final public static LongBuffer wrap(long[] array)
  60. {
  61. return wrap(array, 0, array.length);
  62. }
  63. LongBuffer (int capacity, int limit, int position, int mark)
  64. {
  65. super (capacity, limit, position, mark);
  66. array_offset = 0;
  67. }
  68. public LongBuffer get (long[] dst, int offset, int length)
  69. {
  70. for (int i = offset; i < offset + length; i++)
  71. {
  72. dst[i] = get();
  73. }
  74. return this;
  75. }
  76. public LongBuffer get (long[] dst)
  77. {
  78. return get(dst, 0, dst.length);
  79. }
  80. public LongBuffer put (LongBuffer src)
  81. {
  82. while (src.hasRemaining())
  83. put(src.get());
  84. return this;
  85. }
  86. public LongBuffer put (long[] src, int offset, int length)
  87. {
  88. for (int i = offset; i < offset + length; i++)
  89. put(src[i]);
  90. return this;
  91. }
  92. public final LongBuffer put(long[] src)
  93. {
  94. return put(src, 0, src.length);
  95. }
  96. public final boolean hasArray()
  97. {
  98. return (backing_buffer != null
  99. && !isReadOnly ());
  100. }
  101. public final long[] array()
  102. {
  103. if (backing_buffer == null)
  104. throw new UnsupportedOperationException ();
  105. if (isReadOnly ())
  106. throw new ReadOnlyBufferException ();
  107. return backing_buffer;
  108. }
  109. public final int arrayOffset()
  110. {
  111. if (backing_buffer == null)
  112. throw new UnsupportedOperationException ();
  113. if (isReadOnly ())
  114. throw new ReadOnlyBufferException ();
  115. return array_offset;
  116. }
  117. public int hashCode()
  118. {
  119. return super.hashCode();
  120. }
  121. public boolean equals(Object obj)
  122. {
  123. if (obj instanceof LongBuffer)
  124. {
  125. return compareTo(obj) == 0;
  126. }
  127. return false;
  128. }
  129. public int compareTo(Object ob)
  130. {
  131. LongBuffer a = (LongBuffer) ob;
  132. if (a.remaining() != remaining())
  133. return 1;
  134. if (! hasArray() ||
  135. ! a.hasArray())
  136. {
  137. return 1;
  138. }
  139. int r = remaining();
  140. int i1 = position ();
  141. int i2 = a.position ();
  142. for (int i=0;i<r;i++)
  143. {
  144. int t = (int) (get(i1)- a.get(i2));
  145. if (t != 0)
  146. {
  147. return (int) t;
  148. }
  149. }
  150. return 0;
  151. }
  152. public abstract ByteOrder order();
  153. public abstract long get();
  154. public abstract java.nio. LongBuffer put(long b);
  155. public abstract long get(int index);
  156. public abstract java.nio. LongBuffer put(int index, long b);
  157. public abstract LongBuffer compact();
  158. public abstract boolean isDirect();
  159. public abstract LongBuffer slice();
  160. public abstract LongBuffer duplicate();
  161. public abstract LongBuffer asReadOnlyBuffer();
  162. }