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