/[classpath]/classpath/gnu/java/nio/DoubleBufferImpl.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/DoubleBufferImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by mkoch, Tue Mar 11 08:02:22 2003 UTC revision 1.14 by mkoch, Tue Mar 11 11:48:51 2003 UTC
# Line 40  package gnu.java.nio; Line 40  package gnu.java.nio;
40  import java.nio.ByteBuffer;  import java.nio.ByteBuffer;
41  import java.nio.ByteOrder;  import java.nio.ByteOrder;
42  import java.nio.DoubleBuffer;  import java.nio.DoubleBuffer;
43    import java.nio.ReadOnlyBufferException;
44    
45    /**
46     * This is a Heap memory implementation
47     */
48  public final class DoubleBufferImpl extends DoubleBuffer  public final class DoubleBufferImpl extends DoubleBuffer
49  {  {
50    private int array_offset;    private boolean readOnly;
   private boolean ro;  
51        
52    public DoubleBufferImpl(int cap, int off, int lim)    public DoubleBufferImpl(int cap, int off, int lim)
53    {    {
54        super (cap, lim, off, 0);
55      this.backing_buffer = new double[cap];      this.backing_buffer = new double[cap];
56      this.cap = cap;      readOnly = false;
     this.limit(lim);  
     this.position(off);  
57    }    }
58        
59    public DoubleBufferImpl(double[] array, int off, int lim)    public DoubleBufferImpl(double[] array, int offset, int length)
60    {    {
61        super (array.length, length, offset, 0);
62      this.backing_buffer = array;      this.backing_buffer = array;
63      this.cap = array.length;      readOnly = false;
     this.limit(lim);  
     this.position(off);  
64    }    }
65    
66    public DoubleBufferImpl(DoubleBufferImpl copy)    public DoubleBufferImpl(DoubleBufferImpl copy)
67    {    {
68        super (copy.capacity (), copy.limit (), copy.position (), 0);
69      backing_buffer = copy.backing_buffer;      backing_buffer = copy.backing_buffer;
70      ro = copy.ro;      readOnly = copy.isReadOnly ();
     limit(copy.limit());  
     position(copy.position());  
   }  
     
   void inc_pos(int a)  
   {  
     position(position() + a);  
71    }    }
72        
73    DoubleBufferImpl (byte[] copy)    DoubleBufferImpl (byte[] copy)
74    {    {
75        super (copy.length, copy.length, 0, 0);
76      this.backing_buffer = copy != null ? nio_cast (copy) : null;      this.backing_buffer = copy != null ? nio_cast (copy) : null;
77        readOnly = false;
78    }    }
79    
80    private static native byte nio_get_Byte (DoubleBufferImpl b, int index, int limit);    private static native byte nio_get_Byte (DoubleBufferImpl b, int index, int limit);
# Line 93  public final class DoubleBufferImpl exte Line 90  public final class DoubleBufferImpl exte
90    
91    private static native double[] nio_cast (byte[] copy);    private static native double[] nio_cast (byte[] copy);
92    
93    public boolean isReadOnly()    public boolean isReadOnly ()
94    {    {
95      return ro;      return readOnly;
96    }    }
97    
98    public DoubleBuffer slice()    public DoubleBuffer slice ()
99    {    {
100      DoubleBufferImpl A = new DoubleBufferImpl(this);      return new DoubleBufferImpl (this);
     A.array_offset = position();  
     return A;  
101    }    }
102    
103    public DoubleBuffer duplicate()    public DoubleBuffer duplicate()
# Line 112  public final class DoubleBufferImpl exte Line 107  public final class DoubleBufferImpl exte
107    
108    public DoubleBuffer asReadOnlyBuffer()    public DoubleBuffer asReadOnlyBuffer()
109    {    {
110      DoubleBufferImpl a = new DoubleBufferImpl(this);      DoubleBufferImpl result = new DoubleBufferImpl (this);
111      a.ro = true;      result.readOnly = true;
112      return a;      return result;
113    }    }
114    
115    public DoubleBuffer compact()    public DoubleBuffer compact()
# Line 124  public final class DoubleBufferImpl exte Line 119  public final class DoubleBufferImpl exte
119    
120    public boolean isDirect()    public boolean isDirect()
121    {    {
122      return backing_buffer != null;      return false;
123    }    }
124    
125    final public double get()    final public double get()
# Line 136  public final class DoubleBufferImpl exte Line 131  public final class DoubleBufferImpl exte
131    
132    final public DoubleBuffer put(double b)    final public DoubleBuffer put(double b)
133    {    {
134        if (readOnly)
135          throw new ReadOnlyBufferException ();
136        
137      backing_buffer[position()] = b;      backing_buffer[position()] = b;
138      position(position()+1);      position(position()+1);
139      return this;      return this;
# Line 148  public final class DoubleBufferImpl exte Line 146  public final class DoubleBufferImpl exte
146    
147    final public DoubleBuffer put(int index, double b)    final public DoubleBuffer put(int index, double b)
148    {    {
149        if (readOnly)
150          throw new ReadOnlyBufferException ();
151        
152      backing_buffer[index] = b;      backing_buffer[index] = b;
153      return this;      return this;
154    }    }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26