2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
40 import gnu
.java
.nio
.ShortBufferImpl
;
42 public abstract class ShortBuffer
extends Buffer
implements Comparable
44 protected short [] backing_buffer
;
45 protected int array_offset
;
47 public static ShortBuffer
allocateDirect(int capacity
)
49 throw new Error ("direct buffers not implemented");
52 public static ShortBuffer
allocate(int capacity
)
54 return new ShortBufferImpl(capacity
, 0, capacity
);
57 final public static ShortBuffer
wrap(short[] array
, int offset
, int length
)
59 return new ShortBufferImpl(array
, offset
, length
);
62 final public static ShortBuffer
wrap(String a
)
65 short[] buffer
= new short[len
];
67 for (int i
=0;i
<len
;i
++)
69 buffer
[i
] = (short) a
.charAt(i
);
72 return wrap(buffer
, 0, len
);
75 final public static ShortBuffer
wrap(short[] array
)
77 return wrap(array
, 0, array
.length
);
80 ShortBuffer (int capacity
, int limit
, int position
, int mark
)
82 super (capacity
, limit
, position
, mark
);
86 public ShortBuffer
get (short[] dst
, int offset
, int length
)
88 for (int i
= offset
; i
< offset
+ length
; i
++)
96 public ShortBuffer
get (short[] dst
)
98 return get(dst
, 0, dst
.length
);
101 public ShortBuffer
put (ShortBuffer src
)
103 while (src
.hasRemaining())
109 public ShortBuffer
put (short[] src
, int offset
, int length
)
111 for (int i
= offset
; i
< offset
+ length
; i
++)
117 public final ShortBuffer
put(short[] src
)
119 return put(src
, 0, src
.length
);
122 public final boolean hasArray()
124 return (backing_buffer
!= null
128 public final short[] array()
130 if (backing_buffer
== null)
131 throw new UnsupportedOperationException ();
134 throw new ReadOnlyBufferException ();
136 return backing_buffer
;
139 public final int arrayOffset()
141 if (backing_buffer
== null)
142 throw new UnsupportedOperationException ();
145 throw new ReadOnlyBufferException ();
150 public int hashCode()
152 return super.hashCode();
155 public boolean equals(Object obj
)
157 if (obj
instanceof ShortBuffer
)
159 return compareTo(obj
) == 0;
165 public int compareTo(Object ob
)
167 ShortBuffer a
= (ShortBuffer
) ob
;
169 if (a
.remaining() != remaining())
179 int i1
= position ();
180 int i2
= a
.position ();
182 for (int i
=0;i
<r
;i
++)
184 int t
= (int) (get(i1
)- a
.get(i2
));
195 public abstract ByteOrder
order ();
196 public abstract short get();
197 public abstract java
.nio
. ShortBuffer
put(short b
);
198 public abstract short get(int index
);
199 public abstract java
.nio
. ShortBuffer
put(int index
, short b
);
200 public abstract ShortBuffer
compact();
201 public abstract boolean isDirect();
202 public abstract ShortBuffer
slice();
203 public abstract ShortBuffer
duplicate();
204 public abstract ShortBuffer
asReadOnlyBuffer();