Patch: merge several Number classes with Classpath

Tom Tromey tromey@redhat.com
Mon Jul 23 12:57:00 GMT 2001


I'm checking this in on the trunk.

This merges Number and several of its subclasses with Classpath.  To
make this work I had to add java.lang.VMClassLoader -- this is
something required by Classpath.  It is unfortunate that it has nearly
the same name as our VMClassLoader.

This built on x86 and there were no test suite regressions (including
Mauve).

2001-07-23  Tom Tromey  <tromey@redhat.com>

	* gcj/javaprims.h: Rebuilt class list.
	* Makefile.in: Rebuilt.
	* Makefile.am (core_java_source_files): Added VMClassLoader.
	* java/lang/VMClassLoader.java: New file.
	* java/lang/Boolean.java: Merged with Classpath.
	* java/lang/Byte.java: Merged with Classpath.
	* java/lang/Integer.java: Merged with Classpath.
	* java/lang/Long.java: Merged with Classpath.
	* java/lang/Number.java: Merged with Classpath.
	* java/lang/Short.java: Merged with Classpath.

Tom

Index: java/lang/VMClassLoader.java
===================================================================
RCS file: VMClassLoader.java
diff -N VMClassLoader.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ java/lang/VMClassLoader.java Mon Jul 23 12:54:58 2001
@@ -0,0 +1,85 @@
+/*
+ * java.lang.ClassLoader: part of the Java Class Libraries project.
+ * Copyright (C) 1998, 2001 Free Software Foundation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ */
+
+package java.lang;
+
+/**
+ * java.lang.VMClassLoader is a package-private helper for VMs to implement
+ * on behalf of java.lang.ClassLoader.
+ *
+ * @author John Keiser
+ * @version 1.1.0, Sep 22 1998
+ * @since CP1.1
+ */
+
+class VMClassLoader {
+
+    /** 
+     * Helper to define a class using a string of bytes.
+     * 
+     * @param name the name to give the class.  null if unknown.
+     * @param data the data representing the classfile, in classfile format.
+     * @param offset the offset into the data where the classfile starts.
+     * @param len the length of the classfile data in the array.
+     * @return the class that was defined.
+     * @exception ClassFormatError if the byte array is not in proper classfile format.
+     */
+  // Not yet needed for libgcj.
+//      final static native Class defineClass(ClassLoader cl, String name, 
+//  	     byte[] data, int offset, int len) throws ClassFormatError;
+    
+    /** 
+     * Helper to resolve all references to other classes from this class.
+     * @param c the class to resolve.
+     */
+  // Not yet needed for libgcj.
+  //    final static native void resolveClass(Class c);
+
+    /** 
+     * Helper for java.lang.Integer, Byte, etc. to get the TYPE class
+     * at initialization time.  If there are multiple classloaders, this
+     * method may be called once per ClassLoader per type.
+     *
+     * @param type name of the primitive type; i.e. "int", "byte", etc.
+     * @return a "bogus" class representing the primitive type.
+     */
+  static final Class getPrimitiveClass(String type)
+  {
+    if ("int".equals (type))
+      return int.class;
+    else if ("long".equals (type))
+      return int.class;
+    else if ("boolean".equals (type))
+      return int.class;
+    else if ("short".equals (type))
+      return int.class;
+    else if ("char".equals (type))
+      return int.class;
+    else if ("byte".equals (type))
+      return int.class;
+    else if ("float".equals (type))
+      return int.class;
+    else if ("double".equals (type))
+      return int.class;
+    else if ("void".equals (type))
+      return int.class;
+    return null;
+  }
+}
Index: java/lang/Boolean.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Boolean.java,v
retrieving revision 1.6
diff -u -r1.6 Boolean.java
--- java/lang/Boolean.java 2000/09/08 19:37:08 1.6
+++ java/lang/Boolean.java 2001/07/23 19:54:58
@@ -1,100 +1,177 @@
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Boolean.java -- object wrapper for boolean
+   Copyright (C) 1998, 2001 Free Software Foundation, Inc.
 
-   This file is part of libgcj.
+This file is part of GNU Classpath.
 
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
  
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
 package java.lang;
 
 import java.io.Serializable;
- 
+
 /**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date September 3, 1998.  
- */
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * plus online API docs for JDK 1.2 beta from http://www.javasoft.com .
- * Status:  Believed complete and correct.
- */
- 
-public final class Boolean extends Object implements Serializable
+ * Instances of class <code>Boolean</code> represent primitive 
+ * <code>boolean</code> values.
+ *
+ * @author Paul Fisher
+ * @since JDK1.0
+ */ 
+public final class Boolean implements Serializable
 {
-  public static final Boolean FALSE = new Boolean(false);
-  public static final Boolean TRUE = new Boolean(true);
+    static final long serialVersionUID = -3665804199014368530L;
+    
+    /**
+     * This field is a <code>Boolean</code> object representing the
+     * primitive value <code>true</code>. This instance is returned
+     * by the static <code>valueOf()</code> methods if they return
+     * a <code>Boolean</code> representing <code>true</code>.
+     */
+    public static final Boolean TRUE  = new Boolean(true);
+    
+    /**
+     * This field is a <code>Boolean</code> object representing the 
+     * primitive value <code>false</code>. This instance is returned
+     * by the static <code>valueOf()</code> methods if they return
+     * a <code>Boolean</code> representing <code>false</code>.
+     */
+     public static final Boolean FALSE = new Boolean(false);
 
-  // This initialization is seemingly circular, but it is accepted
-  // by javac, and is handled specially by gcc.
-  public static final Class TYPE = boolean.class;
-
-  /* The boolean value of the instance. */
-  private boolean value;
-
-  private static final long serialVersionUID = -3665804199014368530L;
-
-  public Boolean(boolean boolVal)
-  {
-    value = boolVal;
-  }
-
-  public Boolean(String strVal)
-  {
-    value = (strVal == null ? false : strVal.equalsIgnoreCase("true"));
-  }
-
-  public boolean booleanValue()
-  {
-    return value;
-  }
-
-  public boolean equals(Object obj)
-  {
-    /* Don't need to compare obj to null as instanceof will do this. */
-    if (obj instanceof Boolean)
-      return value == ((Boolean) obj).value;
-    return false;
-  }
-
-  public static boolean getBoolean(String property)
-  {
-    /* TBD: If a security manager exists and it doesn't permit accessing
-     * the property, it will throw an exception.  Should we catch it?
-     */
-    try
-      {
-	String val = System.getProperty(property);
-	return val == null ? false : val.equalsIgnoreCase("true");
-      }
-    catch (SecurityException e)
-      {
-        return false;
-      }
-  }
-
-  public int hashCode()
-  {
-    /* These values are from the Java Lang. Spec. (Sec 20.4.7).
-     * TBD: They could be made private static final fields but they're only
-     * used here (and shouldn't be used anywhere else), though it might be
-     * useful to grep on something like JAVA_HASH_* values for us as
-     * developers.
-     */
-    return value ? 1231 : 1237;
-  }
-
-  public String toString()
-  {
-    return value ? "true" : "false";
-  }
-
-  public static Boolean valueOf(String str)
-  {
-    if (str == null)
-      return FALSE;
-    else
-      /* This returns a Boolean (big B), not a boolean (little b). */
-      return str.equalsIgnoreCase("true") ? TRUE : FALSE;
-  }
+    /**
+     * The primitive type <code>boolean</code> is represented by this 
+     * <code>Class</code> object.
+     */
+    public static final Class TYPE = VMClassLoader.getPrimitiveClass("boolean");
+    
+    /**
+     * The immutable value of this Boolean.
+     */
+    private final boolean value;
+    
+    /**
+     * Create a <code>Boolean</code> object representing the value of the 
+     * argument <code>value</code>. In general the use of the static
+     * method <code>valueof(boolean)</code> is more efficient since it will
+     * not create a new object.
+     *
+     * @param value the primitive value of this <code>Boolean</code>
+     */    
+    public Boolean(boolean value) {
+	this.value = value;
+    }
+    
+    /**
+     * Creates a <code>Boolean</code> object representing the primitive 
+     * <code>true</code> if and only if <code>s</code> matches 
+     * the string "true" ignoring case, otherwise the object will represent 
+     * the primitive <code>false</code>. In general the use of the static
+     * method <code>valueof(String)</code> is more efficient since it will
+     * not create a new object.
+     *
+     * @param s the <code>String</code> representation of <code>true</code>
+     *   or false
+     */
+    public Boolean(String s) {
+	value = "true".equalsIgnoreCase(s);
+    }
+
+    /**
+     * Return the primitive <code>boolean</code> value of this 
+     * <code>Boolean</code> object.
+     */
+    public boolean booleanValue() {
+	return value;
+    }
+
+    /**
+     * Returns the Boolean <code>TRUE</code> if the given boolean is
+     * <code>true</code>, otherwise it will return the Boolean
+     * <code>FALSE</code>.
+     *
+     * @since 1.4
+     */
+    public static Boolean valueOf(boolean b) {
+    	return b ? TRUE : FALSE;
+    }
+
+    /**
+     * Returns the Boolean <code>TRUE</code> if and only if the given
+     * String is equal, ignoring case, to the the String "true", otherwise
+     * it will return the Boolean <code>FALSE</code>.
+     */
+    public static Boolean valueOf(String s) {
+    	return "true".equalsIgnoreCase(s) ? TRUE : FALSE;
+    }
+
+    /**
+     * Returns the integer <code>1231</code> if this object represents 
+     * the primitive <code>true</code> and the integer <code>1237</code>
+     * otherwise.
+     */    
+    public int hashCode() {
+	return (value) ? 1231 : 1237;
+    }
+
+    /**
+     * If the <code>obj</code> is an instance of <code>Boolean</code> and
+     * has the same primitive value as this object then <code>true</code>
+     * is returned.  In all other cases, including if the <code>obj</code>
+     * is <code>null</code>, <code>false</code> is returned.
+     *
+     * @param obj possibly an instance of any <code>Class</code>
+     * @return <code>false</code> is <code>obj</code> is an instance of
+     *   <code>Boolean</code> and has the same primitive value as this 
+     *   object.
+     */    
+    public boolean equals(Object obj) {
+	return (obj instanceof Boolean && value == ((Boolean)obj).value);
+    }
+
+    /**
+     * If the value of the system property <code>name</code> matches
+     * "true" ignoring case then the function returns <code>true</code>.
+     */
+    public static boolean getBoolean(String name) {
+	String val = System.getProperty(name);
+	return ("true".equalsIgnoreCase(val));
+    }
+    
+    /**
+     * Returns "true" if the value of the give boolean is <code>true</code> and
+     * returns "false" if the value of the given boolean is <code>false</code>.
+     *
+     * @since 1.4
+     */
+    public static String toString(boolean b)
+    {
+	return b ? "true" : "false";
+    }
+
+    /**
+     * Returns "true" if the value of this object is <code>true</code> and
+     * returns "false" if the value of this object is <code>false</code>.
+     */
+    public String toString()
+    {
+	return (value) ? "true" : "false";
+    }   
 }
