harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r578502 [9/10] - in /harmony/enhanced/classlib/branches/java6: depends/files/ depends/jars/ depends/manifests/xerces_2.9.0/ depends/manifests/xerces_2.9.1/ depends/manifests/xerces_2.9.1/META-INF/ make/ modules/archive/src/main/native/archi...
Date Sat, 22 Sep 2007 21:25:00 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java Sat Sep 22 14:24:54 2007
@@ -31,95 +31,105 @@
  */
 final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
 
-	static ReadWriteFloatArrayBuffer copy(FloatArrayBuffer other,
-			int markOfOther) {
-		ReadWriteFloatArrayBuffer buf = new ReadWriteFloatArrayBuffer(other
-				.capacity(), other.backingArray, other.offset);
-		buf.limit = other.limit();
-		buf.position = other.position();
-		buf.mark = markOfOther;
-		return buf;
-	}
-
-	ReadWriteFloatArrayBuffer(float[] array) {
-		super(array);
-	}
-
-	ReadWriteFloatArrayBuffer(int capacity) {
-		super(capacity);
-	}
-
-	ReadWriteFloatArrayBuffer(int capacity, float[] backingArray,
-			int arrayOffset) {
-		super(capacity, backingArray, arrayOffset);
-	}
-
-	public FloatBuffer asReadOnlyBuffer() {
-		return ReadOnlyFloatArrayBuffer.copy(this, mark);
-	}
-
-	public FloatBuffer compact() {
-		System.arraycopy(backingArray, position + offset, backingArray, offset,
-				remaining());
-		position = limit - position;
-		limit = capacity;
-		mark = UNSET_MARK;
-		return this;
-	}
-
-	public FloatBuffer duplicate() {
-		return copy(this, mark);
-	}
-
-	public boolean isReadOnly() {
-		return false;
-	}
-
-	protected float[] protectedArray() {
-		return backingArray;
-	}
-
-	protected int protectedArrayOffset() {
-		return offset;
-	}
-
-	protected boolean protectedHasArray() {
-		return true;
-	}
-
-	public FloatBuffer put(float c) {
-		if (position == limit) {
-			throw new BufferOverflowException();
-		}
-		backingArray[offset + position++] = c;
-		return this;
-	}
-
-	public FloatBuffer put(int index, float c) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		backingArray[offset + index] = c;
-		return this;
-	}
+    static ReadWriteFloatArrayBuffer copy(FloatArrayBuffer other,
+            int markOfOther) {
+        ReadWriteFloatArrayBuffer buf = new ReadWriteFloatArrayBuffer(other
+                .capacity(), other.backingArray, other.offset);
+        buf.limit = other.limit();
+        buf.position = other.position();
+        buf.mark = markOfOther;
+        return buf;
+    }
+
+    ReadWriteFloatArrayBuffer(float[] array) {
+        super(array);
+    }
+
+    ReadWriteFloatArrayBuffer(int capacity) {
+        super(capacity);
+    }
+
+    ReadWriteFloatArrayBuffer(int capacity, float[] backingArray,
+            int arrayOffset) {
+        super(capacity, backingArray, arrayOffset);
+    }
+
+    @Override
+    public FloatBuffer asReadOnlyBuffer() {
+        return ReadOnlyFloatArrayBuffer.copy(this, mark);
+    }
+
+    @Override
+    public FloatBuffer compact() {
+        System.arraycopy(backingArray, position + offset, backingArray, offset,
+                remaining());
+        position = limit - position;
+        limit = capacity;
+        mark = UNSET_MARK;
+        return this;
+    }
+
+    @Override
+    public FloatBuffer duplicate() {
+        return copy(this, mark);
+    }
+
+    @Override
+    public boolean isReadOnly() {
+        return false;
+    }
+
+    @Override
+    protected float[] protectedArray() {
+        return backingArray;
+    }
+
+    @Override
+    protected int protectedArrayOffset() {
+        return offset;
+    }
+
+    @Override
+    protected boolean protectedHasArray() {
+        return true;
+    }
 
+    @Override
+    public FloatBuffer put(float c) {
+        if (position == limit) {
+            throw new BufferOverflowException();
+        }
+        backingArray[offset + position++] = c;
+        return this;
+    }
+
+    @Override
+    public FloatBuffer put(int index, float c) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        backingArray[offset + index] = c;
+        return this;
+    }
+
+    @Override
     public FloatBuffer put(float[] src, int off, int len) {
         int length = src.length;
-        if (off < 0 || len < 0 || (long)off + (long)len > length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {
             throw new BufferOverflowException();
         }
-        System.arraycopy(src, off, backingArray, offset
-                + position, len);
+        System.arraycopy(src, off, backingArray, offset + position, len);
         position += len;
         return this;
     }
-    
-	public FloatBuffer slice() {
-		return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset
-				+ position);
-	}
+
+    @Override
+    public FloatBuffer slice() {
+        return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset
+                + position);
+    }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java Sat Sep 22 14:24:54 2007
@@ -16,8 +16,6 @@
 
 package java.nio;
 
-
-
 /**
  * HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
  * the implementation of array based byte buffers.
@@ -31,76 +29,85 @@
  */
 final class ReadWriteHeapByteBuffer extends HeapByteBuffer {
 
-	static ReadWriteHeapByteBuffer copy(HeapByteBuffer other, int markOfOther) {
-		ReadWriteHeapByteBuffer buf = new ReadWriteHeapByteBuffer(
-				other.backingArray, other.capacity(), other.offset);
-		buf.limit = other.limit();
-		buf.position = other.position();
-		buf.mark = markOfOther;
-		buf.order(other.order());
-		return buf;
-	}
-
-	ReadWriteHeapByteBuffer(byte[] backingArray) {
-		super(backingArray);
-	}
-
-	ReadWriteHeapByteBuffer(int capacity) {
-		super(capacity);
-	}
-
-	ReadWriteHeapByteBuffer(byte[] backingArray, int capacity, int arrayOffset) {
-		super(backingArray, capacity, arrayOffset);
-	}
-
-	public ByteBuffer asReadOnlyBuffer() {
-		return ReadOnlyHeapByteBuffer.copy(this, mark);
-	}
-
-	public ByteBuffer compact() {
-		System.arraycopy(backingArray, position + offset, backingArray, offset,
-				remaining());
-		position = limit - position;
-		limit = capacity;
-		mark = UNSET_MARK;
-		return this;
-	}
-
-	public ByteBuffer duplicate() {
-		return copy(this, mark);
-	}
-
-	public boolean isReadOnly() {
-		return false;
-	}
-
-	protected byte[] protectedArray() {
-		return backingArray;
-	}
-
-	protected int protectedArrayOffset() {
-		return offset;
-	}
-
-	protected boolean protectedHasArray() {
-		return true;
-	}
-
-	public ByteBuffer put(byte b) {
-		if (position == limit) {
-			throw new BufferOverflowException();
-		}
-		backingArray[offset + position++] = b;
-		return this;
-	}
-
-	public ByteBuffer put(int index, byte b) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		backingArray[offset + index] = b;
-		return this;
-	}
+    static ReadWriteHeapByteBuffer copy(HeapByteBuffer other, int markOfOther) {
+        ReadWriteHeapByteBuffer buf = new ReadWriteHeapByteBuffer(
+                other.backingArray, other.capacity(), other.offset);
+        buf.limit = other.limit();
+        buf.position = other.position();
+        buf.mark = markOfOther;
+        buf.order(other.order());
+        return buf;
+    }
+
+    ReadWriteHeapByteBuffer(byte[] backingArray) {
+        super(backingArray);
+    }
+
+    ReadWriteHeapByteBuffer(int capacity) {
+        super(capacity);
+    }
+
+    ReadWriteHeapByteBuffer(byte[] backingArray, int capacity, int arrayOffset) {
+        super(backingArray, capacity, arrayOffset);
+    }
+
+    @Override
+    public ByteBuffer asReadOnlyBuffer() {
+        return ReadOnlyHeapByteBuffer.copy(this, mark);
+    }
+
+    @Override
+    public ByteBuffer compact() {
+        System.arraycopy(backingArray, position + offset, backingArray, offset,
+                remaining());
+        position = limit - position;
+        limit = capacity;
+        mark = UNSET_MARK;
+        return this;
+    }
+
+    @Override
+    public ByteBuffer duplicate() {
+        return copy(this, mark);
+    }
+
+    @Override
+    public boolean isReadOnly() {
+        return false;
+    }
+
+    @Override
+    protected byte[] protectedArray() {
+        return backingArray;
+    }
+
+    @Override
+    protected int protectedArrayOffset() {
+        return offset;
+    }
+
+    @Override
+    protected boolean protectedHasArray() {
+        return true;
+    }
+
+    @Override
+    public ByteBuffer put(byte b) {
+        if (position == limit) {
+            throw new BufferOverflowException();
+        }
+        backingArray[offset + position++] = b;
+        return this;
+    }
+
+    @Override
+    public ByteBuffer put(int index, byte b) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        backingArray[offset + index] = b;
+        return this;
+    }
 
     /*
      * Override ByteBuffer.put(byte[], int, int) to improve performance.
@@ -109,8 +116,9 @@
      * 
      * @see java.nio.ByteBuffer#put(byte[], int, int)
      */
+    @Override
     public ByteBuffer put(byte[] src, int off, int len) {
-        if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > src.length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {
@@ -119,86 +127,96 @@
         if (isReadOnly()) {
             throw new ReadOnlyBufferException();
         }
-        System.arraycopy(src, off, backingArray, offset
-                + position, len);
+        System.arraycopy(src, off, backingArray, offset + position, len);
         position += len;
         return this;
     }
-    
-	public ByteBuffer putDouble(double value) {
-		return putLong(Double.doubleToRawLongBits(value));
-	}
-
-	public ByteBuffer putDouble(int index, double value) {
-		return putLong(index, Double.doubleToRawLongBits(value));
-	}
-
-	public ByteBuffer putFloat(float value) {
-		return putInt(Float.floatToIntBits(value));
-	}
-
-	public ByteBuffer putFloat(int index, float value) {
-		return putInt(index, Float.floatToIntBits(value));
-	}
-
-	public ByteBuffer putInt(int value) {
-		int newPosition = position + 4;
-		if (newPosition > limit) {
-			throw new BufferOverflowException();
-		}
-		store(position, value);
-		position = newPosition;
-		return this;
-	}
-
-	public ByteBuffer putInt(int index, int value) {
-		if (index < 0 || (long)index + 4 > limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		store(index, value);
-		return this;
-	}
-
-	public ByteBuffer putLong(int index, long value) {
-		if (index < 0 || (long)index + 8 > limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		store(index, value);
-		return this;
-	}
-
-	public ByteBuffer putLong(long value) {
-		int newPosition = position + 8;
-		if (newPosition > limit) {
-			throw new BufferOverflowException();
-		}
-		store(position, value);
-		position = newPosition;
-		return this;
-	}
-
-	public ByteBuffer putShort(int index, short value) {
-		if (index < 0 || (long)index + 2 > limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		store(index, value);
-		return this;
-	}
-
-	public ByteBuffer putShort(short value) {
-		int newPosition = position + 2;
-		if (newPosition > limit) {
-			throw new BufferOverflowException();
-		}
-		store(position, value);
-		position = newPosition;
-		return this;
-	}
-
-	public ByteBuffer slice() {
-		ReadWriteHeapByteBuffer slice = new ReadWriteHeapByteBuffer(
-				backingArray, remaining(), offset + position);
-		slice.order = order;
-		return slice;
-	}
+
+    @Override
+    public ByteBuffer putDouble(double value) {
+        return putLong(Double.doubleToRawLongBits(value));
+    }
+
+    @Override
+    public ByteBuffer putDouble(int index, double value) {
+        return putLong(index, Double.doubleToRawLongBits(value));
+    }
+
+    @Override
+    public ByteBuffer putFloat(float value) {
+        return putInt(Float.floatToIntBits(value));
+    }
+
+    @Override
+    public ByteBuffer putFloat(int index, float value) {
+        return putInt(index, Float.floatToIntBits(value));
+    }
+
+    @Override
+    public ByteBuffer putInt(int value) {
+        int newPosition = position + 4;
+        if (newPosition > limit) {
+            throw new BufferOverflowException();
+        }
+        store(position, value);
+        position = newPosition;
+        return this;
+    }
+
+    @Override
+    public ByteBuffer putInt(int index, int value) {
+        if (index < 0 || (long) index + 4 > limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        store(index, value);
+        return this;
+    }
+
+    @Override
+    public ByteBuffer putLong(int index, long value) {
+        if (index < 0 || (long) index + 8 > limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        store(index, value);
+        return this;
+    }
+
+    @Override
+    public ByteBuffer putLong(long value) {
+        int newPosition = position + 8;
+        if (newPosition > limit) {
+            throw new BufferOverflowException();
+        }
+        store(position, value);
+        position = newPosition;
+        return this;
+    }
+
+    @Override
+    public ByteBuffer putShort(int index, short value) {
+        if (index < 0 || (long) index + 2 > limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        store(index, value);
+        return this;
+    }
+
+    @Override
+    public ByteBuffer putShort(short value) {
+        int newPosition = position + 2;
+        if (newPosition > limit) {
+            throw new BufferOverflowException();
+        }
+        store(position, value);
+        position = newPosition;
+        return this;
+    }
+
+    @Override
+    public ByteBuffer slice() {
+        ReadWriteHeapByteBuffer slice = new ReadWriteHeapByteBuffer(
+                backingArray, remaining(), offset + position);
+        slice.order = order;
+        return slice;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java Sat Sep 22 14:24:54 2007
@@ -30,93 +30,103 @@
  */
 final class ReadWriteIntArrayBuffer extends IntArrayBuffer {
 
-	static ReadWriteIntArrayBuffer copy(IntArrayBuffer other, int markOfOther) {
-		ReadWriteIntArrayBuffer buf = new ReadWriteIntArrayBuffer(other
-				.capacity(), other.backingArray, other.offset);
-		buf.limit = other.limit();
-		buf.position = other.position();
-		buf.mark = markOfOther;
-		return buf;
-	}
-
-	ReadWriteIntArrayBuffer(int[] array) {
-		super(array);
-	}
-
-	ReadWriteIntArrayBuffer(int capacity) {
-		super(capacity);
-	}
-
-	ReadWriteIntArrayBuffer(int capacity, int[] backingArray, int arrayOffset) {
-		super(capacity, backingArray, arrayOffset);
-	}
-
-	public IntBuffer asReadOnlyBuffer() {
-		return ReadOnlyIntArrayBuffer.copy(this, mark);
-	}
-
-	public IntBuffer compact() {
-		System.arraycopy(backingArray, position + offset, backingArray, offset,
-				remaining());
-		position = limit - position;
-		limit = capacity;
-		mark = UNSET_MARK;
-		return this;
-	}
-
-	public IntBuffer duplicate() {
-		return copy(this, mark);
-	}
-
-	public boolean isReadOnly() {
-		return false;
-	}
-
-	protected int[] protectedArray() {
-		return backingArray;
-	}
-
-	protected int protectedArrayOffset() {
-		return offset;
-	}
-
-	protected boolean protectedHasArray() {
-		return true;
-	}
-
-	public IntBuffer put(int c) {
-		if (position == limit) {
-			throw new BufferOverflowException();
-		}
-		backingArray[offset + position++] = c;
-		return this;
-	}
-
-	public IntBuffer put(int index, int c) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		backingArray[offset + index] = c;
-		return this;
-	}
+    static ReadWriteIntArrayBuffer copy(IntArrayBuffer other, int markOfOther) {
+        ReadWriteIntArrayBuffer buf = new ReadWriteIntArrayBuffer(other
+                .capacity(), other.backingArray, other.offset);
+        buf.limit = other.limit();
+        buf.position = other.position();
+        buf.mark = markOfOther;
+        return buf;
+    }
+
+    ReadWriteIntArrayBuffer(int[] array) {
+        super(array);
+    }
+
+    ReadWriteIntArrayBuffer(int capacity) {
+        super(capacity);
+    }
+
+    ReadWriteIntArrayBuffer(int capacity, int[] backingArray, int arrayOffset) {
+        super(capacity, backingArray, arrayOffset);
+    }
+
+    @Override
+    public IntBuffer asReadOnlyBuffer() {
+        return ReadOnlyIntArrayBuffer.copy(this, mark);
+    }
+
+    @Override
+    public IntBuffer compact() {
+        System.arraycopy(backingArray, position + offset, backingArray, offset,
+                remaining());
+        position = limit - position;
+        limit = capacity;
+        mark = UNSET_MARK;
+        return this;
+    }
+
+    @Override
+    public IntBuffer duplicate() {
+        return copy(this, mark);
+    }
+
+    @Override
+    public boolean isReadOnly() {
+        return false;
+    }
+
+    @Override
+    protected int[] protectedArray() {
+        return backingArray;
+    }
+
+    @Override
+    protected int protectedArrayOffset() {
+        return offset;
+    }
+
+    @Override
+    protected boolean protectedHasArray() {
+        return true;
+    }
 
+    @Override
+    public IntBuffer put(int c) {
+        if (position == limit) {
+            throw new BufferOverflowException();
+        }
+        backingArray[offset + position++] = c;
+        return this;
+    }
+
+    @Override
+    public IntBuffer put(int index, int c) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        backingArray[offset + index] = c;
+        return this;
+    }
+
+    @Override
     public IntBuffer put(int[] src, int off, int len) {
         int length = src.length;
-        if (off < 0 || len < 0 || (long)off + (long)len > length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {
             throw new BufferOverflowException();
         }
-        System.arraycopy(src, off, backingArray, offset
-                + position, len);
+        System.arraycopy(src, off, backingArray, offset + position, len);
         position += len;
         return this;
     }
-    
-	public IntBuffer slice() {
-		return new ReadWriteIntArrayBuffer(remaining(), backingArray, offset
-				+ position);
-	}
+
+    @Override
+    public IntBuffer slice() {
+        return new ReadWriteIntArrayBuffer(remaining(), backingArray, offset
+                + position);
+    }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java Sat Sep 22 14:24:54 2007
@@ -30,93 +30,103 @@
  */
 final class ReadWriteLongArrayBuffer extends LongArrayBuffer {
 
-	static ReadWriteLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) {
-		ReadWriteLongArrayBuffer buf = new ReadWriteLongArrayBuffer(other
-				.capacity(), other.backingArray, other.offset);
-		buf.limit = other.limit();
-		buf.position = other.position();
-		buf.mark = markOfOther;
-		return buf;
-	}
-
-	ReadWriteLongArrayBuffer(long[] array) {
-		super(array);
-	}
-
-	ReadWriteLongArrayBuffer(int capacity) {
-		super(capacity);
-	}
-
-	ReadWriteLongArrayBuffer(int capacity, long[] backingArray, int arrayOffset) {
-		super(capacity, backingArray, arrayOffset);
-	}
-
-	public LongBuffer asReadOnlyBuffer() {
-		return ReadOnlyLongArrayBuffer.copy(this, mark);
-	}
-
-	public LongBuffer compact() {
-		System.arraycopy(backingArray, position + offset, backingArray, offset,
-				remaining());
-		position = limit - position;
-		limit = capacity;
-		mark = UNSET_MARK;
-		return this;
-	}
-
-	public LongBuffer duplicate() {
-		return copy(this, mark);
-	}
-
-	public boolean isReadOnly() {
-		return false;
-	}
-
-	protected long[] protectedArray() {
-		return backingArray;
-	}
-
-	protected int protectedArrayOffset() {
-		return offset;
-	}
-
-	protected boolean protectedHasArray() {
-		return true;
-	}
-
-	public LongBuffer put(long c) {
-		if (position == limit) {
-			throw new BufferOverflowException();
-		}
-		backingArray[offset + position++] = c;
-		return this;
-	}
-
-	public LongBuffer put(int index, long c) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		backingArray[offset + index] = c;
-		return this;
-	}
+    static ReadWriteLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) {
+        ReadWriteLongArrayBuffer buf = new ReadWriteLongArrayBuffer(other
+                .capacity(), other.backingArray, other.offset);
+        buf.limit = other.limit();
+        buf.position = other.position();
+        buf.mark = markOfOther;
+        return buf;
+    }
+
+    ReadWriteLongArrayBuffer(long[] array) {
+        super(array);
+    }
+
+    ReadWriteLongArrayBuffer(int capacity) {
+        super(capacity);
+    }
+
+    ReadWriteLongArrayBuffer(int capacity, long[] backingArray, int arrayOffset) {
+        super(capacity, backingArray, arrayOffset);
+    }
+
+    @Override
+    public LongBuffer asReadOnlyBuffer() {
+        return ReadOnlyLongArrayBuffer.copy(this, mark);
+    }
+
+    @Override
+    public LongBuffer compact() {
+        System.arraycopy(backingArray, position + offset, backingArray, offset,
+                remaining());
+        position = limit - position;
+        limit = capacity;
+        mark = UNSET_MARK;
+        return this;
+    }
+
+    @Override
+    public LongBuffer duplicate() {
+        return copy(this, mark);
+    }
+
+    @Override
+    public boolean isReadOnly() {
+        return false;
+    }
+
+    @Override
+    protected long[] protectedArray() {
+        return backingArray;
+    }
+
+    @Override
+    protected int protectedArrayOffset() {
+        return offset;
+    }
+
+    @Override
+    protected boolean protectedHasArray() {
+        return true;
+    }
 
+    @Override
+    public LongBuffer put(long c) {
+        if (position == limit) {
+            throw new BufferOverflowException();
+        }
+        backingArray[offset + position++] = c;
+        return this;
+    }
+
+    @Override
+    public LongBuffer put(int index, long c) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        backingArray[offset + index] = c;
+        return this;
+    }
+
+    @Override
     public LongBuffer put(long[] src, int off, int len) {
         int length = src.length;
-        if (off < 0 || len < 0 || (long)off + (long)len > length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {
             throw new BufferOverflowException();
         }
-        System.arraycopy(src, off, backingArray, offset
-                + position, len);
+        System.arraycopy(src, off, backingArray, offset + position, len);
         position += len;
         return this;
     }
-    
-	public LongBuffer slice() {
-		return new ReadWriteLongArrayBuffer(remaining(), backingArray, offset
-				+ position);
-	}
+
+    @Override
+    public LongBuffer slice() {
+        return new ReadWriteLongArrayBuffer(remaining(), backingArray, offset
+                + position);
+    }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java Sat Sep 22 14:24:54 2007
@@ -31,94 +31,105 @@
  */
 final class ReadWriteShortArrayBuffer extends ShortArrayBuffer {
 
-	static ReadWriteShortArrayBuffer copy(ShortArrayBuffer other,
-			int markOfOther) {
-		ReadWriteShortArrayBuffer buf = new ReadWriteShortArrayBuffer(other
-				.capacity(), other.backingArray, other.offset);
-		buf.limit = other.limit();
-		buf.position = other.position();
-		buf.mark = markOfOther;
-		return buf;
-	}
-
-	ReadWriteShortArrayBuffer(short[] array) {
-		super(array);
-	}
-
-	ReadWriteShortArrayBuffer(int capacity) {
-		super(capacity);
-	}
-
-	ReadWriteShortArrayBuffer(int capacity, short[] backingArray,
-			int arrayOffset) {
-		super(capacity, backingArray, arrayOffset);
-	}
-
-	public ShortBuffer asReadOnlyBuffer() {
-		return ReadOnlyShortArrayBuffer.copy(this, mark);
-	}
-
-	public ShortBuffer compact() {
-		System.arraycopy(backingArray, position + offset, backingArray, offset,
-				remaining());
-		position = limit - position;
-		limit = capacity;
-		mark = UNSET_MARK;
-		return this;
-	}
-
-	public ShortBuffer duplicate() {
-		return copy(this, mark);
-	}
-
-	public boolean isReadOnly() {
-		return false;
-	}
-
-	protected short[] protectedArray() {
-		return backingArray;
-	}
-
-	protected int protectedArrayOffset() {
-		return offset;
-	}
-
-	protected boolean protectedHasArray() {
-		return true;
-	}
-
-	public ShortBuffer put(short c) {
-		if (position == limit) {
-			throw new BufferOverflowException();
-		}
-		backingArray[offset + position++] = c;
-		return this;
-	}
-
-	public ShortBuffer put(int index, short c) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		backingArray[offset + index] = c;
-		return this;
-	}
+    static ReadWriteShortArrayBuffer copy(ShortArrayBuffer other,
+            int markOfOther) {
+        ReadWriteShortArrayBuffer buf = new ReadWriteShortArrayBuffer(other
+                .capacity(), other.backingArray, other.offset);
+        buf.limit = other.limit();
+        buf.position = other.position();
+        buf.mark = markOfOther;
+        return buf;
+    }
+
+    ReadWriteShortArrayBuffer(short[] array) {
+        super(array);
+    }
+
+    ReadWriteShortArrayBuffer(int capacity) {
+        super(capacity);
+    }
+
+    ReadWriteShortArrayBuffer(int capacity, short[] backingArray,
+            int arrayOffset) {
+        super(capacity, backingArray, arrayOffset);
+    }
+
+    @Override
+    public ShortBuffer asReadOnlyBuffer() {
+        return ReadOnlyShortArrayBuffer.copy(this, mark);
+    }
+
+    @Override
+    public ShortBuffer compact() {
+        System.arraycopy(backingArray, position + offset, backingArray, offset,
+                remaining());
+        position = limit - position;
+        limit = capacity;
+        mark = UNSET_MARK;
+        return this;
+    }
+
+    @Override
+    public ShortBuffer duplicate() {
+        return copy(this, mark);
+    }
+
+    @Override
+    public boolean isReadOnly() {
+        return false;
+    }
+
+    @Override
+    protected short[] protectedArray() {
+        return backingArray;
+    }
+
+    @Override
+    protected int protectedArrayOffset() {
+        return offset;
+    }
+
+    @Override
+    protected boolean protectedHasArray() {
+        return true;
+    }
 
+    @Override
+    public ShortBuffer put(short c) {
+        if (position == limit) {
+            throw new BufferOverflowException();
+        }
+        backingArray[offset + position++] = c;
+        return this;
+    }
+
+    @Override
+    public ShortBuffer put(int index, short c) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        backingArray[offset + index] = c;
+        return this;
+    }
+
+    @Override
     public ShortBuffer put(short[] src, int off, int len) {
         int length = src.length;
-        if (off < 0 || len < 0 || (long)off + (long)len > length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {
             throw new BufferOverflowException();
         }
-        System.arraycopy(src, off, backingArray, offset+position, len);
+        System.arraycopy(src, off, backingArray, offset + position, len);
         position += len;
         return this;
     }
-    
-	public ShortBuffer slice() {
-		return new ReadWriteShortArrayBuffer(remaining(), backingArray, offset
-				+ position);
-	}
+
+    @Override
+    public ShortBuffer slice() {
+        return new ReadWriteShortArrayBuffer(remaining(), backingArray, offset
+                + position);
+    }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java Sat Sep 22 14:24:54 2007
@@ -31,58 +31,62 @@
  */
 abstract class ShortArrayBuffer extends ShortBuffer {
 
-	protected final short[] backingArray;
+    protected final short[] backingArray;
 
-	protected final int offset;
+    protected final int offset;
 
-	ShortArrayBuffer(short[] array) {
-		this(array.length, array, 0);
-	}
-
-	ShortArrayBuffer(int capacity) {
-		this(capacity, new short[capacity], 0);
-	}
-
-	ShortArrayBuffer(int capacity, short[] backingArray, int offset) {
-		super(capacity);
-		this.backingArray = backingArray;
-		this.offset = offset;
-	}
-
-	public final short get() {
-		if (position == limit) {
-			throw new BufferUnderflowException();
-		}
-		return backingArray[offset + position++];
-	}
-
-	public final short get(int index) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		return backingArray[offset + index];
-	}
+    ShortArrayBuffer(short[] array) {
+        this(array.length, array, 0);
+    }
+
+    ShortArrayBuffer(int capacity) {
+        this(capacity, new short[capacity], 0);
+    }
+
+    ShortArrayBuffer(int capacity, short[] backingArray, int offset) {
+        super(capacity);
+        this.backingArray = backingArray;
+        this.offset = offset;
+    }
+
+    @Override
+    public final short get() {
+        if (position == limit) {
+            throw new BufferUnderflowException();
+        }
+        return backingArray[offset + position++];
+    }
 
+    @Override
+    public final short get(int index) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        return backingArray[offset + index];
+    }
+
+    @Override
     public final ShortBuffer get(short[] dest, int off, int len) {
         int length = dest.length;
-        if (off < 0 || len < 0 || (long)off + (long)len > length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {
             throw new BufferUnderflowException();
         }
-        System.arraycopy(backingArray, offset + position, dest,
-                off, len);
+        System.arraycopy(backingArray, offset + position, dest, off, len);
         position += len;
         return this;
     }
-    
-	public final boolean isDirect() {
-		return false;
-	}
-
-	public final ByteOrder order() {
-		return ByteOrder.nativeOrder();
-	}
+
+    @Override
+    public final boolean isDirect() {
+        return false;
+    }
+
+    @Override
+    public final ByteOrder order() {
+        return ByteOrder.nativeOrder();
+    }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortBuffer.java Sat Sep 22 14:24:54 2007
@@ -31,535 +31,539 @@
  * </ul>
  * </p>
  */
-public abstract class ShortBuffer extends Buffer implements Comparable<ShortBuffer> {
+public abstract class ShortBuffer extends Buffer implements
+        Comparable<ShortBuffer> {
 
-	/**
-	 * Creates a short buffer based on a new allocated short array.
-	 * 
-	 * @param capacity
-	 *            The capacity of the new buffer
-	 * @return The created short buffer
-	 * @throws IllegalArgumentException
-	 *             If <code>capacity</code> is less than zero
-	 */
-	public static ShortBuffer allocate(int capacity) {
-		if (capacity < 0) {
-			throw new IllegalArgumentException();
-		}
-		return BufferFactory.newShortBuffer(capacity);
-	}
-
-	/**
-	 * Creates a new short buffer by wrapping the given short array.
-	 * <p>
-	 * Calling this method has the same effect as
-	 * <code>wrap(array, 0, array.length)</code>.
-	 * </p>
-	 * 
-	 * @param array
-	 *            The short array which the new buffer will be based on
-	 * @return The created short buffer
-	 */
-	public static ShortBuffer wrap(short[] array) {
-		return wrap(array, 0, array.length);
-	}
-
-	/**
-	 * Creates new a short buffer by wrapping the given short array.
-	 * <p>
-	 * The new buffer's position will be <code>start</code>, limit will be
-	 * <code>start + len</code>, capacity will be the length of the array.
-	 * </p>
-	 * 
-	 * @param array
-	 *            The short array which the new buffer will be based on
-	 * @param start
-	 *            The start index, must be no less than zero and no greater than
-	 *            <code>array.length</code>
-	 * @param len
-	 *            The length, must be no less than zero and no greater than
-	 *            <code>array.length - start</code>
-	 * @return The created short buffer
-	 * @exception IndexOutOfBoundsException
-	 *                If either <code>start</code> or <code>len</code> is
-	 *                invalid
-	 */
-	public static ShortBuffer wrap(short[] array, int start, int len) {
-                if (array == null) {
-                        throw new NullPointerException();
-                }
-                if (start< 0 || len < 0 || (long)start + (long)len > array.length) {
-                        throw new IndexOutOfBoundsException();
-                }
-
-		ShortBuffer buf = BufferFactory.newShortBuffer(array);
-		buf.position = start;
-		buf.limit = start + len;
-
-		return buf;
-	}
-
-	/**
-	 * Constructs a <code>ShortBuffer</code> with given capacity.
-	 * 
-	 * @param capacity
-	 *            The capacity of the buffer
-	 */
-	ShortBuffer(int capacity) {
-		super(capacity);
-	}
-
-	/**
-	 * Returns the short array which this buffer is based on, if there's one.
-	 * 
-	 * @return The short array which this buffer is based on
-	 * @exception ReadOnlyBufferException
-	 *                If this buffer is based on an array, but it is readonly
-	 * @exception UnsupportedOperationException
-	 *                If this buffer is not based on an array
-	 */
-	public final short[] array() {
-		return protectedArray();
-	}
-
-	/**
-	 * Returns the offset of the short array which this buffer is based on, if
-	 * there's one.
-	 * <p>
-	 * The offset is the index of the array corresponds to the zero position of
-	 * the buffer.
-	 * </p>
-	 * 
-	 * @return The offset of the short array which this buffer is based on
-	 * @exception ReadOnlyBufferException
-	 *                If this buffer is based on an array, but it is readonly
-	 * @exception UnsupportedOperationException
-	 *                If this buffer is not based on an array
-	 */
-	public final int arrayOffset() {
-		return protectedArrayOffset();
-	}
-
-	/**
-	 * Returns a readonly buffer that shares content with this buffer.
-	 * <p>
-	 * The returned buffer is guaranteed to be a new instance, even this buffer
-	 * is readonly itself. The new buffer's position, limit, capacity and mark
-	 * are the same as this buffer.
-	 * </p>
-	 * <p>
-	 * The new buffer shares content with this buffer, which means this buffer's
-	 * change of content will be visible to the new buffer. The two buffer's
-	 * position, limit and mark are independent.
-	 * </p>
-	 * 
-	 * @return A readonly version of this buffer.
-	 */
-	public abstract ShortBuffer asReadOnlyBuffer();
-
-	/**
-	 * Compacts this short buffer.
-	 * <p>
-	 * The remaining <code>short</code>s will be moved to the head of the
-	 * buffer, staring from position zero. Then the position is set to
-	 * <code>remaining()</code>; the limit is set to capacity; the mark is
-	 * cleared.
-	 * </p>
-	 * 
-	 * @return This buffer
-	 * @exception ReadOnlyBufferException
-	 *                If no changes may be made to the contents of this buffer
-	 */
-	public abstract ShortBuffer compact();
-
-	/**
-	 * Compare the remaining <code>short</code>s of this buffer to another
-	 * short buffer's remaining <code>short</code>s.
-	 * 
-	 * @param otherBuffer
-	 *            Another short buffer
-	 * @return a negative value if this is less than <code>other</code>; 0 if
-	 *         this equals to <code>other</code>; a positive value if this is
-	 *         greater than <code>other</code>
-	 * @exception ClassCastException
-	 *                If <code>other</code> is not a short buffer
-	 */
-	public int compareTo(ShortBuffer otherBuffer) {
-		int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
-				: otherBuffer.remaining();
-		int thisPos = position;
-		int otherPos = otherBuffer.position;
-		short thisByte, otherByte;
-		while (compareRemaining > 0) {
-			thisByte = get(thisPos);
-			otherByte = otherBuffer.get(otherPos);
-			if (thisByte != otherByte) {
-				return thisByte < otherByte ? -1 : 1;
-			}
-			thisPos++;
-			otherPos++;
-			compareRemaining--;
-		}
-		return remaining() - otherBuffer.remaining();
-	}
-
-	/**
-	 * Returns a duplicated buffer that shares content with this buffer.
-	 * <p>
-	 * The duplicated buffer's position, limit, capacity and mark are the same
-	 * as this buffer. The duplicated buffer's readonly property and byte order
-	 * are same as this buffer too.
-	 * </p>
-	 * <p>
-	 * The new buffer shares content with this buffer, which means either
-	 * buffer's change of content will be visible to the other. The two buffer's
-	 * position, limit and mark are independent.
-	 * </p>
-	 * 
-	 * @return A duplicated buffer that shares content with this buffer.
-	 */
-	public abstract ShortBuffer duplicate();
-
-	/**
-	 * Tests whether this short buffer equals to another object.
-	 * <p>
-	 * If <code>other</code> is not a short buffer, then false is returned.
-	 * </p>
-	 * <p>
-	 * Two short buffers are equals if, and only if, their remaining
-	 * <code>short</code>s are exactly the same. Position, limit, capacity
-	 * and mark are not considered.
-	 * </p>
-	 * 
-	 * @param other
-	 *            the object to be compared against
-	 * @return Whether this short buffer equals to another object.
-	 */
-	public boolean equals(Object other) {
-		if (!(other instanceof ShortBuffer)) {
-			return false;
-		}
-		ShortBuffer otherBuffer = (ShortBuffer) other;
-
-		if (remaining() != otherBuffer.remaining()) {
-			return false;
-		}
-
-		int myPosition = position;
-		int otherPosition = otherBuffer.position;
-		boolean equalSoFar = true;
-		while (equalSoFar && (myPosition < limit)) {
-			equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
-		}
-
-		return equalSoFar;
-	}
-
-	/**
-	 * Returns the short at the current position and increase the position by 1.
-	 * 
-	 * @return The short at the current position.
-	 * @exception BufferUnderflowException
-	 *                If the position is equal or greater than limit
-	 */
-	public abstract short get();
-
-	/**
-	 * Reads <code>short</code>s from the current position into the specified
-	 * short array and increase the position by the number of <code>short</code>s
-	 * read.
-	 * <p>
-	 * Calling this method has the same effect as
-	 * <code>get(dest, 0, dest.length)</code>.
-	 * </p>
-	 * 
-	 * @param dest
-	 *            The destination short array
-	 * @return This buffer
-	 * @exception BufferUnderflowException
-	 *                if <code>dest.length</code> is greater than
-	 *                <code>remaining()</code>
-	 */
-	public ShortBuffer get(short[] dest) {
-		return get(dest, 0, dest.length);
-	}
-
-	/**
-	 * Reads <code>short</code>s from the current position into the specified
-	 * short array, starting from the specified offset, and increase the
-	 * position by the number of <code>short</code>s read.
-	 * 
-	 * @param dest
-	 *            The target short array
-	 * @param off
-	 *            The offset of the short array, must be no less than zero and
-	 *            no greater than <code>dest.length</code>
-	 * @param len
-	 *            The number of <code>short</code>s to read, must be no less
-	 *            than zero and no greater than <code>dest.length - off</code>
-	 * @return This buffer
-	 * @exception IndexOutOfBoundsException
-	 *                If either <code>off</code> or <code>len</code> is
-	 *                invalid
-	 * @exception BufferUnderflowException
-	 *                If <code>len</code> is greater than
-	 *                <code>remaining()</code>
-	 */
-	public ShortBuffer get(short[] dest, int off, int len) {
+    /**
+     * Creates a short buffer based on a new allocated short array.
+     * 
+     * @param capacity
+     *            The capacity of the new buffer
+     * @return The created short buffer
+     * @throws IllegalArgumentException
+     *             If <code>capacity</code> is less than zero
+     */
+    public static ShortBuffer allocate(int capacity) {
+        if (capacity < 0) {
+            throw new IllegalArgumentException();
+        }
+        return BufferFactory.newShortBuffer(capacity);
+    }
+
+    /**
+     * Creates a new short buffer by wrapping the given short array.
+     * <p>
+     * Calling this method has the same effect as
+     * <code>wrap(array, 0, array.length)</code>.
+     * </p>
+     * 
+     * @param array
+     *            The short array which the new buffer will be based on
+     * @return The created short buffer
+     */
+    public static ShortBuffer wrap(short[] array) {
+        return wrap(array, 0, array.length);
+    }
+
+    /**
+     * Creates new a short buffer by wrapping the given short array.
+     * <p>
+     * The new buffer's position will be <code>start</code>, limit will be
+     * <code>start + len</code>, capacity will be the length of the array.
+     * </p>
+     * 
+     * @param array
+     *            The short array which the new buffer will be based on
+     * @param start
+     *            The start index, must be no less than zero and no greater than
+     *            <code>array.length</code>
+     * @param len
+     *            The length, must be no less than zero and no greater than
+     *            <code>array.length - start</code>
+     * @return The created short buffer
+     * @exception IndexOutOfBoundsException
+     *                If either <code>start</code> or <code>len</code> is
+     *                invalid
+     */
+    public static ShortBuffer wrap(short[] array, int start, int len) {
+        if (array == null) {
+            throw new NullPointerException();
+        }
+        if (start < 0 || len < 0 || (long) start + (long) len > array.length) {
+            throw new IndexOutOfBoundsException();
+        }
+
+        ShortBuffer buf = BufferFactory.newShortBuffer(array);
+        buf.position = start;
+        buf.limit = start + len;
+
+        return buf;
+    }
+
+    /**
+     * Constructs a <code>ShortBuffer</code> with given capacity.
+     * 
+     * @param capacity
+     *            The capacity of the buffer
+     */
+    ShortBuffer(int capacity) {
+        super(capacity);
+    }
+
+    /**
+     * Returns the short array which this buffer is based on, if there's one.
+     * 
+     * @return The short array which this buffer is based on
+     * @exception ReadOnlyBufferException
+     *                If this buffer is based on an array, but it is readonly
+     * @exception UnsupportedOperationException
+     *                If this buffer is not based on an array
+     */
+    public final short[] array() {
+        return protectedArray();
+    }
+
+    /**
+     * Returns the offset of the short array which this buffer is based on, if
+     * there's one.
+     * <p>
+     * The offset is the index of the array corresponds to the zero position of
+     * the buffer.
+     * </p>
+     * 
+     * @return The offset of the short array which this buffer is based on
+     * @exception ReadOnlyBufferException
+     *                If this buffer is based on an array, but it is readonly
+     * @exception UnsupportedOperationException
+     *                If this buffer is not based on an array
+     */
+    public final int arrayOffset() {
+        return protectedArrayOffset();
+    }
+
+    /**
+     * Returns a readonly buffer that shares content with this buffer.
+     * <p>
+     * The returned buffer is guaranteed to be a new instance, even this buffer
+     * is readonly itself. The new buffer's position, limit, capacity and mark
+     * are the same as this buffer.
+     * </p>
+     * <p>
+     * The new buffer shares content with this buffer, which means this buffer's
+     * change of content will be visible to the new buffer. The two buffer's
+     * position, limit and mark are independent.
+     * </p>
+     * 
+     * @return A readonly version of this buffer.
+     */
+    public abstract ShortBuffer asReadOnlyBuffer();
+
+    /**
+     * Compacts this short buffer.
+     * <p>
+     * The remaining <code>short</code>s will be moved to the head of the
+     * buffer, staring from position zero. Then the position is set to
+     * <code>remaining()</code>; the limit is set to capacity; the mark is
+     * cleared.
+     * </p>
+     * 
+     * @return This buffer
+     * @exception ReadOnlyBufferException
+     *                If no changes may be made to the contents of this buffer
+     */
+    public abstract ShortBuffer compact();
+
+    /**
+     * Compare the remaining <code>short</code>s of this buffer to another
+     * short buffer's remaining <code>short</code>s.
+     * 
+     * @param otherBuffer
+     *            Another short buffer
+     * @return a negative value if this is less than <code>other</code>; 0 if
+     *         this equals to <code>other</code>; a positive value if this is
+     *         greater than <code>other</code>
+     * @exception ClassCastException
+     *                If <code>other</code> is not a short buffer
+     */
+    public int compareTo(ShortBuffer otherBuffer) {
+        int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
+                : otherBuffer.remaining();
+        int thisPos = position;
+        int otherPos = otherBuffer.position;
+        short thisByte, otherByte;
+        while (compareRemaining > 0) {
+            thisByte = get(thisPos);
+            otherByte = otherBuffer.get(otherPos);
+            if (thisByte != otherByte) {
+                return thisByte < otherByte ? -1 : 1;
+            }
+            thisPos++;
+            otherPos++;
+            compareRemaining--;
+        }
+        return remaining() - otherBuffer.remaining();
+    }
+
+    /**
+     * Returns a duplicated buffer that shares content with this buffer.
+     * <p>
+     * The duplicated buffer's position, limit, capacity and mark are the same
+     * as this buffer. The duplicated buffer's readonly property and byte order
+     * are same as this buffer too.
+     * </p>
+     * <p>
+     * The new buffer shares content with this buffer, which means either
+     * buffer's change of content will be visible to the other. The two buffer's
+     * position, limit and mark are independent.
+     * </p>
+     * 
+     * @return A duplicated buffer that shares content with this buffer.
+     */
+    public abstract ShortBuffer duplicate();
+
+    /**
+     * Tests whether this short buffer equals to another object.
+     * <p>
+     * If <code>other</code> is not a short buffer, then false is returned.
+     * </p>
+     * <p>
+     * Two short buffers are equals if, and only if, their remaining
+     * <code>short</code>s are exactly the same. Position, limit, capacity
+     * and mark are not considered.
+     * </p>
+     * 
+     * @param other
+     *            the object to be compared against
+     * @return Whether this short buffer equals to another object.
+     */
+    @Override
+    public boolean equals(Object other) {
+        if (!(other instanceof ShortBuffer)) {
+            return false;
+        }
+        ShortBuffer otherBuffer = (ShortBuffer) other;
+
+        if (remaining() != otherBuffer.remaining()) {
+            return false;
+        }
+
+        int myPosition = position;
+        int otherPosition = otherBuffer.position;
+        boolean equalSoFar = true;
+        while (equalSoFar && (myPosition < limit)) {
+            equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+        }
+
+        return equalSoFar;
+    }
+
+    /**
+     * Returns the short at the current position and increase the position by 1.
+     * 
+     * @return The short at the current position.
+     * @exception BufferUnderflowException
+     *                If the position is equal or greater than limit
+     */
+    public abstract short get();
+
+    /**
+     * Reads <code>short</code>s from the current position into the specified
+     * short array and increase the position by the number of <code>short</code>s
+     * read.
+     * <p>
+     * Calling this method has the same effect as
+     * <code>get(dest, 0, dest.length)</code>.
+     * </p>
+     * 
+     * @param dest
+     *            The destination short array
+     * @return This buffer
+     * @exception BufferUnderflowException
+     *                if <code>dest.length</code> is greater than
+     *                <code>remaining()</code>
+     */
+    public ShortBuffer get(short[] dest) {
+        return get(dest, 0, dest.length);
+    }
+
+    /**
+     * Reads <code>short</code>s from the current position into the specified
+     * short array, starting from the specified offset, and increase the
+     * position by the number of <code>short</code>s read.
+     * 
+     * @param dest
+     *            The target short array
+     * @param off
+     *            The offset of the short array, must be no less than zero and
+     *            no greater than <code>dest.length</code>
+     * @param len
+     *            The number of <code>short</code>s to read, must be no less
+     *            than zero and no greater than <code>dest.length - off</code>
+     * @return This buffer
+     * @exception IndexOutOfBoundsException
+     *                If either <code>off</code> or <code>len</code> is
+     *                invalid
+     * @exception BufferUnderflowException
+     *                If <code>len</code> is greater than
+     *                <code>remaining()</code>
+     */
+    public ShortBuffer get(short[] dest, int off, int len) {
         int length = dest.length;
-        if (off < 0 || len < 0 || (long)off + (long)len > length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > length) {
             throw new IndexOutOfBoundsException();
         }
-		if (len > remaining()) {
-			throw new BufferUnderflowException();
-		}
-		for (int i = off; i < off + len; i++) {
-			dest[i] = get();
-		}
-		return this;
-	}
-
-	/**
-	 * Returns a short at the specified index, and the position is not changed.
-	 * 
-	 * @param index
-	 *            The index, must be no less than zero and less than limit
-	 * @return A short at the specified index.
-	 * @exception IndexOutOfBoundsException
-	 *                If index is invalid
-	 */
-	public abstract short get(int index);
-
-	/**
-	 * Returns whether this buffer is based on a short array and is read/write.
-	 * <p>
-	 * If this buffer is readonly, then false is returned.
-	 * </p>
-	 * 
-	 * @return Whether this buffer is based on a short array and is read/write.
-	 */
-	public final boolean hasArray() {
-		return protectedHasArray();
-	}
-
-	/**
-	 * Hash code is calculated from the remaining <code>short</code>s.
-	 * <p>
-	 * Position, limit, capacity and mark don't affect the hash code.
-	 * </p>
-	 * 
-	 * @return The hash code calculated from the remaining <code>short</code>s.
-	 */
-	public int hashCode() {
-		int myPosition = position;
-		int hash = 0;
-		while (myPosition < limit) {
-			hash = hash + get(myPosition++);
-		}
-		return hash;
-	}
-
-	/**
-	 * Returns true if this buffer is direct.
-	 * <p>
-	 * A direct buffer will try its best to take advantage of native memory APIs
-	 * and it may not stay in java heap, thus not affected by GC.
-	 * </p>
-	 * <p>
-	 * A short buffer is direct, if it is based on a byte buffer and the byte
-	 * buffer is direct.
-	 * </p>
-	 * 
-	 * @return True if this buffer is direct.
-	 */
-	public abstract boolean isDirect();
-
-	/**
-	 * Returns the byte order used by this buffer when converting
-	 * <code>short</code>s from/to <code>byte</code>s.
-	 * <p>
-	 * If this buffer is not based on a byte buffer, then always return the
-	 * platform's native byte order.
-	 * </p>
-	 * 
-	 * @return The byte order used by this buffer when converting
-	 *         <code>short</code>s from/to <code>byte</code>s.
-	 */
-	public abstract ByteOrder order();
-
-	/**
-	 * Child class implements this method to realize <code>array()</code>.
-	 * 
-	 * @return see <code>array()</code>
-	 */
-	abstract short[] protectedArray();
-
-	/**
-	 * Child class implements this method to realize <code>arrayOffset()</code>.
-	 * 
-	 * @return see <code>arrayOffset()</code>
-	 */
-	abstract int protectedArrayOffset();
-
-	/**
-	 * Child class implements this method to realize <code>hasArray()</code>.
-	 * 
-	 * @return see <code>hasArray()</code>
-	 */
-	abstract boolean protectedHasArray();
-
-	/**
-	 * Writes the given short to the current position and increase the position
-	 * by 1.
-	 * 
-	 * @param s
-	 *            The short to write
-	 * @return This buffer
-	 * @exception BufferOverflowException
-	 *                If position is equal or greater than limit
-	 * @exception ReadOnlyBufferException
-	 *                If no changes may be made to the contents of this buffer
-	 */
-	public abstract ShortBuffer put(short s);
-
-	/**
-	 * Writes <code>short</code>s in the given short array to the current
-	 * position and increase the position by the number of <code>short</code>s
-	 * written.
-	 * <p>
-	 * Calling this method has the same effect as
-	 * <code>put(src, 0, src.length)</code>.
-	 * </p>
-	 * 
-	 * @param src
-	 *            The source short array
-	 * @return This buffer
-	 * @exception BufferOverflowException
-	 *                If <code>remaining()</code> is less than
-	 *                <code>src.length</code>
-	 * @exception ReadOnlyBufferException
-	 *                If no changes may be made to the contents of this buffer
-	 */
-	public final ShortBuffer put(short[] src) {
-		return put(src, 0, src.length);
-	}
-
-	/**
-	 * Writes <code>short</code>s in the given short array, starting from the
-	 * specified offset, to the current position and increase the position by
-	 * the number of <code>short</code>s written.
-	 * 
-	 * @param src
-	 *            The source short array
-	 * @param off
-	 *            The offset of short array, must be no less than zero and no
-	 *            greater than <code>src.length</code>
-	 * @param len
-	 *            The number of <code>short</code>s to write, must be no less
-	 *            than zero and no greater than <code>src.length - off</code>
-	 * @return This buffer
-	 * @exception BufferOverflowException
-	 *                If <code>remaining()</code> is less than
-	 *                <code>len</code>
-	 * @exception IndexOutOfBoundsException
-	 *                If either <code>off</code> or <code>len</code> is
-	 *                invalid
-	 * @exception ReadOnlyBufferException
-	 *                If no changes may be made to the contents of this buffer
-	 */
-	public ShortBuffer put(short[] src, int off, int len) {
+        if (len > remaining()) {
+            throw new BufferUnderflowException();
+        }
+        for (int i = off; i < off + len; i++) {
+            dest[i] = get();
+        }
+        return this;
+    }
+
+    /**
+     * Returns a short at the specified index, and the position is not changed.
+     * 
+     * @param index
+     *            The index, must be no less than zero and less than limit
+     * @return A short at the specified index.
+     * @exception IndexOutOfBoundsException
+     *                If index is invalid
+     */
+    public abstract short get(int index);
+
+    /**
+     * Returns whether this buffer is based on a short array and is read/write.
+     * <p>
+     * If this buffer is readonly, then false is returned.
+     * </p>
+     * 
+     * @return Whether this buffer is based on a short array and is read/write.
+     */
+    public final boolean hasArray() {
+        return protectedHasArray();
+    }
+
+    /**
+     * Hash code is calculated from the remaining <code>short</code>s.
+     * <p>
+     * Position, limit, capacity and mark don't affect the hash code.
+     * </p>
+     * 
+     * @return The hash code calculated from the remaining <code>short</code>s.
+     */
+    @Override
+    public int hashCode() {
+        int myPosition = position;
+        int hash = 0;
+        while (myPosition < limit) {
+            hash = hash + get(myPosition++);
+        }
+        return hash;
+    }
+
+    /**
+     * Returns true if this buffer is direct.
+     * <p>
+     * A direct buffer will try its best to take advantage of native memory APIs
+     * and it may not stay in java heap, thus not affected by GC.
+     * </p>
+     * <p>
+     * A short buffer is direct, if it is based on a byte buffer and the byte
+     * buffer is direct.
+     * </p>
+     * 
+     * @return True if this buffer is direct.
+     */
+    public abstract boolean isDirect();
+
+    /**
+     * Returns the byte order used by this buffer when converting
+     * <code>short</code>s from/to <code>byte</code>s.
+     * <p>
+     * If this buffer is not based on a byte buffer, then always return the
+     * platform's native byte order.
+     * </p>
+     * 
+     * @return The byte order used by this buffer when converting
+     *         <code>short</code>s from/to <code>byte</code>s.
+     */
+    public abstract ByteOrder order();
+
+    /**
+     * Child class implements this method to realize <code>array()</code>.
+     * 
+     * @return see <code>array()</code>
+     */
+    abstract short[] protectedArray();
+
+    /**
+     * Child class implements this method to realize <code>arrayOffset()</code>.
+     * 
+     * @return see <code>arrayOffset()</code>
+     */
+    abstract int protectedArrayOffset();
+
+    /**
+     * Child class implements this method to realize <code>hasArray()</code>.
+     * 
+     * @return see <code>hasArray()</code>
+     */
+    abstract boolean protectedHasArray();
+
+    /**
+     * Writes the given short to the current position and increase the position
+     * by 1.
+     * 
+     * @param s
+     *            The short to write
+     * @return This buffer
+     * @exception BufferOverflowException
+     *                If position is equal or greater than limit
+     * @exception ReadOnlyBufferException
+     *                If no changes may be made to the contents of this buffer
+     */
+    public abstract ShortBuffer put(short s);
+
+    /**
+     * Writes <code>short</code>s in the given short array to the current
+     * position and increase the position by the number of <code>short</code>s
+     * written.
+     * <p>
+     * Calling this method has the same effect as
+     * <code>put(src, 0, src.length)</code>.
+     * </p>
+     * 
+     * @param src
+     *            The source short array
+     * @return This buffer
+     * @exception BufferOverflowException
+     *                If <code>remaining()</code> is less than
+     *                <code>src.length</code>
+     * @exception ReadOnlyBufferException
+     *                If no changes may be made to the contents of this buffer
+     */
+    public final ShortBuffer put(short[] src) {
+        return put(src, 0, src.length);
+    }
+
+    /**
+     * Writes <code>short</code>s in the given short array, starting from the
+     * specified offset, to the current position and increase the position by
+     * the number of <code>short</code>s written.
+     * 
+     * @param src
+     *            The source short array
+     * @param off
+     *            The offset of short array, must be no less than zero and no
+     *            greater than <code>src.length</code>
+     * @param len
+     *            The number of <code>short</code>s to write, must be no less
+     *            than zero and no greater than <code>src.length - off</code>
+     * @return This buffer
+     * @exception BufferOverflowException
+     *                If <code>remaining()</code> is less than
+     *                <code>len</code>
+     * @exception IndexOutOfBoundsException
+     *                If either <code>off</code> or <code>len</code> is
+     *                invalid
+     * @exception ReadOnlyBufferException
+     *                If no changes may be made to the contents of this buffer
+     */
+    public ShortBuffer put(short[] src, int off, int len) {
         int length = src.length;
-        if (off < 0 || len < 0 || (long)off + (long)len > length) {
+        if (off < 0 || len < 0 || (long) off + (long) len > length) {
             throw new IndexOutOfBoundsException();
         }
-        
-		if (len > remaining()) {
-			throw new BufferOverflowException();
-		}
-		for (int i = off; i < off + len; i++) {
-			put(src[i]);
-		}
-		return this;
-	}
-
-	/**
-	 * Writes all the remaining <code>short</code>s of the <code>src</code>
-	 * short buffer to this buffer's current position, and increase both
-	 * buffers' position by the number of <code>short</code>s copied.
-	 * 
-	 * @param src
-	 *            The source short buffer
-	 * @return This buffer
-	 * @exception BufferOverflowException
-	 *                If <code>src.remaining()</code> is greater than this
-	 *                buffer's <code>remaining()</code>
-	 * @exception IllegalArgumentException
-	 *                If <code>src</code> is this buffer
-	 * @exception ReadOnlyBufferException
-	 *                If no changes may be made to the contents of this buffer
-	 */
-	public ShortBuffer put(ShortBuffer src) {
-		if (src == this) {
-			throw new IllegalArgumentException();
-		}
-		if (src.remaining() > remaining()) {
-			throw new BufferOverflowException();
-		}
+
+        if (len > remaining()) {
+            throw new BufferOverflowException();
+        }
+        for (int i = off; i < off + len; i++) {
+            put(src[i]);
+        }
+        return this;
+    }
+
+    /**
+     * Writes all the remaining <code>short</code>s of the <code>src</code>
+     * short buffer to this buffer's current position, and increase both
+     * buffers' position by the number of <code>short</code>s copied.
+     * 
+     * @param src
+     *            The source short buffer
+     * @return This buffer
+     * @exception BufferOverflowException
+     *                If <code>src.remaining()</code> is greater than this
+     *                buffer's <code>remaining()</code>
+     * @exception IllegalArgumentException
+     *                If <code>src</code> is this buffer
+     * @exception ReadOnlyBufferException
+     *                If no changes may be made to the contents of this buffer
+     */
+    public ShortBuffer put(ShortBuffer src) {
+        if (src == this) {
+            throw new IllegalArgumentException();
+        }
+        if (src.remaining() > remaining()) {
+            throw new BufferOverflowException();
+        }
         short[] contents = new short[src.remaining()];
         src.get(contents);
         put(contents);
-		return this;
-	}
+        return this;
+    }
 
-	/**
-	 * Write a short to the specified index of this buffer and the position is
-	 * not changed.
-	 * 
-	 * @param index
-	 *            The index, must be no less than zero and less than the limit
-	 * @param s
-	 *            The short to write
-	 * @return This buffer
-	 * @exception IndexOutOfBoundsException
-	 *                If index is invalid
-	 * @exception ReadOnlyBufferException
-	 *                If no changes may be made to the contents of this buffer
-	 */
-	public abstract ShortBuffer put(int index, short s);
-
-	/**
-	 * Returns a sliced buffer that shares content with this buffer.
-	 * <p>
-	 * The sliced buffer's capacity will be this buffer's
-	 * <code>remaining()</code>, and its zero position will correspond to
-	 * this buffer's current position. The new buffer's position will be 0,
-	 * limit will be its capacity, and its mark is unset. The new buffer's
-	 * readonly property and byte order are same as this buffer.
-	 * </p>
-	 * <p>
-	 * The new buffer shares content with this buffer, which means either
-	 * buffer's change of content will be visible to the other. The two buffer's
-	 * position, limit and mark are independent.
-	 * </p>
-	 * 
-	 * @return A sliced buffer that shares content with this buffer.
-	 */
-	public abstract ShortBuffer slice();
-
-	/**
-	 * Returns a string represents the state of this short buffer.
-	 * 
-	 * @return A string represents the state of this short buffer.
-	 */
-	public String toString() {
-		StringBuffer buf = new StringBuffer();
-		buf.append(getClass().getName());
-		buf.append(", status: capacity="); //$NON-NLS-1$
-		buf.append(capacity());
-		buf.append(" position="); //$NON-NLS-1$
-		buf.append(position());
-		buf.append(" limit="); //$NON-NLS-1$
-		buf.append(limit());
-		return buf.toString();
-	}
+    /**
+     * Write a short to the specified index of this buffer and the position is
+     * not changed.
+     * 
+     * @param index
+     *            The index, must be no less than zero and less than the limit
+     * @param s
+     *            The short to write
+     * @return This buffer
+     * @exception IndexOutOfBoundsException
+     *                If index is invalid
+     * @exception ReadOnlyBufferException
+     *                If no changes may be made to the contents of this buffer
+     */
+    public abstract ShortBuffer put(int index, short s);
+
+    /**
+     * Returns a sliced buffer that shares content with this buffer.
+     * <p>
+     * The sliced buffer's capacity will be this buffer's
+     * <code>remaining()</code>, and its zero position will correspond to
+     * this buffer's current position. The new buffer's position will be 0,
+     * limit will be its capacity, and its mark is unset. The new buffer's
+     * readonly property and byte order are same as this buffer.
+     * </p>
+     * <p>
+     * The new buffer shares content with this buffer, which means either
+     * buffer's change of content will be visible to the other. The two buffer's
+     * position, limit and mark are independent.
+     * </p>
+     * 
+     * @return A sliced buffer that shares content with this buffer.
+     */
+    public abstract ShortBuffer slice();
+
+    /**
+     * Returns a string represents the state of this short buffer.
+     * 
+     * @return A string represents the state of this short buffer.
+     */
+    @Override
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append(getClass().getName());
+        buf.append(", status: capacity="); //$NON-NLS-1$
+        buf.append(capacity());
+        buf.append(" position="); //$NON-NLS-1$
+        buf.append(position());
+        buf.append(" limit="); //$NON-NLS-1$
+        buf.append(limit());
+        return buf.toString();
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java Sat Sep 22 14:24:54 2007
@@ -19,7 +19,6 @@
 import org.apache.harmony.nio.internal.DirectBuffer;
 import org.apache.harmony.luni.platform.PlatformAddress;
 
-
 /**
  * This class wraps a byte buffer to be a short buffer.
  * <p>
@@ -31,166 +30,176 @@
  * The adapter extends Buffer, thus has its own position and limit.</li>
  * </ul>
  * </p>
- * 
  */
-final class ShortToByteBufferAdapter extends ShortBuffer implements DirectBuffer {
+final class ShortToByteBufferAdapter extends ShortBuffer implements
+        DirectBuffer {
 
-	static ShortBuffer wrap(ByteBuffer byteBuffer) {
-		return new ShortToByteBufferAdapter(byteBuffer.slice());
-	}
-
-	private final ByteBuffer byteBuffer;
-
-	ShortToByteBufferAdapter(ByteBuffer byteBuffer) {
-		super((byteBuffer.capacity() >> 1));
-		this.byteBuffer = byteBuffer;
-		this.byteBuffer.clear();
-	}
-
-        public int getByteCapacity() {
-            if (byteBuffer instanceof DirectBuffer) {
-                return ((DirectBuffer)byteBuffer).getByteCapacity();
-            } else {
-                assert false : byteBuffer;
-                return -1;
-            }            
-        }
-
-        public PlatformAddress getEffectiveAddress() {
-            if (byteBuffer instanceof DirectBuffer) {
-                return ((DirectBuffer)byteBuffer).getEffectiveAddress();
-            } else {
-                assert false : byteBuffer;
-                return null;
-            }
-        }
-
-        public PlatformAddress getBaseAddress() {
-            if (byteBuffer instanceof DirectBuffer) {
-                return ((DirectBuffer)byteBuffer).getBaseAddress();
-            } else {
-                assert false : byteBuffer;
-                return null;
-            }
-        }
-            
-        public boolean isAddressValid() {
-            if (byteBuffer instanceof DirectBuffer) {
-                return ((DirectBuffer)byteBuffer).isAddressValid();
-            } else {
-                assert false : byteBuffer;
-                return false;
-            }
-        }
-
-        public void addressValidityCheck() {
-            if (byteBuffer instanceof DirectBuffer) {
-                ((DirectBuffer)byteBuffer).addressValidityCheck();
-            } else {
-                assert false : byteBuffer;
-            }
-        }
-            
-        public void free() {
-            if (byteBuffer instanceof DirectBuffer) {
-                ((DirectBuffer)byteBuffer).free();
-            } else {
-                assert false : byteBuffer;
-            }   
-        }
-
-	public ShortBuffer asReadOnlyBuffer() {
-		ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
-				.asReadOnlyBuffer());
-		buf.limit = limit;
-		buf.position = position;
-		buf.mark = mark;
-		return buf;
-	}
-
-	public ShortBuffer compact() {
-		if (byteBuffer.isReadOnly()) {
-			throw new ReadOnlyBufferException();
-		}
-		byteBuffer.limit(limit << 1);
-		byteBuffer.position(position << 1);
-		byteBuffer.compact();
-		byteBuffer.clear();
-		position = limit - position;
-		limit = capacity;
-		mark = UNSET_MARK;
-		return this;
-	}
-
-	public ShortBuffer duplicate() {
-		ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
-				.duplicate());
-		buf.limit = limit;
-		buf.position = position;
-		buf.mark = mark;
-		return buf;
-	}
-
-	public short get() {
-		if (position == limit) {
-			throw new BufferUnderflowException();
-		}
-		return byteBuffer.getShort(position++ << 1);
-	}
-
-	public short get(int index) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		return byteBuffer.getShort(index << 1);
-	}
-
-	public boolean isDirect() {
-		return byteBuffer.isDirect();
-	}
-
-	public boolean isReadOnly() {
-		return byteBuffer.isReadOnly();
-	}
-
-	public ByteOrder order() {
-		return byteBuffer.order();
-	}
-
-	protected short[] protectedArray() {
-		throw new UnsupportedOperationException();
-	}
-
-	protected int protectedArrayOffset() {
-		throw new UnsupportedOperationException();
-	}
-
-	protected boolean protectedHasArray() {
-		return false;
-	}
-
-	public ShortBuffer put(short c) {
-		if (position == limit) {
-			throw new BufferOverflowException();
-		}
-		byteBuffer.putShort(position++ << 1, c);
-		return this;
-	}
-
-	public ShortBuffer put(int index, short c) {
-		if (index < 0 || index >= limit) {
-			throw new IndexOutOfBoundsException();
-		}
-		byteBuffer.putShort(index << 1, c);
-		return this;
-	}
-
-	public ShortBuffer slice() {
-		byteBuffer.limit(limit << 1);
-		byteBuffer.position(position << 1);
-		ShortBuffer result = new ShortToByteBufferAdapter(byteBuffer.slice());
-		byteBuffer.clear();
-		return result;
-	}
+    static ShortBuffer wrap(ByteBuffer byteBuffer) {
+        return new ShortToByteBufferAdapter(byteBuffer.slice());
+    }
+
+    private final ByteBuffer byteBuffer;
+
+    ShortToByteBufferAdapter(ByteBuffer byteBuffer) {
+        super((byteBuffer.capacity() >> 1));
+        this.byteBuffer = byteBuffer;
+        this.byteBuffer.clear();
+    }
+
+    public int getByteCapacity() {
+        if (byteBuffer instanceof DirectBuffer) {
+            return ((DirectBuffer) byteBuffer).getByteCapacity();
+        }
+        assert false : byteBuffer;
+        return -1;
+    }
+
+    public PlatformAddress getEffectiveAddress() {
+        if (byteBuffer instanceof DirectBuffer) {
+            return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+        }
+        assert false : byteBuffer;
+        return null;
+    }
+
+    public PlatformAddress getBaseAddress() {
+        if (byteBuffer instanceof DirectBuffer) {
+            return ((DirectBuffer) byteBuffer).getBaseAddress();
+        }
+        assert false : byteBuffer;
+        return null;
+    }
+
+    public boolean isAddressValid() {
+        if (byteBuffer instanceof DirectBuffer) {
+            return ((DirectBuffer) byteBuffer).isAddressValid();
+        }
+        assert false : byteBuffer;
+        return false;
+    }
+
+    public void addressValidityCheck() {
+        if (byteBuffer instanceof DirectBuffer) {
+            ((DirectBuffer) byteBuffer).addressValidityCheck();
+        } else {
+            assert false : byteBuffer;
+        }
+    }
+
+    public void free() {
+        if (byteBuffer instanceof DirectBuffer) {
+            ((DirectBuffer) byteBuffer).free();
+        } else {
+            assert false : byteBuffer;
+        }
+    }
+
+    @Override
+    public ShortBuffer asReadOnlyBuffer() {
+        ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
+                .asReadOnlyBuffer());
+        buf.limit = limit;
+        buf.position = position;
+        buf.mark = mark;
+        return buf;
+    }
+
+    @Override
+    public ShortBuffer compact() {
+        if (byteBuffer.isReadOnly()) {
+            throw new ReadOnlyBufferException();
+        }
+        byteBuffer.limit(limit << 1);
+        byteBuffer.position(position << 1);
+        byteBuffer.compact();
+        byteBuffer.clear();
+        position = limit - position;
+        limit = capacity;
+        mark = UNSET_MARK;
+        return this;
+    }
+
+    @Override
+    public ShortBuffer duplicate() {
+        ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
+                .duplicate());
+        buf.limit = limit;
+        buf.position = position;
+        buf.mark = mark;
+        return buf;
+    }
+
+    @Override
+    public short get() {
+        if (position == limit) {
+            throw new BufferUnderflowException();
+        }
+        return byteBuffer.getShort(position++ << 1);
+    }
+
+    @Override
+    public short get(int index) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        return byteBuffer.getShort(index << 1);
+    }
+
+    @Override
+    public boolean isDirect() {
+        return byteBuffer.isDirect();
+    }
+
+    @Override
+    public boolean isReadOnly() {
+        return byteBuffer.isReadOnly();
+    }
+
+    @Override
+    public ByteOrder order() {
+        return byteBuffer.order();
+    }
+
+    @Override
+    protected short[] protectedArray() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    protected int protectedArrayOffset() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    protected boolean protectedHasArray() {
+        return false;
+    }
+
+    @Override
+    public ShortBuffer put(short c) {
+        if (position == limit) {
+            throw new BufferOverflowException();
+        }
+        byteBuffer.putShort(position++ << 1, c);
+        return this;
+    }
+
+    @Override
+    public ShortBuffer put(int index, short c) {
+        if (index < 0 || index >= limit) {
+            throw new IndexOutOfBoundsException();
+        }
+        byteBuffer.putShort(index << 1, c);
+        return this;
+    }
+
+    @Override
+    public ShortBuffer slice() {
+        byteBuffer.limit(limit << 1);
+        byteBuffer.position(position << 1);
+        ShortBuffer result = new ShortToByteBufferAdapter(byteBuffer.slice());
+        byteBuffer.clear();
+        return result;
+    }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java Sat Sep 22 14:24:54 2007
@@ -195,6 +195,17 @@
         other.limit(5);
         assertTrue(buf.compareTo(other) > 0);
         assertTrue(other.compareTo(buf) < 0);
+
+        DoubleBuffer dbuffer1 = DoubleBuffer.wrap(new double[] { Double.NaN });
+        DoubleBuffer dbuffer2 = DoubleBuffer.wrap(new double[] { Double.NaN });
+        DoubleBuffer dbuffer3 = DoubleBuffer.wrap(new double[] { 42d });
+
+        assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1
+                .compareTo(dbuffer2));
+        assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3
+                .compareTo(dbuffer1));
+        assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer1
+                .compareTo(dbuffer3));
     }
 
     public void testDuplicate() {

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java Sat Sep 22 14:24:54 2007
@@ -20,6 +20,7 @@
 import java.nio.BufferOverflowException;
 import java.nio.BufferUnderflowException;
 import java.nio.ByteOrder;
+import java.nio.DoubleBuffer;
 import java.nio.FloatBuffer;
 import java.nio.InvalidMarkException;
 
@@ -184,6 +185,18 @@
         other.limit(5);
         assertTrue(buf.compareTo(other) > 0);
         assertTrue(other.compareTo(buf) < 0);
+        
+        FloatBuffer fbuffer1 = FloatBuffer.wrap(new float[] { Float.NaN });
+        FloatBuffer fbuffer2 = FloatBuffer.wrap(new float[] { Float.NaN });
+        FloatBuffer fbuffer3 = FloatBuffer.wrap(new float[] { 42f });
+
+        assertEquals("Failed equal comparison with NaN entry", 0, fbuffer1
+                .compareTo(fbuffer2));
+        assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer3
+                .compareTo(fbuffer1));
+        assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer1
+                .compareTo(fbuffer3));
+
     }
 
     public void testDuplicate() {

Modified: harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java Sat Sep 22 14:24:54 2007
@@ -108,16 +108,6 @@
     // cached Charset table
     private static HashMap<String, Charset> cachedCharsetTable = new HashMap<String, Charset>();
 
-    // cached CharsetDecoder table
-    private static HashMap<String, CharsetDecoder> cachedCharsetDecoderTable = new HashMap<String, CharsetDecoder>();
-
-    // cached CharsetEncoder table
-    private static HashMap<String, CharsetEncoder> cachedCharsetEncoderTable = new HashMap<String, CharsetEncoder>();
-
-    private CharsetEncoder cachedEncoder = null;
-
-    private CharsetDecoder cachedDecoder = null;
-
     static {
         /*
          * Create built-in charset provider even if no privilege to access
@@ -637,36 +627,19 @@
      *            the character buffer containing the content to be encoded
      * @return the result of the encoding
      */
-    synchronized public final ByteBuffer encode(CharBuffer buffer) {
-        if (cachedEncoder == null) {
-            cachedEncoder = getCachedCharsetEncoder(canonicalName);
-        }
-
-        try {
-            synchronized (cachedEncoder) {
-                return cachedEncoder.encode(buffer);
-            }
+    public final ByteBuffer encode(CharBuffer buffer) {
+        try 
+        {
+            return this.newEncoder()
+                     .onMalformedInput(CodingErrorAction.REPLACE)
+                     .onUnmappableCharacter(CodingErrorAction.REPLACE)
+                     .encode(buffer);
+                                     
         } catch (CharacterCodingException ex) {
             throw new Error(ex.getMessage(), ex);
         }
     }
 
-    /*
-     * get cached CharsetEncoder by canonical name
-     */
-    private CharsetEncoder getCachedCharsetEncoder(String name) {
-        synchronized (cachedCharsetEncoderTable) {
-            CharsetEncoder e = cachedCharsetEncoderTable.get(name);
-            if (null == e) {
-                e = this.newEncoder();
-                e.onMalformedInput(CodingErrorAction.REPLACE);
-                e.onUnmappableCharacter(CodingErrorAction.REPLACE);
-                cachedCharsetEncoderTable.put(name, e);
-            }
-            return e;
-        }
-    }
-
     /**
      * Encodes a string and outputs to a byte buffer that is to be returned.
      * <p>
@@ -695,34 +668,17 @@
      * @return a character buffer containing the output of the decoding
      */
     public final CharBuffer decode(ByteBuffer buffer) {
-        if (cachedDecoder == null) {
-            cachedDecoder = getCachedCharsetDecoder(canonicalName);
-        }
 
-        try {
-            synchronized (cachedDecoder) {
-                return cachedDecoder.decode(buffer);
-            }
-        } catch (CharacterCodingException ex) {
-            throw new Error(ex.getMessage(), ex);
-        }
-    }
-
-    /*
-     * get cached CharsetDecoder by canonical name
-     */
-    private CharsetDecoder getCachedCharsetDecoder(String name) {
-        synchronized (cachedCharsetDecoderTable) {
-            CharsetDecoder d = cachedCharsetDecoderTable.get(name);
-            if (null == d) {
-                d = this.newDecoder();
-                d.onMalformedInput(CodingErrorAction.REPLACE);
-                d.onUnmappableCharacter(CodingErrorAction.REPLACE);
-                cachedCharsetDecoderTable.put(name, d);
-            }
-            return d;
-        }
-    }
+		try {
+			return this.newDecoder()
+					.onMalformedInput(CodingErrorAction.REPLACE)
+					.onUnmappableCharacter(CodingErrorAction.REPLACE)
+					.decode(buffer);
+
+		} catch (CharacterCodingException ex) {
+			throw new Error(ex.getMessage(), ex);
+		}
+	}
 
     /*
      * -------------------------------------------------------------------



Mime
View raw message