diff options
author | Michael Koch <konqueror@gmx.de> | 2004-05-04 21:31:30 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2004-05-04 21:31:30 +0000 |
commit | 933522fbc3340705007b00b7ac3734db7002a8c7 (patch) | |
tree | 7281d10d42a1f2c51d91d3923158d74d7a9511ff /libjava/java/nio | |
parent | 6c89c39a4880297da031f52ade9b839c6e73ef48 (diff) | |
download | gcc-933522fbc3340705007b00b7ac3734db7002a8c7.zip gcc-933522fbc3340705007b00b7ac3734db7002a8c7.tar.gz gcc-933522fbc3340705007b00b7ac3734db7002a8c7.tar.bz2 |
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
Diffstat (limited to 'libjava/java/nio')
-rw-r--r-- | libjava/java/nio/ByteBuffer.java | 41 | ||||
-rw-r--r-- | libjava/java/nio/CharBuffer.java | 43 | ||||
-rw-r--r-- | libjava/java/nio/DoubleBuffer.java | 43 | ||||
-rw-r--r-- | libjava/java/nio/FloatBuffer.java | 43 | ||||
-rw-r--r-- | libjava/java/nio/IntBuffer.java | 43 | ||||
-rw-r--r-- | libjava/java/nio/LongBuffer.java | 43 | ||||
-rw-r--r-- | libjava/java/nio/ShortBuffer.java | 43 |
7 files changed, 132 insertions, 167 deletions
diff --git a/libjava/java/nio/ByteBuffer.java b/libjava/java/nio/ByteBuffer.java index 276b2db..8b43da5 100644 --- a/libjava/java/nio/ByteBuffer.java +++ b/libjava/java/nio/ByteBuffer.java @@ -293,32 +293,27 @@ public abstract class ByteBuffer extends Buffer */ public int compareTo (Object obj) { - ByteBuffer a = (ByteBuffer) obj; + ByteBuffer other = (ByteBuffer) obj; - if (a.remaining () != remaining ()) - return 1; - - if (! hasArray () || - ! a.hasArray ()) - { - return 1; - } - - int r = remaining (); - int i1 = position (); - int i2 = a.position (); - - for (int i = 0; i < r; i++) + int num = Math.min(remaining(), other.remaining()); + int pos_this = position(); + int pos_other = other.position(); + + for (int count = 0; count < num; count++) { - int t = (int) (get (i1) - a.get (i2)); - - if (t != 0) - { - return (int) t; - } + byte a = get(pos_this++); + byte b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** diff --git a/libjava/java/nio/CharBuffer.java b/libjava/java/nio/CharBuffer.java index 3d488ba..416ca83 100644 --- a/libjava/java/nio/CharBuffer.java +++ b/libjava/java/nio/CharBuffer.java @@ -1,5 +1,5 @@ /* 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. @@ -310,32 +310,27 @@ public abstract class CharBuffer extends Buffer */ public int compareTo (Object obj) { - CharBuffer a = (CharBuffer) obj; + CharBuffer other = (CharBuffer) obj; - if (a.remaining () != remaining ()) - return 1; - - if (! hasArray () || - ! a.hasArray ()) - { - return 1; - } - - int r = remaining (); - int i1 = position (); - int i2 = a.position (); - - for (int i = 0; i < r; i++) + int num = Math.min(remaining(), other.remaining()); + int pos_this = position(); + int pos_other = other.position(); + + for (int count = 0; count < num; count++) { - int t = (int) (get (i1) - a.get (i2)); - - if (t != 0) - { - return (int) t; - } + char a = get(pos_this++); + char b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** diff --git a/libjava/java/nio/DoubleBuffer.java b/libjava/java/nio/DoubleBuffer.java index d669c21..1ad8bae 100644 --- a/libjava/java/nio/DoubleBuffer.java +++ b/libjava/java/nio/DoubleBuffer.java @@ -1,5 +1,5 @@ /* 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. @@ -265,32 +265,27 @@ public abstract class DoubleBuffer extends Buffer */ public int compareTo (Object obj) { - DoubleBuffer a = (DoubleBuffer) obj; + DoubleBuffer other = (DoubleBuffer) obj; - if (a.remaining () != remaining ()) - return 1; - - if (! hasArray () || - ! a.hasArray ()) - { - return 1; - } - - int r = remaining (); - int i1 = position (); - int i2 = a.position (); - - for (int i = 0; i < r; i++) + int num = Math.min(remaining(), other.remaining()); + int pos_this = position(); + int pos_other = other.position(); + + for (int count = 0; count < num; count++) { - int t = (int) (get (i1) - a.get (i2)); - - if (t != 0) - { - return (int) t; - } + double a = get(pos_this++); + double b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** diff --git a/libjava/java/nio/FloatBuffer.java b/libjava/java/nio/FloatBuffer.java index 0c7b04d..ab87b7f 100644 --- a/libjava/java/nio/FloatBuffer.java +++ b/libjava/java/nio/FloatBuffer.java @@ -1,5 +1,5 @@ /* 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. @@ -265,32 +265,27 @@ public abstract class FloatBuffer extends Buffer */ public int compareTo (Object obj) { - FloatBuffer a = (FloatBuffer) obj; + FloatBuffer other = (FloatBuffer) obj; - if (a.remaining () != remaining ()) - return 1; - - if (! hasArray () || - ! a.hasArray ()) - { - return 1; - } - - int r = remaining (); - int i1 = position (); - int i2 = a.position (); - - for (int i = 0; i < r; i++) + int num = Math.min(remaining(), other.remaining()); + int pos_this = position(); + int pos_other = other.position(); + + for (int count = 0; count < num; count++) { - int t = (int) (get (i1) - a.get (i2)); - - if (t != 0) - { - return (int) t; - } + float a = get(pos_this++); + float b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** diff --git a/libjava/java/nio/IntBuffer.java b/libjava/java/nio/IntBuffer.java index 469a344..52d822a 100644 --- a/libjava/java/nio/IntBuffer.java +++ b/libjava/java/nio/IntBuffer.java @@ -1,5 +1,5 @@ /* 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. @@ -265,32 +265,27 @@ public abstract class IntBuffer extends Buffer */ public int compareTo (Object obj) { - IntBuffer a = (IntBuffer) obj; + IntBuffer other = (IntBuffer) obj; - if (a.remaining () != remaining ()) - return 1; - - if (! hasArray () || - ! a.hasArray ()) - { - return 1; - } - - int r = remaining (); - int i1 = position (); - int i2 = a.position (); - - for (int i = 0; i < r; i++) + int num = Math.min(remaining(), other.remaining()); + int pos_this = position(); + int pos_other = other.position(); + + for (int count = 0; count < num; count++) { - int t = (int) (get (i1) - a.get (i2)); - - if (t != 0) - { - return (int) t; - } + int a = get(pos_this++); + int b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** diff --git a/libjava/java/nio/LongBuffer.java b/libjava/java/nio/LongBuffer.java index 712e0b3..1b420eb 100644 --- a/libjava/java/nio/LongBuffer.java +++ b/libjava/java/nio/LongBuffer.java @@ -1,5 +1,5 @@ /* 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. @@ -265,32 +265,27 @@ public abstract class LongBuffer extends Buffer */ public int compareTo (Object obj) { - LongBuffer a = (LongBuffer) obj; + LongBuffer other = (LongBuffer) obj; - if (a.remaining () != remaining ()) - return 1; - - if (! hasArray () || - ! a.hasArray ()) - { - return 1; - } - - int r = remaining (); - int i1 = position (); - int i2 = a.position (); - - for (int i = 0; i < r; i++) + int num = Math.min(remaining(), other.remaining()); + int pos_this = position(); + int pos_other = other.position(); + + for (int count = 0; count < num; count++) { - int t = (int) (get (i1) - a.get (i2)); - - if (t != 0) - { - return (int) t; - } + long a = get(pos_this++); + long b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** diff --git a/libjava/java/nio/ShortBuffer.java b/libjava/java/nio/ShortBuffer.java index 61097d0..9f54276 100644 --- a/libjava/java/nio/ShortBuffer.java +++ b/libjava/java/nio/ShortBuffer.java @@ -1,5 +1,5 @@ /* 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. @@ -265,32 +265,27 @@ public abstract class ShortBuffer extends Buffer */ public int compareTo (Object obj) { - ShortBuffer a = (ShortBuffer) obj; + ShortBuffer other = (ShortBuffer) obj; - if (a.remaining () != remaining ()) - return 1; - - if (! hasArray () || - ! a.hasArray ()) - { - return 1; - } - - int r = remaining (); - int i1 = position (); - int i2 = a.position (); - - for (int i = 0; i < r; i++) + int num = Math.min(remaining(), other.remaining()); + int pos_this = position(); + int pos_other = other.position(); + + for (int count = 0; count < num; count++) { - int t = (int) (get (i1) - a.get (i2)); - - if (t != 0) - { - return (int) t; - } + short a = get(pos_this++); + short b = other.get(pos_other++); + + if (a == b) + continue; + + if (a < b) + return -1; + + return 1; } - - return 0; + + return remaining() - other.remaining(); } /** |