Index: java/lang/Byte.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Byte.java,v
retrieving revision 1.5
diff -u -r1.5 Byte.java
--- java/lang/Byte.java 2001/02/09 02:56:38 1.5
+++ java/lang/Byte.java 2001/07/23 19:54:58
@@ -1,88 +1,193 @@
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Byte.java -- object wrapper for byte
+   Copyright (C) 1998, 2001 Free Software Foundation, Inc.
 
-   This file is part of libgcj.
+This file is part of GNU Classpath.
 
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
 
+
 package java.lang;
 
 /**
- * @author Per Bothner <bothner@cygnus.com>
- * @date April 17, 1998.  
- */
-/* Written using "Java Class Libraries", 2nd edition, plus online
- * API docs for JDK 1.2 beta from http://www.javasoft.com .
- * Status:  Believed complete and correct.
- *	    Includes JDK 1.2 methods.
+ * Instances of class <code>Byte</code> represent primitive <code>byte</code>
+ * values.
+ *
+ * Additionally, this class provides various helper functions and variables
+ * useful to bytes.
+ *
+ * @author Paul Fisher
+ * @author John Keiser
+ * @author Per Bothner
+ * @since JDK 1.0
  */
-
-public final class Byte extends Number implements Comparable
+public final class Byte extends Number implements Comparable 
 {
-  byte value;
-
-  public final static byte MIN_VALUE = -128;
-  public final static byte MAX_VALUE = 127;
+  static final long serialVersionUID = -7183698231559129828L;
 
-  // This initialization is seemingly circular, but it is accepted
-  // by javac, and is handled specially by gcc.
-  public static final Class TYPE = byte.class;
-
-  private static final long serialVersionUID = -7183698231559129828L;
-
-  public Byte(byte value)
+  /**
+   * The minimum value a <code>byte</code> can represent is -128.
+   */
+  public static final byte MIN_VALUE = -128;
+
+  /**
+   * The maximum value a <code>byte</code> can represent is 127.
+   */
+  public static final byte MAX_VALUE = 127;
+
+  /**
+   * The primitive type <code>byte</code> is represented by this 
+   * <code>Class</code> object.
+   */
+  public static final Class TYPE = VMClassLoader.getPrimitiveClass("byte");
+
+  /**
+   * The immutable value of this Byte.
+   */
+  private final byte value;
+
+  /**
+   * Create a <code>Byte</code> object representing the value of the 
+   * <code>byte</code> argument.
+   *
+   * @param value the value to use
+   */     
+  public Byte(byte value) 
   {
     this.value = value;
   }
-
-  public Byte(String str) 
-    throws NumberFormatException
-  {
-    this.value = parseByte(str, 10);
-  }
-
-  public byte byteValue()
-  {
-    return value;
-  }
 
-  public short shortValue()
-  {
-    return value;
-  }
-
-  public int intValue()
-  {
-    return value;
-  }
-
-  public long longValue ()
+  /**
+   * Create a <code>Byte</code> object representing the value specified 
+   * by the <code>String</code> argument.
+   *
+   * @param s the string to convert.
+   */
+  public Byte(String s) throws NumberFormatException 
+  {
+    value = parseByte(s, 10);
+  }
+
+  /**
+   * Return a hashcode representing this Object.
+   *
+   * <code>Byte</code>'s hash code is calculated by simply returning its
+   * value.
+   *
+   * @return this Object's hash code.
+   */
+  public int hashCode() 
   {
     return value;
   }
-
-  public float floatValue ()
-  {
-    return (float) value;
-  }
-
-  public double doubleValue ()
-  {
-    return (double) value;
-  }
-
-  public static Byte decode(String str)
-    throws NumberFormatException
-  {
-    int i = (Integer.decode(str)).intValue();
-    if (i < MIN_VALUE || i > MAX_VALUE)
-      throw new NumberFormatException();
-    return new Byte((byte) i);
-  }
 
-  public static byte parseByte(String str, int radix)
-    throws NumberFormatException
+  /**
+   * Returns <code>true</code> if <code>obj</code> is an instance of
+   * <code>Byte</code> and represents the same byte value.
+   * @return whether these Objects are semantically equal.
+   */    
+  public boolean equals(Object obj) 
+  {
+    return ((obj instanceof Byte) && (value == ((Byte)obj).byteValue()));
+  }
+
+  /**
+   * Converts the <code>byte</code> to a <code>String</code> and assumes
+   * a radix of 10.
+   * @param i the <code>byte</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */    
+  public static String toString(byte i) 
+  {
+    return Integer.toString ((int) i);
+  }
+
+  /**
+   * Converts the <code>Byte</code> value to a <code>String</code> and
+   * assumes a radix of 10.
+   * @return the <code>String</code> representation of this <code>Byte</code>.
+   */    
+  public String toString() 
+  {
+    return Integer.toString ((int) value);
+  }
+    
+  /**
+   * Creates a new <code>Byte</code> object using the <code>String</code>,
+   * assuming a radix of 10.
+   * @param s the <code>String</code> to convert.
+   * @return the new <code>Byte</code>.
+   * @see #Byte(java.lang.String)
+   * @see #parseByte(java.lang.String)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>byte</code>.
+   */
+  public static Byte valueOf(String s) throws NumberFormatException 
+  {
+    return new Byte(parseByte(s));
+  }
+
+  /**
+   * Creates a new <code>Byte</code> object using the <code>String</code>
+   * and specified radix (base).
+   * @param s the <code>String</code> to convert.
+   * @param radix the radix (base) to convert with.
+   * @return the new <code>Byte</code>.
+   * @see #parseByte(java.lang.String,int)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>byte</code>.
+   */
+  public static Byte valueOf(String s, int radix) 
+    throws NumberFormatException 
+  {
+    return new Byte(parseByte(s, radix));
+  }
+
+  /**
+   * Converts the specified <code>String</code> into a <code>byte</code>.
+   * This function assumes a radix of 10.
+   *
+   * @param s the <code>String</code> to convert
+   * @return the <code>byte</code> value of the <code>String</code>
+   *         argument.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>byte</code>.
+   */
+  public static byte parseByte(String s) throws NumberFormatException 
+  {
+    return parseByte(s, 10);
+  }
+
+  /**
+   * Converts the specified <code>String</code> into a <code>byte</code>
+   * using the specified radix (base).
+   *
+   * @param str the <code>String</code> to convert
+   * @param radix the radix (base) to use in the conversion
+   * @return the <code>String</code> argument converted to </code>byte</code>.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>byte</code>.    
+   */
+  public static byte parseByte(String str, int radix) 
+    throws NumberFormatException 
   {
     int i = Integer.parseInt(str, radix);
     if (i < MIN_VALUE || i > MAX_VALUE)
@@ -90,55 +195,109 @@
     return (byte) i;
   }
 
-  public static byte parseByte(String str)
-    throws NumberFormatException
+  /**
+   * Convert the specified <code>String</code> into a <code>Byte</code>.
+   * The <code>String</code> may represent decimal, hexadecimal, or 
+   * octal numbers.
+   *
+   * The <code>String</code> argument is interpreted based on the leading
+   * characters.  Depending on what the String begins with, the base will be
+   * interpreted differently:
+   *
+   * <table>
+   * <tr><th>Leading<br>Characters</th><th>Base</th></tr>
+   * <tr><td>#</td><td>16</td></tr>
+   * <tr><td>0x</td><td>16</td></tr>
+   * <tr><td>0X</td><td>16</td></tr>
+   * <tr><td>0</td><td>8</td></tr>
+   * <tr><td>Anything<br>Else</td><td>10</td></tr>
+   * </table>
+   *
+   * @param str the <code>String</code> to interpret.
+   * @return the value of the String as a <code>Byte</code>.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>byte</code>.    
+   */
+  public static Byte decode(String str) throws NumberFormatException 
   {
-    return parseByte(str, 10);
-  }
-
-  public static Byte valueOf(String str, int radix)
-    throws NumberFormatException
-  {
-    return new Byte(parseByte(str, radix));
+    int i = (Integer.decode(str)).intValue();
+    if (i < MIN_VALUE || i > MAX_VALUE)
+      throw new NumberFormatException();
+    return new Byte((byte) i);
   }
-
-  public static Byte valueOf(String str)
-    throws NumberFormatException
+    
+  /** Return the value of this <code>Byte</code> as an <code>short</code>.
+   ** @return the value of this <code>Byte</code> as an <code>short</code>.
+   **/
+  public byte byteValue()
   {
-    return valueOf(str, 10);
+    return value;
   }
 
-  // Added in JDK 1.2
-  public int compareTo(Byte anotherByte)
+  /** Return the value of this <code>Byte</code> as an <code>short</code>.
+   ** @return the value of this <code>Byte</code> as an <code>short</code>.
+   **/
+  public short shortValue()
   {
-    return this.value - anotherByte.value;
+    return value;
   }
 
-  // Added in JDK 1.2
-  /** @throws ClassCastException */
-  public int compareTo(Object o)
+  /** Return the value of this <code>Byte</code> as an <code>int</code>.
+   ** @return the value of this <code>Byte</code> as an <code>int</code>.
+   **/
+  public int intValue()
   {
-    return this.value - ((Byte) o).value;
+    return value;
   }
 
-  public boolean equals(Object obj)
+  /** Return the value of this <code>Byte</code> as a <code>long</code>.
+   ** @return the value of this <code>Byte</code> as a <code>long</code>.
+   **/
+  public long longValue()
   {
-    return (obj instanceof Byte) && ((Byte)obj).value == value;
+    return value;
   }
 
-  // Verified that hashCode is returns plain value (see Boolean_1 test).
-  public int hashCode()
+  /** Return the value of this <code>Byte</code> as a <code>float</code>.
+   ** @return the value of this <code>Byte</code> as a <code>float</code>.
+   **/
+  public float floatValue()
   {
     return value;
   }
 
-  public String toString()
+  /** Return the value of this <code>Byte</code> as a <code>double</code>.
+   ** @return the value of this <code>Byte</code> as a <code>double</code>.
+   **/
+  public double doubleValue()
   {
-    return Integer.toString((int) value);
+    return value;
   }
-
-  public static String toString(byte value)
+    
+  /**
+   * Compare two Bytes numerically by comparing their
+   * <code>byte</code> values.
+   * @return a positive value if this <code>Byte</code> is greater
+   * in value than the argument <code>Byte</code>; a negative value
+   * if this <code>Byte</code> is smaller in value than the argument
+   * <code>Byte</code>; and <code>0</code>, zero, if this
+   * <code>Byte</code> is equal in value to the argument
+   * <code>Byte</code>.  
+   */
+  public int compareTo(Byte b)
+  {
+    return (int)(value - b.byteValue());
+  }
+    
+  /**
+   * Behaves like <code>compareTo(java.lang.Byte)</code> unless the Object
+   * is not a <code>Byte</code>.  Then it throws a 
+   * <code>ClassCastException</code>.
+   * @exception ClassCastException if the argument is not a
+   * <code>Byte</code>.  
+   */
+  public int compareTo(Object o)
   {
-    return Integer.toString((int) value);
+    return compareTo((Byte)o);
   }
 }
