Commit 933522fb by Michael Koch Committed by Michael Koch

2004-05-04 Michael Koch <konqueror@gmx.de>

	* java/nio/ByteBuffer.java,
	java/nio/CharBuffer.java,
	java/nio/DoubleBuffer.java,
	java/nio/FloatBuffer.java,
	java/nio/IntBuffer.java,
	java/nio/LongBuffer.java,
	java/nio/ShortBuffer.java:
	(compareTo): Fixed bogus implementation in all buffer classes.

From-SVN: r81489
parent 6c89c39a
2004-05-04 Michael Koch <konqueror@gmx.de>
* java/nio/ByteBuffer.java,
java/nio/CharBuffer.java,
java/nio/DoubleBuffer.java,
java/nio/FloatBuffer.java,
java/nio/IntBuffer.java,
java/nio/LongBuffer.java,
java/nio/ShortBuffer.java:
(compareTo): Fixed bogus implementation in all buffer classes.
2004-05-04 Ingo Proetel <proetel@aicas.com> 2004-05-04 Ingo Proetel <proetel@aicas.com>
* java/awt/image/ColorModel.java (getRGBdefault): Default ColorModel has * java/awt/image/ColorModel.java (getRGBdefault): Default ColorModel has
......
...@@ -293,32 +293,27 @@ public abstract class ByteBuffer extends Buffer ...@@ -293,32 +293,27 @@ public abstract class ByteBuffer extends Buffer
*/ */
public int compareTo (Object obj) public int compareTo (Object obj)
{ {
ByteBuffer a = (ByteBuffer) obj; ByteBuffer other = (ByteBuffer) obj;
if (a.remaining () != remaining ()) int num = Math.min(remaining(), other.remaining());
return 1; int pos_this = position();
int pos_other = other.position();
if (! hasArray () ||
! a.hasArray ()) for (int count = 0; count < num; count++)
{
return 1;
}
int r = remaining ();
int i1 = position ();
int i2 = a.position ();
for (int i = 0; i < r; i++)
{ {
int t = (int) (get (i1) - a.get (i2)); byte a = get(pos_this++);
byte b = other.get(pos_other++);
if (t != 0)
{ if (a == b)
return (int) t; continue;
}
if (a < b)
return -1;
return 1;
} }
return 0; return remaining() - other.remaining();
} }
/** /**
......
/* CharBuffer.java -- /* CharBuffer.java --
Copyright (C) 2002, 2003 Free Software Foundation, Inc. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -310,32 +310,27 @@ public abstract class CharBuffer extends Buffer ...@@ -310,32 +310,27 @@ public abstract class CharBuffer extends Buffer
*/ */
public int compareTo (Object obj) public int compareTo (Object obj)
{ {
CharBuffer a = (CharBuffer) obj; CharBuffer other = (CharBuffer) obj;
if (a.remaining () != remaining ()) int num = Math.min(remaining(), other.remaining());
return 1; int pos_this = position();
int pos_other = other.position();
if (! hasArray () ||
! a.hasArray ()) for (int count = 0; count < num; count++)
{
return 1;
}
int r = remaining ();
int i1 = position ();
int i2 = a.position ();
for (int i = 0; i < r; i++)
{ {
int t = (int) (get (i1) - a.get (i2)); char a = get(pos_this++);
char b = other.get(pos_other++);
if (t != 0)
{ if (a == b)
return (int) t; continue;
}
if (a < b)
return -1;
return 1;
} }
return 0; return remaining() - other.remaining();
} }
/** /**
......
/* DoubleBuffer.java -- /* DoubleBuffer.java --
Copyright (C) 2002, 2003 Free Software Foundation, Inc. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -265,32 +265,27 @@ public abstract class DoubleBuffer extends Buffer ...@@ -265,32 +265,27 @@ public abstract class DoubleBuffer extends Buffer
*/ */
public int compareTo (Object obj) public int compareTo (Object obj)
{ {
DoubleBuffer a = (DoubleBuffer) obj; DoubleBuffer other = (DoubleBuffer) obj;
if (a.remaining () != remaining ()) int num = Math.min(remaining(), other.remaining());
return 1; int pos_this = position();
int pos_other = other.position();
if (! hasArray () ||
! a.hasArray ()) for (int count = 0; count < num; count++)
{
return 1;
}
int r = remaining ();
int i1 = position ();
int i2 = a.position ();
for (int i = 0; i < r; i++)
{ {
int t = (int) (get (i1) - a.get (i2)); double a = get(pos_this++);
double b = other.get(pos_other++);
if (t != 0)
{ if (a == b)
return (int) t; continue;
}
if (a < b)
return -1;
return 1;
} }
return 0; return remaining() - other.remaining();
} }
/** /**
......
/* FloatBuffer.java -- /* FloatBuffer.java --
Copyright (C) 2002, 2003 Free Software Foundation, Inc. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -265,32 +265,27 @@ public abstract class FloatBuffer extends Buffer ...@@ -265,32 +265,27 @@ public abstract class FloatBuffer extends Buffer
*/ */
public int compareTo (Object obj) public int compareTo (Object obj)
{ {
FloatBuffer a = (FloatBuffer) obj; FloatBuffer other = (FloatBuffer) obj;
if (a.remaining () != remaining ()) int num = Math.min(remaining(), other.remaining());
return 1; int pos_this = position();
int pos_other = other.position();
if (! hasArray () ||
! a.hasArray ()) for (int count = 0; count < num; count++)
{
return 1;
}
int r = remaining ();
int i1 = position ();
int i2 = a.position ();
for (int i = 0; i < r; i++)
{ {
int t = (int) (get (i1) - a.get (i2)); float a = get(pos_this++);
float b = other.get(pos_other++);
if (t != 0)
{ if (a == b)
return (int) t; continue;
}
if (a < b)
return -1;
return 1;
} }
return 0; return remaining() - other.remaining();
} }
/** /**
......
/* IntBuffer.java -- /* IntBuffer.java --
Copyright (C) 2002, 2003 Free Software Foundation, Inc. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -265,32 +265,27 @@ public abstract class IntBuffer extends Buffer ...@@ -265,32 +265,27 @@ public abstract class IntBuffer extends Buffer
*/ */
public int compareTo (Object obj) public int compareTo (Object obj)
{ {
IntBuffer a = (IntBuffer) obj; IntBuffer other = (IntBuffer) obj;
if (a.remaining () != remaining ()) int num = Math.min(remaining(), other.remaining());
return 1; int pos_this = position();
int pos_other = other.position();
if (! hasArray () ||
! a.hasArray ()) for (int count = 0; count < num; count++)
{
return 1;
}
int r = remaining ();
int i1 = position ();
int i2 = a.position ();
for (int i = 0; i < r; i++)
{ {
int t = (int) (get (i1) - a.get (i2)); int a = get(pos_this++);
int b = other.get(pos_other++);
if (t != 0)
{ if (a == b)
return (int) t; continue;
}
if (a < b)
return -1;
return 1;
} }
return 0; return remaining() - other.remaining();
} }
/** /**
......
/* LongBuffer.java -- /* LongBuffer.java --
Copyright (C) 2002, 2003 Free Software Foundation, Inc. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -265,32 +265,27 @@ public abstract class LongBuffer extends Buffer ...@@ -265,32 +265,27 @@ public abstract class LongBuffer extends Buffer
*/ */
public int compareTo (Object obj) public int compareTo (Object obj)
{ {
LongBuffer a = (LongBuffer) obj; LongBuffer other = (LongBuffer) obj;
if (a.remaining () != remaining ()) int num = Math.min(remaining(), other.remaining());
return 1; int pos_this = position();
int pos_other = other.position();
if (! hasArray () ||
! a.hasArray ()) for (int count = 0; count < num; count++)
{
return 1;
}
int r = remaining ();
int i1 = position ();
int i2 = a.position ();
for (int i = 0; i < r; i++)
{ {
int t = (int) (get (i1) - a.get (i2)); long a = get(pos_this++);
long b = other.get(pos_other++);
if (t != 0)
{ if (a == b)
return (int) t; continue;
}
if (a < b)
return -1;
return 1;
} }
return 0; return remaining() - other.remaining();
} }
/** /**
......
/* ShortBuffer.java -- /* ShortBuffer.java --
Copyright (C) 2002, 2003 Free Software Foundation, Inc. Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -265,32 +265,27 @@ public abstract class ShortBuffer extends Buffer ...@@ -265,32 +265,27 @@ public abstract class ShortBuffer extends Buffer
*/ */
public int compareTo (Object obj) public int compareTo (Object obj)
{ {
ShortBuffer a = (ShortBuffer) obj; ShortBuffer other = (ShortBuffer) obj;
if (a.remaining () != remaining ()) int num = Math.min(remaining(), other.remaining());
return 1; int pos_this = position();
int pos_other = other.position();
if (! hasArray () ||
! a.hasArray ()) for (int count = 0; count < num; count++)
{
return 1;
}
int r = remaining ();
int i1 = position ();
int i2 = a.position ();
for (int i = 0; i < r; i++)
{ {
int t = (int) (get (i1) - a.get (i2)); short a = get(pos_this++);
short b = other.get(pos_other++);
if (t != 0)
{ if (a == b)
return (int) t; continue;
}
if (a < b)
return -1;
return 1;
} }
return 0; return remaining() - other.remaining();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment