From c97036e4c3dd29bcf32a3e72ce332e5fd8f5c325 Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Fri, 9 Feb 2001 02:56:38 +0000 Subject: [PATCH] Byte.java: Remove redundant instanceof and null checks. * java/lang/Byte.java: Remove redundant instanceof and null checks. * java/lang/Integer.java: Likewise. * java/lang/Long.java: Likewise. * java/lang/Short.java: Likewise. * java/lang/Double.java: Likewise. (doubleToRawLongBits): New method. * java/lang/Float.java: As above. (floatToRawIntBits): New method. From-SVN: r39556 --- libjava/ChangeLog | 11 +++++++++++ libjava/java/lang/Byte.java | 12 +++++------- libjava/java/lang/Double.java | 17 ++++++++--------- libjava/java/lang/Float.java | 16 ++++++++-------- libjava/java/lang/Integer.java | 15 ++++++--------- libjava/java/lang/Long.java | 17 +++++++---------- libjava/java/lang/Short.java | 13 +++++-------- 7 files changed, 50 insertions(+), 51 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 7c9ca24..981c0ed 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,14 @@ +2001-02-08 Bryce McKinlay + + * java/lang/Byte.java: Remove redundant instanceof and null checks. + * java/lang/Integer.java: Likewise. + * java/lang/Long.java: Likewise. + * java/lang/Short.java: Likewise. + * java/lang/Double.java: Likewise. + (doubleToRawLongBits): New method. + * java/lang/Float.java: As above. + (floatToRawIntBits): New method. + 2001-02-08 Tom Tromey * java/lang/Float.java (parseFloat): New method. diff --git a/libjava/java/lang/Byte.java b/libjava/java/lang/Byte.java index 78f34aa..347e252 100644 --- a/libjava/java/lang/Byte.java +++ b/libjava/java/lang/Byte.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation This file is part of libgcj. @@ -115,17 +115,15 @@ public final class Byte extends Number implements Comparable } // Added in JDK 1.2 - public int compareTo(Object o) throws ClassCastException + /** @throws ClassCastException */ + public int compareTo(Object o) { - if (o instanceof Byte) - return this.value - ((Byte) o).value; - else - throw new ClassCastException(); + return this.value - ((Byte) o).value; } public boolean equals(Object obj) { - return obj != null && (obj instanceof Byte) && ((Byte)obj).value == value; + return (obj instanceof Byte) && ((Byte)obj).value == value; } // Verified that hashCode is returns plain value (see Boolean_1 test). diff --git a/libjava/java/lang/Double.java b/libjava/java/lang/Double.java index 8de429e..a656b51 100644 --- a/libjava/java/lang/Double.java +++ b/libjava/java/lang/Double.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation This file is part of libgcj. @@ -54,9 +54,6 @@ public final class Double extends Number implements Comparable public boolean equals (Object obj) { - if (obj == null) - return false; - if (!(obj instanceof Double)) return false; @@ -108,12 +105,8 @@ public final class Double extends Number implements Comparable return toString (v, false); } - public static Double valueOf (String s) throws NullPointerException, - NumberFormatException + public static Double valueOf (String s) throws NumberFormatException { - if (s == null) - throw new NullPointerException (); - return new Double (parseDouble (s)); } @@ -146,6 +139,12 @@ public final class Double extends Number implements Comparable public static native long doubleToLongBits (double value); + public static long doubleToRawLongBits (double value) + { + // FIXME: Check that this is correct with respect to NaN values. + return doubleToLongBits (value); + } + public static native double longBitsToDouble (long bits); public int compareTo (Double d) diff --git a/libjava/java/lang/Float.java b/libjava/java/lang/Float.java index 4a1f7fe..f15b06d 100644 --- a/libjava/java/lang/Float.java +++ b/libjava/java/lang/Float.java @@ -64,9 +64,6 @@ public final class Float extends Number implements Comparable public boolean equals (Object obj) { - if (obj == null) - return false; - if (!(obj instanceof Float)) return false; @@ -115,12 +112,8 @@ public final class Float extends Number implements Comparable return Double.toString ((double) v, true); } - public static Float valueOf (String s) throws NullPointerException, - NumberFormatException + public static Float valueOf (String s) throws NumberFormatException { - if (s == null) - throw new NullPointerException (); - return new Float (Double.valueOf (s).floatValue ()); } @@ -152,6 +145,13 @@ public final class Float extends Number implements Comparable } public static native int floatToIntBits (float value); + + public static int floatToRawIntBits (float value) + { + // FIXME: Is this supposed to be different? NaN values seem to be handled + // the same in the JDK. + return floatToIntBits (value); + } public static native float intBitsToFloat (int bits); diff --git a/libjava/java/lang/Integer.java b/libjava/java/lang/Integer.java index 163c850..2cf7bb4 100644 --- a/libjava/java/lang/Integer.java +++ b/libjava/java/lang/Integer.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation This file is part of libgcj. @@ -86,11 +86,9 @@ public final class Integer extends Number implements Comparable } // Added in JDK 1.2 - public int compareTo(Object o) throws ClassCastException + /** @throws ClassCastException */ + public int compareTo(Object o) { - if (!(o instanceof Integer)) - throw new ClassCastException(); - return this.compareTo((Integer) o); } @@ -101,7 +99,7 @@ public final class Integer extends Number implements Comparable int radix = 10; final int len; - if (str == null || (len = str.length()) == 0) + if ((len = str.length()) == 0) throw new NumberFormatException(); // Negative numbers are always radix 10. @@ -140,8 +138,7 @@ public final class Integer extends Number implements Comparable public boolean equals(Object obj) { - return (obj != null && (obj instanceof Integer) - && ((Integer) obj).value == value); + return (obj instanceof Integer && ((Integer) obj).value == value); } public static Integer getInteger(String prop) @@ -181,7 +178,7 @@ public final class Integer extends Number implements Comparable { final int len; - if (str == null || (len = str.length()) == 0 || + if ((len = str.length()) == 0 || radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) throw new NumberFormatException(); diff --git a/libjava/java/lang/Long.java b/libjava/java/lang/Long.java index e6872db..cb2cec2 100644 --- a/libjava/java/lang/Long.java +++ b/libjava/java/lang/Long.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation This file is part of libgcj. @@ -86,11 +86,9 @@ public final class Long extends Number implements Comparable } // Added in JDK 1.2 - public int compareTo(Object o) throws ClassCastException + /** @throws ClassCastException */ + public int compareTo(Object o) { - if (!(o instanceof Long)) - throw new ClassCastException(); - return this.compareTo((Long) o); } @@ -102,7 +100,7 @@ public final class Long extends Number implements Comparable int radix = 10; final int len; - if (str == null || (len = str.length()) == 0) + if ((len = str.length()) == 0) throw new NumberFormatException(); // Negative numbers are always radix 10. @@ -141,8 +139,7 @@ public final class Long extends Number implements Comparable public boolean equals(Object obj) { - return (obj != null && (obj instanceof Long) - && ((Long) obj).value == value); + return (obj instanceof Long && ((Long) obj).value == value); } public static Long getLong(String prop) @@ -183,8 +180,8 @@ public final class Long extends Number implements Comparable { final int len; - if (str == null || (len = str.length()) == 0 || - radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) + if ((len = str.length()) == 0 || radix < Character.MIN_RADIX + || radix > Character.MAX_RADIX) throw new NumberFormatException(); boolean isNeg = false; diff --git a/libjava/java/lang/Short.java b/libjava/java/lang/Short.java index 6733607..66eb4fd 100644 --- a/libjava/java/lang/Short.java +++ b/libjava/java/lang/Short.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation This file is part of libgcj. @@ -115,18 +115,15 @@ public final class Short extends Number implements Comparable } // Added in JDK 1.2 - public int compareTo(Object o) throws ClassCastException + /** @throws ClassCastException */ + public int compareTo(Object o) { - if (o instanceof Short) - return this.value - ((Short) o).value; - else - throw new ClassCastException(); + return this.value - ((Short) o).value; } public boolean equals(Object obj) { - return (obj != null && (obj instanceof Short) - && ((Short) obj).value == value); + return (obj instanceof Short) && ((Short) obj).value == value; } // Verified that hashCode is returns plain value (see Short_1 test). -- 2.7.4