Index: java/lang/Integer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Integer.java,v
retrieving revision 1.8
diff -u -r1.8 Integer.java
--- java/lang/Integer.java 2001/05/22 04:38:35 1.8
+++ java/lang/Integer.java 2001/07/23 19:54:58
@@ -1,182 +1,368 @@
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* java.lang.Integer
+   Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
 
-   This file is part of libgcj.
+This file is part of GNU Classpath.
 
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
  
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
 package java.lang;
 
 /**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date September 11, 1998.  
+ * Instances of class <code>Integer</code> represent primitive
+ * <code>int</code> values.
+ *
+ * Additionally, this class provides various helper functions and variables
+ * related to ints.
+ *
+ * @author Paul Fisher
+ * @author John Keiser
+ * @author Warren Levy
+ * @since JDK 1.0
  */
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * plus online API docs for JDK 1.2 beta from http://www.javasoft.com .
- * Status:  Believed complete and correct.
- */
- 
 public final class Integer extends Number implements Comparable
 {
-  public static final int MAX_VALUE = 0x7FFFFFFF;
-  public static final int MIN_VALUE = 0x80000000;
-
-  // This initialization is seemingly circular, but it is accepted
-  // by javac, and is handled specially by gcc.
-  public static final Class TYPE = int.class;
-
-  /* The int value of the instance. */
-  private int value;
-
+  // compatible with JDK 1.0.2+
   private static final long serialVersionUID = 1360826667806852920L;
 
-  public Integer(int val)
-  {
-    value = val;
-  }
-
-  public Integer(String str) throws NumberFormatException
-  {
-    value = parseInt(str, 10);
-  }
-
-  public byte byteValue()
-  {
-    return (byte) value;
-  }
-
-  public double doubleValue()
-  {
-    return (double) value;
-  }
-
-  public float floatValue()
-  {
-    return (float) value;
-  }
+  /**
+   * The minimum value an <code>int</code> can represent is -2147483648.
+   */
+  public static final int MIN_VALUE = 0x80000000;
 
-  public int intValue()
+  /**
+   * The maximum value an <code>int</code> can represent is 2147483647.
+   */
+  public static final int MAX_VALUE = 0x7fffffff;
+
+  /**
+   * The primitive type <code>int</code> is represented by this 
+   * <code>Class</code> object.
+   */
+  public static final Class TYPE = VMClassLoader.getPrimitiveClass ("int");
+
+  /**
+   * The immutable value of this Integer.
+   */
+  private final int value;
+
+  /**
+   * Create an <code>Integer</code> object representing the value of the 
+   * <code>int</code> argument.
+   *
+   * @param value the value to use
+   */
+  public Integer(int value)
+  {
+    this.value = value;
+  }
+
+  /**
+   * Create an <code>Integer</code> object representing the value of the 
+   * argument after conversion to an <code>int</code>.
+   *
+   * @param s the string to convert.
+   */
+  public Integer(String s) throws NumberFormatException
+  {
+    value = parseInt(s, 10);
+  }
+
+  /**
+   * Return a hashcode representing this Object.
+   *
+   * <code>Integer</code>'s hash code is calculated by simply returning its
+   * value.
+   *
+   * @return this Object's hash code.
+   */
+  public int hashCode()
   {
     return value;
   }
 
-  public long longValue()
+  /**
+   * If the <code>Object</code> is not <code>null</code>, is an
+   * <code>instanceof</code> <code>Integer</code>, and represents
+   * the same primitive <code>int</code> value return 
+   * <code>true</code>.  Otherwise <code>false</code> is returned.
+   */
+  public boolean equals(Object obj)
   {
-    return value;
+    return obj instanceof Integer && value == ((Integer)obj).value;
   }
 
-  public short shortValue()
+  /**
+   * Get the specified system property as an <code>Integer</code>.
+   *
+   * The <code>decode()</code> method will be used to interpret the value of
+   * the property.
+   * @param nm the name of the system property
+   * @return the system property as an <code>Integer</code>, or
+   *         <code>null</code> if the property is not found or cannot be
+   *         decoded as an <code>Integer</code>.
+   * @see java.lang.System#getProperty(java.lang.String)
+   * @see #decode(int)
+   */
+  public static Integer getInteger(String nm)
+  {
+    return getInteger(nm, null);
+  }
+
+  /**
+   * Get the specified system property as an <code>Integer</code>, or use a
+   * default <code>int</code> value if the property is not found or is not
+   * decodable.
+   * 
+   * The <code>decode()</code> method will be used to interpret the value of
+   * the property.
+   *
+   * @param nm the name of the system property
+   * @param val the default value to use if the property is not found or not
+   *        a number.
+   * @return the system property as an <code>Integer</code>, or the default
+   *         value if the property is not found or cannot be decoded as an
+   *         <code>Integer</code>.
+   * @see java.lang.System#getProperty(java.lang.String)
+   * @see #decode(int)
+   * @see #getInteger(java.lang.String,java.lang.Integer)
+   */
+  public static Integer getInteger(String nm, int val)
+  {
+    Integer result = getInteger(nm, null);
+    return (result == null) ? new Integer(val) : result;
+  }
+
+  /**
+   * Get the specified system property as an <code>Integer</code>, or use a
+   * default <code>Integer</code> value if the property is not found or is
+   * not decodable.
+   * 
+   * The <code>decode()</code> method will be used to interpret the value of
+   * the property.
+   *
+   * @param nm the name of the system property
+   * @param val the default value to use if the property is not found or not
+   *        a number.
+   * @return the system property as an <code>Integer</code>, or the default
+   *         value if the property is not found or cannot be decoded as an
+   *         <code>Integer</code>.
+   * @see java.lang.System#getProperty(java.lang.String)
+   * @see #decode(int)
+   * @see #getInteger(java.lang.String,int)
+   */
+  public static Integer getInteger(String nm, Integer def)
   {
-    return (short) value;
+    String val = System.getProperty(nm);
+    if (val == null) return def;
+    try
+      {
+      return decode(nm);
+      }
+    catch (NumberFormatException e)
+      {
+	return def;
+      }
   }
 
-  // Added in JDK 1.2
-  public int compareTo(Integer anotherInteger)
+  private static String toUnsignedString(int num, int exp)
   {
-    if (this.value == anotherInteger.value)
-      return 0;
-
-    // Returns just -1 or 1 on inequality; doing math might overflow the int.
-    if (this.value > anotherInteger.value)
-      return 1;
+    // Use an array large enough for a binary number.
+    int radix = 1 << exp;
+    int mask = radix - 1;
+    char[] buffer = new char[32];
+    int i = 32;
+    do
+      {
+        buffer[--i] = Character.forDigit(num & mask, radix);
+        num = num >>> exp;
+      }
+    while (num != 0);
 
-    return -1;
+    return String.valueOf(buffer, i, 32-i);
   }
 
-  // Added in JDK 1.2
-  /** @throws ClassCastException */
-  public int compareTo(Object o)
+  /**
+   * Converts the <code>int</code> to a <code>String</code> assuming it is
+   * unsigned in base 16.
+   * @param i the <code>int</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toHexString(int i)
+  {
+    return toUnsignedString(i, 4);
+  }
+
+  /**
+   * Converts the <code>int</code> to a <code>String</code> assuming it is
+   * unsigned in base 8.
+   * @param i the <code>int</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toOctalString(int i)
+  {
+    return toUnsignedString(i, 3);
+  }
+
+  /**
+   * Converts the <code>int</code> to a <code>String</code> assuming it is
+   * unsigned in base 2.
+   * @param i the <code>int</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toBinaryString(int i)
+  {
+    return toUnsignedString(i, 1);
+  }
+
+  /**
+   * Converts the <code>int</code> to a <code>String</code> and assumes
+   * a radix of 10.
+   * @param i the <code>int</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toString(int i)
+  {
+    // This is tricky: in libgcj, String.valueOf(int) is a fast native
+    // implementation.  In Classpath it just calls back to
+    // Integer.toString(int,int).
+    return String.valueOf (i);
+  }
+
+  /**
+   * Converts the <code>Integer</code> value to a <code>String</code> and
+   * assumes a radix of 10.
+   * @return the <code>String</code> representation of this <code>Integer</code>.
+   */    
+  public String toString()
   {
-    return this.compareTo((Integer) o);
+    return toString (value);
   }
 
-  public static Integer decode(String str) throws NumberFormatException
+  /**
+   * Converts the <code>int</code> to a <code>String</code> using
+   * the specified radix (base).
+   * @param i the <code>int</code> to convert to <code>String</code>.
+   * @param radix the radix (base) to use in the conversion.
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toString(int num, int radix)
   {
-    boolean isNeg = false;
-    int index = 0;
-    int radix = 10;
-    final int len;
-
-    if ((len = str.length()) == 0)
-      throw new NumberFormatException();
+    // Use optimized method for the typical case.
+    if (radix == 10 ||
+        radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
+      return toString(num);
 
-    // Negative numbers are always radix 10.
-    if (str.charAt(0) == '-')
+    // For negative numbers, print out the absolute value w/ a leading '-'.
+    // Use an array large enough for a binary number.
+    char[] buffer = new char[33];
+    int i = 33;
+    boolean isNeg;
+    if (num < 0)
       {
-        radix = 10;
-        index++;
         isNeg = true;
-      }
-    else if (str.charAt(index) == '#')
-      {
-        radix = 16;
-        index++;
-      }
-    else if (str.charAt(index) == '0')
-      {
-        // Check if str is just "0"
-        if (len == 1)
-          return new Integer(0);
+        num = -(num);
 
-        index++;
-        if (str.charAt(index) == 'x')
+        // When the value is MIN_VALUE, it overflows when made positive
+        if (num < 0)
           {
-            radix = 16;
-            index++;
+            buffer[--i] = Character.forDigit(-(num + radix) % radix, radix);
+            num = -(num / radix);
           }
-        else
-          radix = 8;
       }
-
-    if (index >= len)
-      throw new NumberFormatException();
-
-    return new Integer(parseInt(str, index, len, isNeg, radix));
-  }
-
-  public boolean equals(Object obj)
-  {
-    return (obj instanceof Integer && ((Integer) obj).value == value);
-  }
-
-  public static Integer getInteger(String prop)
-  {
-    return getInteger(prop, null);
-  }
-
-  public static Integer getInteger(String prop, int defval)
-  {
-    Integer val = getInteger(prop, null);
-    return val == null ? new Integer(defval) : val;
-  }
+    else
+      isNeg = false;
 
-  public static Integer getInteger(String prop, Integer defobj)
-  {
-    try
-      {
-        String val = System.getProperty(prop);
-	if (val != null)
-	  return decode(val);
-      }
-    catch (NumberFormatException ex)
+    do
       {
+        buffer[--i] = Character.forDigit(num % radix, radix);
+        num /= radix;
       }
-    return defobj;
-  }
+    while (num > 0);
 
-  public int hashCode()
-  {
-    return value;
-  }
+    if (isNeg)
+      buffer[--i] = '-';
 
-  public static int parseInt(String str) throws NumberFormatException
-  {
-    return parseInt(str, 10);
+    return String.valueOf(buffer, i, 33-i);
   }
 
-  public static int parseInt(String str, int radix) throws NumberFormatException
+  /**
+   * Creates a new <code>Integer</code> object using the <code>String</code>,
+   * assuming a radix of 10.
+   * @param s the <code>String</code> to convert.
+   * @return the new <code>Integer</code>.
+   * @see #Integer(java.lang.String)
+   * @see #parseInt(java.lang.String)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as an <code>int</code>.
+   */
+  public static Integer valueOf(String s) throws NumberFormatException
+  {
+    return new Integer(parseInt(s));
+  }
+
+  /**
+   * Creates a new <code>Integer</code> object using the <code>String</code>
+   * and specified radix (base).
+   * @param s the <code>String</code> to convert.
+   * @param radix the radix (base) to convert with.
+   * @return the new <code>Integer</code>.
+   * @see #parseInt(java.lang.String,int)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as an <code>int</code>.
+   */
+  public static Integer valueOf(String s, int radix)
+    throws NumberFormatException
+  {
+    return new Integer(parseInt(s, radix));
+  }
+
+  /**
+   * Converts the specified <code>String</code> into an <code>int</code>.
+   * This function assumes a radix of 10.
+   *
+   * @param s the <code>String</code> to convert
+   * @return the <code>int</code> value of the <code>String</code>
+   *         argument.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as an <code>int</code>.
+   */
+  public static int parseInt(String s) throws NumberFormatException
+  {
+    return parseInt(s, 10);
+  }
+
+  /**
+   * Converts the specified <code>String</code> into an <code>int</code>
+   * using the specified radix (base).
+   *
+   * @param s the <code>String</code> to convert
+   * @param radix the radix (base) to use in the conversion
+   * @return the <code>String</code> argument converted to </code>int</code>.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>int</code>.    
+   */
+  public static int parseInt(String str, int radix)
+    throws NumberFormatException
   {
     final int len;
 
@@ -199,7 +385,8 @@
   }
 
   private static int parseInt(String str, int index, int len, boolean isNeg,
-        			int radix) throws NumberFormatException
+			      int radix)
+    throws NumberFormatException
   {
     int val = 0;
     int digval;
@@ -228,96 +415,156 @@
     return isNeg ? -(val) : val;
   }
 
