1 | /* DoubleBuffer.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.DoubleBufferImpl;
|
---|
41 |
|
---|
42 | public abstract class DoubleBuffer extends Buffer implements Comparable
|
---|
43 | {
|
---|
44 | protected double [] backing_buffer;
|
---|
45 | protected int array_offset;
|
---|
46 |
|
---|
47 | public static DoubleBuffer allocateDirect(int capacity)
|
---|
48 | {
|
---|
49 | throw new Error ("direct buffers are not implemented");
|
---|
50 | }
|
---|
51 |
|
---|
52 | public static DoubleBuffer allocate(int capacity)
|
---|
53 | {
|
---|
54 | return new DoubleBufferImpl(capacity, 0, capacity);
|
---|
55 | }
|
---|
56 |
|
---|
57 | final public static DoubleBuffer wrap (double[] array, int offset, int length)
|
---|
58 | {
|
---|
59 | return new DoubleBufferImpl(array, offset, length);
|
---|
60 | }
|
---|
61 |
|
---|
62 | final public static DoubleBuffer wrap(String a)
|
---|
63 | {
|
---|
64 | int len = a.length();
|
---|
65 | double[] buffer = new double[len];
|
---|
66 |
|
---|
67 | for (int i=0;i<len;i++)
|
---|
68 | {
|
---|
69 | buffer[i] = (double) a.charAt(i);
|
---|
70 | }
|
---|
71 |
|
---|
72 | return wrap(buffer, 0, len);
|
---|
73 | }
|
---|
74 |
|
---|
75 | final public static DoubleBuffer wrap(double[] array)
|
---|
76 | {
|
---|
77 | return wrap(array, 0, array.length);
|
---|
78 | }
|
---|
79 |
|
---|
80 | DoubleBuffer (int capacity, int limit, int position, int mark)
|
---|
81 | {
|
---|
82 | super (capacity, limit, position, mark);
|
---|
83 | }
|
---|
84 |
|
---|
85 | public DoubleBuffer get (double[] dst, int offset, int length)
|
---|
86 | {
|
---|
87 | for (int i = offset; i < offset + length; i++)
|
---|
88 | {
|
---|
89 | dst[i] = get();
|
---|
90 | }
|
---|
91 |
|
---|
92 | return this;
|
---|
93 | }
|
---|
94 |
|
---|
95 | public DoubleBuffer get (double[] dst)
|
---|
96 | {
|
---|
97 | return get(dst, 0, dst.length);
|
---|
98 | }
|
---|
99 |
|
---|
100 | public DoubleBuffer put (DoubleBuffer src)
|
---|
101 | {
|
---|
102 | while (src.hasRemaining())
|
---|
103 | put(src.get());
|
---|
104 |
|
---|
105 | return this;
|
---|
106 | }
|
---|
107 |
|
---|
108 | public DoubleBuffer put (double[] src, int offset, int length)
|
---|
109 | {
|
---|
110 | for (int i = offset; i < offset + length; i++)
|
---|
111 | put(src[i]);
|
---|
112 |
|
---|
113 | return this;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public final DoubleBuffer put(double[] src)
|
---|
117 | {
|
---|
118 | return put(src, 0, src.length);
|
---|
119 | }
|
---|
120 |
|
---|
121 | public final boolean hasArray()
|
---|
122 | {
|
---|
123 | return (backing_buffer != null
|
---|
124 | && !isReadOnly ());
|
---|
125 | }
|
---|
126 |
|
---|
127 | public final double[] array()
|
---|
128 | {
|
---|
129 | if (backing_buffer == null)
|
---|
130 | throw new UnsupportedOperationException ();
|
---|
131 |
|
---|
132 | if (isReadOnly ())
|
---|
133 | throw new ReadOnlyBufferException ();
|
---|
134 |
|
---|
135 | return backing_buffer;
|
---|
136 | }
|
---|
137 |
|
---|
138 | public final int arrayOffset()
|
---|
139 | {
|
---|
140 | if (backing_buffer == null)
|
---|
141 | throw new UnsupportedOperationException ();
|
---|
142 |
|
---|
143 | if (isReadOnly ())
|
---|
144 | throw new ReadOnlyBufferException ();
|
---|
145 |
|
---|
146 | return array_offset;
|
---|
147 | }
|
---|
148 |
|
---|
149 | public int hashCode()
|
---|
150 | {
|
---|
151 | return super.hashCode();
|
---|
152 | }
|
---|
153 |
|
---|
154 | public boolean equals(Object obj)
|
---|
155 | {
|
---|
156 | if (obj instanceof DoubleBuffer)
|
---|
157 | {
|
---|
158 | return compareTo(obj) == 0;
|
---|
159 | }
|
---|
160 |
|
---|
161 | return false;
|
---|
162 | }
|
---|
163 |
|
---|
164 | public int compareTo(Object ob)
|
---|
165 | {
|
---|
166 | DoubleBuffer a = (DoubleBuffer) ob;
|
---|
167 |
|
---|
168 | if (a.remaining() != remaining())
|
---|
169 | return 1;
|
---|
170 |
|
---|
171 | if (! hasArray() ||
|
---|
172 | ! a.hasArray())
|
---|
173 | {
|
---|
174 | return 1;
|
---|
175 | }
|
---|
176 |
|
---|
177 | int r = remaining();
|
---|
178 | int i1 = position ();
|
---|
179 | int i2 = a.position ();
|
---|
180 |
|
---|
181 | for (int i=0;i<r;i++)
|
---|
182 | {
|
---|
183 | int t = (int) (get(i1)- a.get(i2));
|
---|
184 | if (t != 0)
|
---|
185 | {
|
---|
186 | return (int) t;
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | return 0;
|
---|
191 | }
|
---|
192 |
|
---|
193 | public abstract ByteOrder order ();
|
---|
194 | public abstract double get();
|
---|
195 | public abstract DoubleBuffer put (double b);
|
---|
196 | public abstract double get(int index);
|
---|
197 | public abstract DoubleBuffer put(int index, double b);
|
---|
198 | public abstract DoubleBuffer compact();
|
---|
199 | public abstract boolean isDirect();
|
---|
200 | public abstract DoubleBuffer slice();
|
---|
201 | public abstract DoubleBuffer duplicate();
|
---|
202 | public abstract DoubleBuffer asReadOnlyBuffer();
|
---|
203 | }
|
---|