Hi,
I merged a few things from the generics branch to the trunk.
Regards,
Jeroen
2006-04-17 Jeroen Frijters <[EMAIL PROTECTED]>
* java/lang/Boolean.java: Implemented Comparable.
* java/lang/ClassLoader.java
(getResources): Not final anymore in 1.5.
* java/lang/Enum.java, java/lang/Iterable.java:
Copied from generics branch.
* java/lang/Thread.java (destroy): Marked deprecated.
* java/lang/ThreadLocal.java (remove): New method.
Index: java/lang/Boolean.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Boolean.java,v
retrieving revision 1.24
diff -u -r1.24 Boolean.java
--- java/lang/Boolean.java 7 Nov 2005 17:02:19 -0000 1.24
+++ java/lang/Boolean.java 17 Apr 2006 10:09:27 -0000
@@ -1,5 +1,5 @@
/* Boolean.java -- object wrapper for boolean
- Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -47,9 +47,9 @@
* @author Paul Fisher
* @author Eric Blake ([EMAIL PROTECTED])
* @since 1.0
- * @status updated to 1.4
+ * @status updated to 1.5
*/
-public final class Boolean implements Serializable
+public final class Boolean implements Serializable, Comparable
{
/**
* Compatible with JDK 1.0.2+.
@@ -223,34 +223,37 @@
}
/**
- * If the String argument is "true", ignoring case, return true.
- * Otherwise, return false.
+ * Compares this Boolean to another.
*
- * @param b String to parse
+ * @param b the Boolean to compare this Boolean to
+ * @return 0 if both Booleans represent the same value, a positive number
+ * if this Boolean represents true and the other false, and a negative
+ * number otherwise.
* @since 1.5
*/
- public static boolean parseBoolean(String b)
+ public int compareTo(Boolean other)
{
- return "true".equalsIgnoreCase(b) ? true : false;
+ return value == other.value ? 0 : (value ? 1 : -1);
}
-
+
/**
- * Compares this Boolean to another.
- * @param b the Boolean to compare this Boolean to
- * @return 0 if both Booleans represent the same value, a positive number
- * if this Boolean represents true and b represents false, or a negative
- * number otherwise.
+ * Bridge method
+ */
+ public int compareTo(Object other)
+ {
+ return compareTo((Boolean)other);
+ }
+
+ /**
+ * If the String argument is "true", ignoring case, return true.
+ * Otherwise, return false.
+ *
+ * @param b String to parse
* @since 1.5
*/
- public int compareTo (Boolean b)
+ public static boolean parseBoolean(String b)
{
- if (b == null)
- throw new NullPointerException("argument passed to compareTo(Boolean)
cannot be null");
-
- if (this.value == b.value)
- return 0;
- if (this.value == true)
- return 1;
- return -1;
+ return "true".equalsIgnoreCase(b) ? true : false;
}
+
}
Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.58
diff -u -r1.58 ClassLoader.java
--- java/lang/ClassLoader.java 21 Sep 2005 22:35:32 -0000 1.58
+++ java/lang/ClassLoader.java 17 Apr 2006 09:20:26 -0000
@@ -628,8 +628,9 @@
* @return an enumaration of all resources found
* @throws IOException if I/O errors occur in the process
* @since 1.2
+ * @specnote this was <code>final</code> prior to 1.5
*/
- public final Enumeration getResources(String name) throws IOException
+ public Enumeration getResources(String name) throws IOException
{
Enumeration parentResources;
if (parent == null)
Index: java/lang/Enum.java
===================================================================
RCS file: java/lang/Enum.java
diff -N java/lang/Enum.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/lang/Enum.java 17 Apr 2006 10:18:51 -0000
@@ -0,0 +1,146 @@
+/* Enum.java - Base class for all enums
+ Copyright (C) 2004, 2005 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.lang;
+
+import java.io.Serializable;
+import java.lang.reflect.Field;
+
+/**
+ * @since 1.5
+ */
+public abstract class Enum
+ implements Comparable, Serializable
+{
+
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = -4300926546619394005L;
+
+ String name;
+ int ordinal;
+
+ protected Enum(String name, int ordinal)
+ {
+ this.name = name;
+ this.ordinal = ordinal;
+ }
+
+ /**
+ * Returns an Enum for a enum class given a description string of
+ * the enum constant.
+ *
+ * @exception NullPointerException when etype or s are null.
+ * @exception IllegalArgumentException when there is no value s in
+ * the enum etype.
+ */
+ public static Enum valueOf(Class etype, String s)
+ {
+ if (etype == null || s == null)
+ throw new NullPointerException();
+
+ try
+ {
+ Field f = etype.getDeclaredField(s);
+ if (! f.isEnumConstant())
+ throw new IllegalArgumentException(s);
+ return (Enum) f.get(null);
+ }
+ catch (NoSuchFieldException exception)
+ {
+ throw new IllegalArgumentException(s);
+ }
+ catch (IllegalAccessException exception)
+ {
+ throw new Error("Unable to access Enum class");
+ }
+ }
+
+ public final boolean equals(Object o)
+ {
+ // Enum constants are singular, so we need only compare `=='.
+ return this == o;
+ }
+
+ public final int hashCode()
+ {
+ return ordinal;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+
+ public final int compareTo(Enum e)
+ {
+ if (getDeclaringClass() != e.getDeclaringClass())
+ throw new ClassCastException();
+ return ordinal - e.ordinal;
+ }
+
+ public final int compareTo(Object o)
+ {
+ return compareTo((Enum)o);
+ }
+
+ protected final Object clone() throws CloneNotSupportedException
+ {
+ throw new CloneNotSupportedException("can't clone an enum constant");
+ }
+
+ public final String name()
+ {
+ return name;
+ }
+
+ public final int ordinal()
+ {
+ return ordinal;
+ }
+
+ public final Class getDeclaringClass()
+ {
+ Class k = getClass();
+ // We might be in an anonymous subclass of the enum class, so go
+ // up one more level.
+ if (k.getSuperclass() != Enum.class)
+ k = k.getSuperclass();
+ return k;
+ }
+}
Index: java/lang/Iterable.java
===================================================================
RCS file: java/lang/Iterable.java
diff -N java/lang/Iterable.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/lang/Iterable.java 17 Apr 2006 10:15:40 -0000
@@ -0,0 +1,59 @@
+/* Iterable.java -- Notes collection over which one may iterate
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.lang;
+
+import java.util.Iterator;
+
+/**
+ * This interface is used to indicate that a given class can be
+ * iterated over. The compiler uses this interface to determine which
+ * classes are suitable targets of the <code>foreach</code> construct.
+ *
+ * @author Tom Tromey <[EMAIL PROTECTED]>
+ * @since 1.5
+ */
+public interface Iterable
+{
+ /**
+ * Returns an iterator for the collection.
+ *
+ * @return an iterator.
+ */
+ Iterator iterator ();
+}
Index: java/lang/Thread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.20
diff -u -r1.20 Thread.java
--- java/lang/Thread.java 14 Apr 2006 07:51:42 -0000 1.20
+++ java/lang/Thread.java 17 Apr 2006 09:19:08 -0000
@@ -457,6 +457,19 @@
/**
* Originally intended to destroy this thread, this method was never
* implemented by Sun, and is hence a no-op.
+ *
+ * @deprecated This method was originally intended to simply destroy
+ * the thread without performing any form of cleanup operation.
+ * However, it was never implemented. It is now deprecated
+ * for the same reason as <code>suspend()</code>,
+ * <code>stop()</code> and <code>resume()</code>; namely,
+ * it is prone to deadlocks. If a thread is destroyed while
+ * it still maintains a lock on a resource, then this resource
+ * will remain locked and any attempts by other threads to
+ * access the resource will result in a deadlock. Thus, even
+ * an implemented version of this method would be still be
+ * deprecated, due to its unsafe nature.
+ * @throws NoSuchMethodError as this method was never implemented.
*/
public void destroy()
{
Index: java/lang/ThreadLocal.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ThreadLocal.java,v
retrieving revision 1.9
diff -u -r1.9 ThreadLocal.java
--- java/lang/ThreadLocal.java 6 Jan 2006 15:05:57 -0000 1.9
+++ java/lang/ThreadLocal.java 17 Apr 2006 10:16:47 -0000
@@ -152,4 +152,15 @@
// ever modify the map.
map.put(this, value == null ? NULL : value);
}
+
+ /**
+ * Removes the value associated with the ThreadLocal object for the
+ * currently executing Thread.
+ * @since 1.5
+ */
+ public void remove()
+ {
+ Map map = Thread.getThreadLocals();
+ map.remove(this);
+ }
}