-  public static String toBinaryString(int num)
+  /**
+   * Convert the specified <code>String</code> into an <code>Integer</code>.
+   * The <code>String</code> may represent decimal, hexadecimal, or 
+   * octal numbers.
+   *
+   * The <code>String</code> argument is interpreted based on the leading
+   * characters.  Depending on what the String begins with, the base will be
+   * interpreted differently:
+   *
+   * <table border=1>
+   * <tr><th>Leading<br>Characters</th><th>Base</th></tr>
+   * <tr><td>#</td><td>16</td></tr>
+   * <tr><td>0x</td><td>16</td></tr>
+   * <tr><td>0X</td><td>16</td></tr>
+   * <tr><td>0</td><td>8</td></tr>
+   * <tr><td>Anything<br>Else</td><td>10</td></tr>
+   * </table>
+   *
+   * @param str the <code>String</code> to interpret.
+   * @return the value of the String as an <code>Integer</code>.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as an <code>int</code>.    
+   */
+  public static Integer decode(String str) throws NumberFormatException
   {
-    return toUnsignedString(num, 1);
+    boolean isNeg = false;
+    int index = 0;
+    int radix = 10;
+    final int len;
+
+    if (str == null || (len = str.length()) == 0)
+      throw new NumberFormatException("string null or empty");
+
+    // Negative numbers are always radix 10.
+    if (str.charAt(index) == '-')
+      {
+        radix = 10;
+        index++;
+        isNeg = true;
+      }
+    else if (str.charAt(index) == '#')
+      {
+        radix = 16;
+        index++;
+      }
+    else if (str.charAt(index) == '0')
+      {
+        // Check if str is just "0"
+        if (len == 1)
+          return new Integer(0);
+
+        index++;
+        if (str.charAt(index) == 'x' || str.charAt(index) == 'X')
+          {
+            radix = 16;
+            index++;
+          }
+        else
+          radix = 8;
+      }
+
+    if (index >= len)
+      throw new NumberFormatException("empty value");
+
+    return new Integer(parseInt(str, index, len, isNeg, radix));
   }
 
-  public static String toHexString(int num)
+  /** Return the value of this <code>Integer</code> as a <code>byte</code>.
+   ** @return the value of this <code>Integer</code> as a <code>byte</code>.
+   **/
+  public byte byteValue()
   {
-    return toUnsignedString(num, 4);
+    return (byte) value;
   }
 
-  public static String toOctalString(int num)
+  /** Return the value of this <code>Integer</code> as a <code>short</code>.
+   ** @return the value of this <code>Integer</code> as a <code>short</code>.
+   **/
+  public short shortValue()
   {
-    return toUnsignedString(num, 3);
+    return (short) value;
   }
 
-  private static String toUnsignedString(int num, int exp)
+  /** Return the value of this <code>Integer</code> as an <code>int</code>.
+   ** @return the value of this <code>Integer</code> as an <code>int</code>.
+   **/
+  public int intValue()
   {
-    // Use an array large enough for a binary number.
-    int radix = 1 << exp;
-    int mask = radix - 1;
-    char[] buffer = new char[32];
-    int i = 32;
-    do
-      {
-        buffer[--i] = Character.forDigit(num & mask, radix);
-        num = num >>> exp;
-      }
-    while (num != 0);
-
-    return String.valueOf(buffer, i, 32-i);
+    return value;
   }
 
-  public String toString()
+  /** Return the value of this <code>Integer</code> as a <code>long</code>.
+   ** @return the value of this <code>Integer</code> as a <code>long</code>.
+   **/
+  public long longValue()
   {
-    return toString(this.value);
+    return value;
   }
 
-  public static String toString(int num)
+  /** Return the value of this <code>Integer</code> as a <code>float</code>.
+   ** @return the value of this <code>Integer</code> as a <code>float</code>.
+   **/
+  public float floatValue()
   {
-    return String.valueOf (num);
+    return value;
   }
 
-  public static String toString(int num, int radix)
+  /** Return the value of this <code>Integer</code> as a <code>double</code>.
+   ** @return the value of this <code>Integer</code> as a <code>double</code>.
+   **/
+  public double doubleValue()
   {
-    // Use optimized method for the typical case.
-    if (radix == 10 ||
-        radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
-      return toString(num);
-
-    // For negative numbers, print out the absolute value w/ a leading '-'.
-    // Use an array large enough for a binary number.
-    char[] buffer = new char[33];
-    int i = 33;
-    boolean isNeg;
-    if (num < 0)
-      {
-        isNeg = true;
-        num = -(num);
-
-        // When the value is MIN_VALUE, it overflows when made positive
-        if (num < 0)
-          {
-            buffer[--i] = Character.forDigit(-(num + radix) % radix, radix);
-            num = -(num / radix);
-          }
-      }
-    else
-      isNeg = false;
-
-    do
-      {
-        buffer[--i] = Character.forDigit(num % radix, radix);
-        num /= radix;
-      }
-    while (num > 0);
-
-    if (isNeg)
-      buffer[--i] = '-';
-
-    return String.valueOf(buffer, i, 33-i);
+    return value;
   }
 
-  public static Integer valueOf(String str) throws NumberFormatException
+  /**
+   * Compare two Integers numerically by comparing their
+   * <code>int</code> values.
+   * @return a positive value if this <code>Integer</code> is greater
+   * in value than the argument <code>Integer</code>; a negative value
+   * if this <code>Integer</code> is smaller in value than the argument
+   * <code>Integer</code>; and <code>0</code>, zero, if this
+   * <code>Integer</code> is equal in value to the argument
+   * <code>Integer</code>.  
+   *
+   * @since 1.2
+   */
+  public int compareTo(Integer i)
   {
-    return new Integer(parseInt(str, 10));
+    if (this.value == i.value)
+      return 0;
+
+    // Returns just -1 or 1 on inequality; doing math might overflow.
+    if (this.value > i.value)
+      return 1;
+
+    return -1;
   }
 
-  public static Integer valueOf(String str, int radix)
-  				throws NumberFormatException
+  /**
+   * Behaves like <code>compareTo(java.lang.Integer)</code> unless the Object
+   * is not a <code>Integer</code>.  Then it throws a 
+   * <code>ClassCastException</code>.
+   * @exception ClassCastException if the argument is not a
+   * <code>Integer</code>.
+   *
+   * @since 1.2
+   */
+  public int compareTo(Object o)
   {
-    return new Integer(parseInt(str, radix));
+    return compareTo((Integer)o);
   }
 }
Index: java/lang/Long.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Long.java,v
retrieving revision 1.8
diff -u -r1.8 Long.java
--- java/lang/Long.java 2001/05/22 04:38:35 1.8
+++ java/lang/Long.java 2001/07/23 19:54:58
@@ -1,98 +1,425 @@
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* java.lang.Long
+   Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
 
-   This file is part of libgcj.
+This file is part of GNU Classpath.
 
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
  
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
 package java.lang;
 
 /**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date September 18, 1998.  
- */
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * plus online API docs for JDK 1.2 beta from http://www.javasoft.com .
- * Status:  Believed complete and correct.
+ * Instances of class <code>Double</code> represent primitive
+ * <code>double</code> values.
+ *
+ * Additionally, this class provides various helper functions and variables
+ * related to longs.
+ *
+ * @author Paul Fisher
+ * @author John Keiser
+ * @author Warren Levy
+ * @since JDK 1.0
  */
- 
 public final class Long extends Number implements Comparable
 {
-  public static final long MAX_VALUE = 0x7FFFFFFFFFFFFFFFL;
-  public static final long MIN_VALUE = 0x8000000000000000L;
+  // compatible with JDK 1.0.2+
+  static final long serialVersionUID = 4290774380558885855L;
 
-  // This initialization is seemingly circular, but it is accepted
-  // by javac, and is handled specially by gcc.
-  public static final Class TYPE = long.class;
-
-  /* The long value of the instance. */
-  private long value;
-
-  private static final long serialVersionUID = 4290774380558885855L;
+  /**
+   * The minimum value a <code>long</code> can represent is
+   * -9223372036854775808.
+   */
+  public static final long MIN_VALUE = 0x8000000000000000L;
 
-  public Long(long val)
+  /**
+   * The maximum value a <code>long</code> can represent is
+   * 9223372036854775807.
+   */
+  public static final long MAX_VALUE = 0x7fffffffffffffffL;
+
+  /**
+   * The primitive type <code>long</code> is represented by this 
+   * <code>Class</code> object.
+   */
+  public static final Class TYPE = VMClassLoader.getPrimitiveClass ("long");
+
+  /**
+   * The immutable value of this Long.
+   */
+  private final long value;
+
+  /**
+   * Create a <code>Long</code> object representing the value of the 
+   * <code>long</code> argument.
+   *
+   * @param value the value to use
+   */
+  public Long(long value)
+  {
+    this.value = value;
+  }
+
+  /**
+   * Create a <code>Long</code> object representing the value of the 
+   * argument after conversion to a <code>long</code>.
+   *
+   * @param s the string to convert.
+   */
+  public Long(String s) throws NumberFormatException
+  {
+    value = parseLong(s, 10);
+  }
+
+  /**
+   * If the <code>Object</code> is not <code>null</code>, is an
+   * <code>instanceof</code> <code>Long</code>, and represents
+   * the same primitive <code>long</code> value return 
+   * <code>true</code>.  Otherwise <code>false</code> is returned.
+   */
+  public boolean equals(Object obj)
   {
-    value = val;
+    return obj instanceof Long && ((Long)obj).value == value;
   }
 
-  public Long(String str) throws NumberFormatException
+  /**
+   * Return a hashcode representing this Object.
+   *
+   * <code>Long</code>'s hash code is calculated by simply returning its
+   * value.
+   *
+   * @return this Object's hash code.
+   */
+  public int hashCode()
   {
-    value = parseLong(str, 10);
+    return (int)(value^(value>>>32));
   }
 
-  public byte byteValue()
-  {
-    return (byte) value;
+  /**
+   * Get the specified system property as a <code>Long</code>.
+   *
+   * A method similar to <code>Integer</code>'s <code>decode()</code> will be
+   * used to interpret the value of the property.
+   * 
+   * @param nm the name of the system property
+   * @return the system property as an <code>Long</code>, or
+   *         <code>null</code> if the property is not found or cannot be
+   *         decoded as a <code>Long</code>.
+   * @see java.lang.System#getProperty(java.lang.String)
+   * @see java.lang.Integer#decode(int)
+   */
+  public static Long getLong(String nm)
+  {
+    return getLong(nm, null);
+  }
+
+  /**
+   * Get the specified system property as an <code>Long</code>, or use a
+   * default <code>long</code> value if the property is not found or is not
+   * decodable.
+   * 
+   * A method similar to <code>Integer</code>'s <code>decode()</code> will be
+   * used to interpret the value of the property.
+   * 
+   * @param nm the name of the system property
+   * @param val the default value to use if the property is not found or not
+   *        a number.
+   * @return the system property as a <code>Long</code>, or the default
+   *         value if the property is not found or cannot be decoded as a
+   *         <code>Long</code>.
+   * @see java.lang.System#getProperty(java.lang.String)
+   * @see java.lang.Integer#decode(int)
+   * @see #getLong(java.lang.String,java.lang.Long)
+   */
+  public static Long getLong(String nm, long val)
+  {
+    Long result = getLong(nm, null);
+    return (result == null) ? new Long(val) : result;
+  }
+
+  /**
+   * Get the specified system property as an <code>Long</code>, or use a
+   * default <code>Long</code> value if the property is not found or is
+   * not decodable.
+   * 
+   * The <code>decode()</code> method will be used to interpret the value of
+   * the property.
+   *
+   * @param nm the name of the system property
+   * @param val the default value to use if the property is not found or not
+   *        a number.
+   * @return the system property as an <code>Long</code>, or the default
+   *         value if the property is not found or cannot be decoded as an
+   *         <code>Long</code>.
+   * @see java.lang.System#getProperty(java.lang.String)
+   * @see java.lang.Integer#decode(int)
+   * @see #getLong(java.lang.String,long)
+   */
+  public static Long getLong(String nm, Long def)
+  {
+    String val = System.getProperty(nm);
+    if (val == null)
+      return def;
+    try
+      {
+	return decode(nm);
+      }
+    catch (NumberFormatException e)
+      {
+	return def;
+      }
   }
 
-  public double doubleValue()
+  private static String toUnsignedString(long num, int exp)
   {
-    return (double) value;
-  }
+    // Use an array large enough for a binary number.
+    int radix = 1 << exp;
+    int mask = radix - 1;
+    char[] buffer = new char[64];
+    int i = 64;
+    do
+      {
+        buffer[--i] = Character.forDigit((int) num & mask, radix);
+        num = num >>> exp;
+      }
+    while (num != 0);
 
-  public float floatValue()
-  {
-    return (float) value;
+    return String.valueOf(buffer, i, 64-i);
   }
 
-  public int intValue()
+  /**
+   * Converts the <code>long</code> to a <code>String</code> assuming it is
+   * unsigned in base 16.
+   * @param i the <code>long</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toHexString(long i)
+  {
+    return toUnsignedString(i, 4);
+  }
+
+  /**
+   * Converts the <code>long</code> to a <code>String</code> assuming it is
+   * unsigned in base 8.
+   * @param i the <code>long</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toOctalString(long i)
+  {
+    return toUnsignedString(i, 3);
+  }
+
+  /**
+   * Converts the <code>long</code> to a <code>String</code> assuming it is
+   * unsigned in base 2.
+   * @param i the <code>long</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toBinaryString(long i) {
+    return toUnsignedString(i, 1);
+  }
+
+  /**
+   * Converts the <code>long</code> to a <code>String</code> and assumes
+   * a radix of 10.
+   * @param num the <code>long</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */    
+  public static String toString(long num)
   {
-    return (int) value;
-  }
+    // Use the Integer toString for efficiency if possible.
+    if (num <= Integer.MAX_VALUE && num >= Integer.MIN_VALUE)
+      return Integer.toString((int) num);
 
-  public long longValue()
-  {
-    return value;
+    // Use an array large enough for "-9223372036854775808"; i.e. 20 chars.
+    char[] buffer = new char[20];
+    int i = 20;
+    boolean isNeg;
+    if (num < 0)
+      {
+        isNeg = true;
+        num = -(num);
+        if (num < 0)
+          {
+            // Must be MIN_VALUE, so handle this special case.
+            buffer[--i] = '8';
+            num = 922337203685477580L;
+          }
+      }
+    else
+      isNeg = false;
+
+    do
+      {
+        buffer[--i] = (char) ((int) '0' + (num % 10));
+        num /= 10;
+      }
+    while (num > 0);
+
+    if (isNeg)
+      buffer[--i] = '-';
+
+    return String.valueOf(buffer, i, 20-i);
   }
 
-  public short shortValue()
+  /**
+   * Converts the <code>Long</code> value to a <code>String</code> and
+   * assumes a radix of 10.
+   * @return the <code>String</code> representation of this <code>Long</code>.
+   */    
+  public String toString()
   {
-    return (short) value;
+    return toString(value);
   }
-
-  // Added in JDK 1.2
-  public int compareTo(Long anotherLong)
+  
+  /**
+   * Converts the <code>long</code> to a <code>String</code> using
+   * the specified radix (base).
+   * @param num the <code>long</code> to convert to <code>String</code>.
+   * @param radix the radix (base) to use in the conversion.
+   * @return the <code>String</code> representation of the argument.
+   */
+  public static String toString(long num, int radix)
   {
-    if (this.value == anotherLong.value)
-      return 0;
+    // Use optimized method for the typical case.
+    if (radix == 10 ||
+        radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
+      return toString(num);
 
-    // Returns just -1 or 1 on inequality; doing math might overflow the long.
-    if (this.value > anotherLong.value)
-      return 1;
+    // Use the Integer toString for efficiency if possible.
+    if (num <= Integer.MAX_VALUE && num >= Integer.MIN_VALUE)
+      return Integer.toString((int) num, radix);
 
-    return -1;
-  }
+    // For negative numbers, print out the absolute value w/ a leading '-'.
+    // Use an array large enough for a binary number.
+    char[] buffer = new char[65];
+    int i = 65;
+    boolean isNeg;
+    if (num < 0)
+      {
+        isNeg = true;
+        num = -(num);
 
-  // Added in JDK 1.2
-  /** @throws ClassCastException */
-  public int compareTo(Object o)
+        // When the value is MIN_VALUE, it overflows when made positive
+        if (num < 0)
+          {
+            buffer[--i] = Character.forDigit((int) (-(num + radix) % radix),
+						radix);
+            num = -(num / radix);
+          }
+      }
+    else
+      isNeg = false;
+
+    do
+      {
+        buffer[--i] = Character.forDigit((int) (num % radix), radix);
+        num /= radix;
+      }
+    while (num > 0);
+
+    if (isNeg)
+      buffer[--i] = '-';
+
+    return String.valueOf(buffer, i, 65-i);
+  }
+    
+  /**
+   * Creates a new <code>Long</code> object using the <code>String</code>,
+   * assuming a radix of 10.
+   * @param s the <code>String</code> to convert.
+   * @return the new <code>Long</code>.
+   * @see #Long(java.lang.String)
+   * @see #parseLong(java.lang.String)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>long</code>.
+   */
+  public static Long valueOf(String s) throws NumberFormatException
+  {
+    return new Long(parseLong(s));
+  }
+
+  /**
+   * Creates a new <code>Long</code> object using the <code>String</code>
+   * and specified radix (base).
+   * @param s the <code>String</code> to convert.
+   * @param radix the radix (base) to convert with.
+   * @return the new <code>Long</code>.
+   * @see #parseLong(java.lang.String,int)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>long</code>.
+   */
+  public static Long valueOf(String s, int radix) throws NumberFormatException
+  {
+    return new Long(parseLong(s, radix));
+  }
+
+  /**
+   * Converts the specified <code>String</code> into a <code>long</code>.
+   * This function assumes a radix of 10.
+   *
+   * @param s the <code>String</code> to convert
+   * @return the <code>long</code> value of the <code>String</code>
+   *         argument.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>long</code>.
+   */
+  public static long parseLong(String s) throws NumberFormatException
+  {
+    return parseLong(s, 10);
+  }
+
+  /**
+   * Converts the specified <code>String</code> into a <code>long</code>
+   * using the specified radix (base).
+   *
+   * @param s the <code>String</code> to convert
+   * @param radix the radix (base) to use in the conversion
+   * @return the <code>String</code> argument converted to </code>long</code>.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>long</code>.    
+   */
+  public static long parseLong(String str, int radix)
+    throws NumberFormatException
   {
-    return this.compareTo((Long) o);
+    final int len;
+
+    if ((len = str.length()) == 0 || radix < Character.MIN_RADIX 
+         || radix > Character.MAX_RADIX)
+      throw new NumberFormatException();
+
+    boolean isNeg = false;
+    int index = 0;
+    if (str.charAt(index) == '-')
+      if (len > 1)
+        {
+          isNeg = true;
+          index++;
+        }
+      else
+        throw new NumberFormatException();
+
+    return parseLong(str, index, len, isNeg, radix);
   }
 
-  // Added in JDK 1.2
   public static Long decode(String str) throws NumberFormatException
   {
     boolean isNeg = false;
@@ -137,69 +464,6 @@
     return new Long(parseLong(str, index, len, isNeg, radix));
   }
 
-  public boolean equals(Object obj)
-  {
-    return (obj instanceof Long && ((Long) obj).value == value);
-  }
-
-  public static Long getLong(String prop)
-  {
-    return getLong(prop, null);
-  }
-
-  public static Long getLong(String prop, long defval)
-  {
-    Long val = getLong(prop, null);
-    return val == null ? new Long(defval) : val;
-  }
-
-  public static Long getLong(String prop, Long defobj)
-  {
-    try
-      {
-        String val = System.getProperty(prop);
-	if (val != null)    
-	  return decode(val);
-      }
-    catch (NumberFormatException ex)
-      {
-      }
-    return defobj;
-  }
-
-  public int hashCode()
-  {
-    return (int)(this.longValue()^(this.longValue()>>>32));
-  }
-
-  public static long parseLong(String str) throws NumberFormatException
-  {
-    return parseLong(str, 10);
-  }
-
-  public static long parseLong(String str, int radix)
-			throws NumberFormatException
-  {
-    final int len;
-
-    if ((len = str.length()) == 0 || radix < Character.MIN_RADIX 
-         || radix > Character.MAX_RADIX)
-      throw new NumberFormatException();
-
-    boolean isNeg = false;
-    int index = 0;
-    if (str.charAt(index) == '-')
-      if (len > 1)
-        {
-          isNeg = true;
-          index++;
-        }
-      else
-        throw new NumberFormatException();
-
-    return parseLong(str, index, len, isNeg, radix);
-  }
-
   private static long parseLong(String str, int index, int len, boolean isNeg,
         			int radix) throws NumberFormatException
   {
@@ -230,133 +494,89 @@
     return isNeg ? -(val) : val;
   }
 
-  public static String toBinaryString(long num)
+  /** Return the value of this <code>Long</code> as an <code>short</code>.
+   ** @return the value of this <code>Long</code> as an <code>short</code>.
+   **/
+  public byte byteValue()
   {
-    return toUnsignedString(num, 1);
+    return (byte) value;
   }
 
-  public static String toHexString(long num)
+  /** Return the value of this <code>Long</code> as an <code>short</code>.
+   ** @return the value of this <code>Long</code> as an <code>short</code>.
+   **/
+  public short shortValue()
   {
-    return toUnsignedString(num, 4);
+    return (short) value;
   }
 
-  public static String toOctalString(long num)
+  /** Return the value of this <code>Long</code> as an <code>int</code>.
+   ** @return the value of this <code>Long</code> as an <code>int</code>.
+   **/
+  public int intValue()
   {
-    return toUnsignedString(num, 3);
+    return (int) value;
   }
 
-  private static String toUnsignedString(long num, int exp)
+  /** Return the value of this <code>Long</code> as a <code>long</code>.
+   ** @return the value of this <code>Long</code> as a <code>long</code>.
+   **/
+  public long longValue()
   {
-    // Use an array large enough for a binary number.
-    int radix = 1 << exp;
-    long mask = radix - 1;
-    char[] buffer = new char[64];
-    int i = 64;
-    do
-      {
-        buffer[--i] = Character.forDigit((int) (num & mask), radix);
-        num = num >>> exp;
-      }
-    while (num != 0);
-
-    return String.valueOf(buffer, i, 64-i);
+    return value;
   }
 
-  public String toString()
+  /** Return the value of this <code>Long</code> as a <code>float</code>.
+   ** @return the value of this <code>Long</code> as a <code>float</code>.
+   **/
+  public float floatValue()
   {
-    return toString(this.value);
+    return value;
   }
 
-  public static String toString(long num)
+  /** Return the value of this <code>Long</code> as a <code>double</code>.
+   ** @return the value of this <code>Long</code> as a <code>double</code>.
+   **/
+  public double doubleValue()
   {
-    // Use the Integer toString for efficiency if possible.
-    if (num <= Integer.MAX_VALUE && num >= Integer.MIN_VALUE)
-      return Integer.toString((int) num);
-
-    // Use an array large enough for "-9223372036854775808"; i.e. 20 chars.
-    char[] buffer = new char[20];
-    int i = 20;
-    boolean isNeg;
-    if (num < 0)
-      {
-        isNeg = true;
-        num = -(num);
-        if (num < 0)
-          {
-            // Must be MIN_VALUE, so handle this special case.
-            buffer[--i] = '8';
-            num = 922337203685477580L;
-          }
-      }
-    else
-      isNeg = false;
-
-    do
-      {
-        buffer[--i] = (char) ((int) '0' + (num % 10));
-        num /= 10;
-      }
-    while (num > 0);
-
-    if (isNeg)
-      buffer[--i] = '-';
-
-    return String.valueOf(buffer, i, 20-i);
+    return value;
   }
 
-  public static String toString(long num, int radix)
+  /**
+   * Compare two Longs numerically by comparing their
+   * <code>long</code> values.
+   * @return a positive value if this <code>Long</code> is greater
+   * in value than the argument <code>Long</code>; a negative value
+   * if this <code>Long</code> is smaller in value than the argument
+   * <code>Long</code>; and <code>0</code>, zero, if this
+   * <code>Long</code> is equal in value to the argument
+   * <code>Long</code>.  
+   *
+   * @since 1.2
+   */
+  public int compareTo(Long l)
   {
-    // Use optimized method for the typical case.
-    if (radix == 10 ||
-        radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
-      return toString(num);
-
-    // Use the Integer toString for efficiency if possible.
-    if (num <= Integer.MAX_VALUE && num >= Integer.MIN_VALUE)
-      return Integer.toString((int) num, radix);
-
-    // For negative numbers, print out the absolute value w/ a leading '-'.
-    // Use an array large enough for a binary number.
-    char[] buffer = new char[65];
-    int i = 65;
-    boolean isNeg;
-    if (num < 0)
-      {
-        isNeg = true;
-        num = -(num);
-
-        // When the value is MIN_VALUE, it overflows when made positive
-        if (num < 0)
-          {
-            buffer[--i] = Character.forDigit((int) (-(num + radix) % radix),
-						radix);
-            num = -(num / radix);
-          }
-      }
-    else
-      isNeg = false;
-
-    do
-      {
-        buffer[--i] = Character.forDigit((int) (num % radix), radix);
-        num /= radix;
-      }
-    while (num > 0);
-
-    if (isNeg)
-      buffer[--i] = '-';
+    if (this.value == l.value)
+      return 0;
 
-    return String.valueOf(buffer, i, 65-i);
-  }
+    // Returns just -1 or 1 on inequality; doing math might overflow the long.
+    if (this.value > l.value)
+      return 1;
 
-  public static Long valueOf(String str) throws NumberFormatException
-  {
-    return new Long(parseLong(str, 10));
+    return -1;
   }
-
-  public static Long valueOf(String str, int radix)
-  				throws NumberFormatException
+    
+  /**
+   * Behaves like <code>compareTo(java.lang.Long)</code> unless the Object
+   * is not a <code>Long</code>.  Then it throws a 
+   * <code>ClassCastException</code>.
+   * @exception ClassCastException if the argument is not a
+   * <code>Long</code>.
+   *
+   * @since 1.2
+   */
+  public int compareTo(Object o)
   {
-    return new Long(parseLong(str, radix));
+    return compareTo((Long)o);
   }
 }
Index: java/lang/Number.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Number.java,v
retrieving revision 1.4
diff -u -r1.4 Number.java
--- java/lang/Number.java 2000/09/08 19:37:08 1.4
+++ java/lang/Number.java 2001/07/23 19:54:59
@@ -1,41 +1,83 @@
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* java.lang.Number
+   Copyright (C) 1998, 2001 Free Software Foundation, Inc.
 
-   This file is part of libgcj.
+This file is part of GNU Classpath.
 
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
  
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+
 package java.lang;
 
 import java.io.Serializable;
- 
+
 /**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date September 2, 1998.  
- */
-/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
- * "The Java Language Specification", ISBN 0-201-63451-1
- * plus online API docs for JDK 1.2 beta from http://www.javasoft.com .
- * Status:  Believed complete and correct.
- */
- 
+ ** Number is a generic superclass of all the numeric classes, namely
+ ** <code>Byte</code>, <code>Short</code>, <code>Integer</code>,
+ ** <code>Long</code>, <code>Float</code>, and <code>Double</code>.
+ **
+ ** It provides ways to convert from any one value to any other.
+ **
+ ** @author Paul Fisher
+ ** @author John Keiser
+ ** @author Warren Levy
+ ** @since JDK1.0
+ **/
 public abstract class Number implements Serializable
 {
-  public byte byteValue()	// Became non-abstract in JDK 1.2
+  /** Return the value of this <code>Number</code> as a <code>byte</code>.
+   ** @return the value of this <code>Number</code> as a <code>byte</code>.
+   **/
+  public byte byteValue()
   {
     return (byte) intValue();
   }
-
-  public abstract double doubleValue();
-  public abstract float floatValue();
-  public abstract int intValue();
-  public abstract long longValue();
 
-  public short shortValue()	// Became non-abstract in JDK 1.2
+  /** Return the value of this <code>Number</code> as a <code>short</code>.
+   ** @return the value of this <code>Number</code> as a <code>short</code>.
+   **/
+  public short shortValue()
   {
     return (short) intValue();
   }
+
+  /** Return the value of this <code>Number</code> as an <code>int</code>.
+   ** @return the value of this <code>Number</code> as an <code>int</code>.
+   **/
+  public abstract int intValue();
+
+  /** Return the value of this <code>Number</code> as a <code>long</code>.
+   ** @return the value of this <code>Number</code> as a <code>long</code>.
+   **/
+  public abstract long longValue();
+
+  /** Return the value of this <code>Number</code> as a <code>float</code>.
+   ** @return the value of this <code>Number</code> as a <code>float</code>.
+   **/
+  public abstract float floatValue();
+
+  /** Return the value of this <code>Number</code> as a <code>float</code>.
+   ** @return the value of this <code>Number</code> as a <code>float</code>.
+   **/
+  public abstract double doubleValue();
 
   private static final long serialVersionUID = -8742448824652078965L;
 }
Index: java/lang/Short.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Short.java,v
retrieving revision 1.5
diff -u -r1.5 Short.java
--- java/lang/Short.java 2001/02/09 02:56:38 1.5
+++ java/lang/Short.java 2001/07/23 19:54:59
@@ -1,144 +1,307 @@
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* java.lang.Short
+   Copyright (C) 1998, 2001 Free Software Foundation, Inc.
 
-   This file is part of libgcj.
+This file is part of GNU Classpath.
 
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
 
+
 package java.lang;
 
 /**
- * @author Per Bothner <bothner@cygnus.com>
- * @date April 17, 1998.  
- */
-/* Written using "Java Class Libraries", 2nd edition, plus online
- * API docs for JDK 1.2 beta from http://www.javasoft.com .
- * Status:  Believed complete and correct.
- *	    Includes JDK 1.2 methods.
+ * Instances of class <code>Short</code> represent primitive
+ * <code>short</code> values.
+ *
+ * Additionally, this class provides various helper functions and variables
+ * related to shorts.
+ *
+ * @author Paul Fisher
+ * @author John Keiser
+ * @since JDK 1.0
  */
-
 public final class Short extends Number implements Comparable
 {
-  short value;
-
-  public final static short MIN_VALUE = -32768;
-  public final static short MAX_VALUE = 32767;
+  static final long serialVersionUID = 7515723908773894738L;
 
-  // This initialization is seemingly circular, but it is accepted
-  // by javac, and is handled specially by gcc.
-  public static final Class TYPE = short.class;
-
-  private static final long serialVersionUID = 7515723908773894738L;
-
+  /**
+   * The minimum value a <code>short</code> can represent is -32768.
+   */
+  public static final short MIN_VALUE = -32768;
+
+  /**
+   * The minimum value a <code>short</code> can represent is 32767.
+   */
+  public static final short MAX_VALUE =  32767;
+
+  /**
+   * The primitive type <code>short</code> is represented by this 
+   * <code>Class</code> object.
+   */
+  public static final Class TYPE = VMClassLoader.getPrimitiveClass("short");
+
+  /**
+   * The immutable value of this Short.
+   */
+  private final short value;
+
+  /**
+   * Create a <code>Short</code> object representing the value of the 
+   * <code>short</code> argument.
+   *
+   * @param value the value to use
+   */
   public Short(short value)
   {
     this.value = value;
   }
 
-  public Short(String str) 
-    throws NumberFormatException
-  {
-    this.value = parseShort(str, 10);
-  }
-
-  public byte byteValue()
-  {
-    return (byte) value;
-  }
-
-  public short shortValue()
-  {
-    return value;
-  }
-
-  public int intValue()
+  /**
+   * Create a <code>Short</code> object representing the value of the 
+   * argument after conversion to a <code>short</code>.
+   *
+   * @param s the string to convert.
+   */
+  public Short(String s) throws NumberFormatException
+  {
+    value = parseShort(s, 10);
+  }
+
+  /**
+   * Return a hashcode representing this Object.
+   *
+   * <code>Short</code>'s hash code is calculated by simply returning its
+   * value.
+   *
+   * @return this Object's hash code.
+   */
+  public int hashCode()
   {
     return value;
   }
 
-  public long longValue ()
+  /**
+   * If the <code>Object</code> is not <code>null</code>, is an
+   * <code>instanceof</code> <code>Short</code>, and represents
+   * the same primitive <code>short</code> value return 
+   * <code>true</code>.  Otherwise <code>false</code> is returned.
+   */
+  public boolean equals(Object obj)
   {
-    return value;
+    return obj instanceof Short && ((Short)obj).value == value;
   }
 
-  public float floatValue ()
+  /**
+   * Converts the <code>short</code> to a <code>String</code> and assumes
+   * a radix of 10.
+   * @param i the <code>short</code> to convert to <code>String</code>
+   * @return the <code>String</code> representation of the argument.
+   */    
+  public static String toString(short i)
   {
-    return (float) value;
+    return Integer.toString((int) i);
   }
 
-  public double doubleValue ()
+  /**
+   * Converts the <code>Short</code> value to a <code>String</code> and
+   * assumes a radix of 10.
+   * @return the <code>String</code> representation of this <code>Short</code>.
+   */    
+  public String toString()
   {
-    return (double) value;
+    return Integer.toString ((int) value);
   }
 
-  public static Short decode(String str)
+  /**
+   * Creates a new <code>Short</code> object using the <code>String</code>,
+   * assuming a radix of 10.
+   * @param s the <code>String</code> to convert.
+   * @return the new <code>Short</code>.
+   * @see #Short(java.lang.String)
+   * @see #parseShort(java.lang.String)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>short</code>.
+   */
+  public static Short valueOf(String s) throws NumberFormatException
+  {
+    return new Short(parseShort(s));
+  }
+
+  /**
+   * Creates a new <code>Short</code> object using the <code>String</code>
+   * and specified radix (base).
+   * @param s the <code>String</code> to convert.
+   * @param radix the radix (base) to convert with.
+   * @return the new <code>Short</code>.
+   * @see #parseShort(java.lang.String,int)
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>short</code>.
+   */
+  public static Short valueOf(String s, int radix)
     throws NumberFormatException
   {
-    int i = (Integer.decode(str)).intValue();
-    if (i < MIN_VALUE || i > MAX_VALUE)
-      throw new NumberFormatException();
-    return new Short((short) i);
+    return new Short(parseShort(s, radix));
   }
 
-  public static short parseShort(String str, int radix)
+  /**
+   * Converts the specified <code>String</code> into a <code>short</code>.
+   * This function assumes a radix of 10.
+   *
+   * @param s the <code>String</code> to convert
+   * @return the <code>short</code> value of the <code>String</code>
+   *         argument.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>short</code>.
+   */
+  public static short parseShort(String s) throws NumberFormatException
+  {
+    return parseShort(s, 10);
+  }
+
+  /**
+   * Converts the specified <code>String</code> into a <code>short</code>
+   * using the specified radix (base).
+   *
+   * @param s the <code>String</code> to convert
+   * @param radix the radix (base) to use in the conversion
+   * @return the <code>String</code> argument converted to </code>short</code>.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>short</code>.
+   */
+  public static short parseShort(String s, int radix) 
     throws NumberFormatException
   {
-    int i = Integer.parseInt(str, radix);
+    int i = Integer.parseInt(s, radix);
     if (i < MIN_VALUE || i > MAX_VALUE)
       throw new NumberFormatException();
     return (short) i;
   }
 
-  public static short parseShort(String str)
-    throws NumberFormatException
+  /**
+   * Convert the specified <code>String</code> into a <code>Short</code>.
+   * The <code>String</code> may represent decimal, hexadecimal, or 
+   * octal numbers.
+   *
+   * The <code>String</code> argument is interpreted based on the leading
+   * characters.  Depending on what the String begins with, the base will be
+   * interpreted differently:
+   *
+   * <table>
+   * <tr><th>Leading<br>Characters</th><th>Base</th></tr>
+   * <tr><td>#</td><td>16</td></tr>
+   * <tr><td>0x</td><td>16</td></tr>
+   * <tr><td>0X</td><td>16</td></tr>
+   * <tr><td>0</td><td>8</td></tr>
+   * <tr><td>Anything<br>Else</td><td>10</td></tr>
+   * </table>
+   *
+   * @param s the <code>String</code> to interpret.
+   * @return the value of the String as a <code>Short</code>.
+   * @exception NumberFormatException thrown if the <code>String</code> 
+   * cannot be parsed as a <code>short</code>.    
+   */
+  public static Short decode(String s) throws NumberFormatException
   {
-    return parseShort(str, 10);
-  }
-
-  public static Short valueOf(String str, int radix)
-    throws NumberFormatException
-  {
-    return new Short(parseShort(str, radix));
+    int i = (Integer.decode(s)).intValue();
+    if (i < MIN_VALUE || i > MAX_VALUE)
+      throw new NumberFormatException();
+    return new Short((short) i);
   }
 
-  public static Short valueOf(String str)
-    throws NumberFormatException
+  /** Return the value of this <code>Short</code> as an <code>short</code>.
+   ** @return the value of this <code>Short</code> as an <code>short</code>.
+   **/
+  public byte byteValue()
   {
-    return valueOf(str, 10);
+    return (byte) value;
   }
 
-  // Added in JDK 1.2
-  public int compareTo(Short anotherShort)
+  /** Return the value of this <code>Short</code> as an <code>short</code>.
+   ** @return the value of this <code>Short</code> as an <code>short</code>.
+   **/
+  public short shortValue()
   {
-    return this.value - anotherShort.value;
+    return value;
   }
 
-  // Added in JDK 1.2
-  /** @throws ClassCastException */
-  public int compareTo(Object o)
+  /** Return the value of this <code>Short</code> as an <code>int</code>.
+   ** @return the value of this <code>Short</code> as an <code>int</code>.
+   **/
+  public int intValue()
   {
-    return this.value - ((Short) o).value;
+    return value;
   }
 
-  public boolean equals(Object obj)
+  /** Return the value of this <code>Short</code> as a <code>long</code>.
+   ** @return the value of this <code>Short</code> as a <code>long</code>.
+   **/
+  public long longValue()
   {
-    return (obj instanceof Short) && ((Short) obj).value == value;
+    return value;
   }
 
-  // Verified that hashCode is returns plain value (see Short_1 test).
-  public int hashCode()
+  /** Return the value of this <code>Short</code> as a <code>float</code>.
+   ** @return the value of this <code>Short</code> as a <code>float</code>.
+   **/
+  public float floatValue()
   {
     return value;
   }
 
-  public String toString()
+  /** Return the value of this <code>Short</code> as a <code>double</code>.
+   ** @return the value of this <code>Short</code> as a <code>double</code>.
+   **/
+  public double doubleValue()
   {
-    return Integer.toString((int) value);
+    return value;
   }
 
-  public static String toString(short value)
+  /**
+   * Compare two Shorts numerically by comparing their
+   * <code>short</code> values.
+   * @return a positive value if this <code>Short</code> is greater
+   * in value than the argument <code>Short</code>; a negative value
+   * if this <code>Short</code> is smaller in value than the argument
+   * <code>Short</code>; and <code>0</code>, zero, if this
+   * <code>Short</code> is equal in value to the argument
+   * <code>Short</code>.  
+   *
+   * @since 1.2
+   */
+  public int compareTo(Short s)
+  {
+    return value - s.value;
+  }
+    
+  /**
+   * Behaves like <code>compareTo(java.lang.Short)</code> unless the Object
+   * is not a <code>Short</code>.  Then it throws a 
+   * <code>ClassCastException</code>.
+   * @exception ClassCastException if the argument is not a
+   * <code>Short</code>.
+   *
+   * @since 1.2
+   */
+  public int compareTo(Object o)
   {
-    return Integer.toString((int) value);
+    return compareTo((Short)o);
   }
 }



More information about the Java-patches mailing list