Merged gcj-eclipse branch to trunk.

From-SVN: r120621
This commit is contained in:
Tom Tromey
2007-01-09 19:58:05 +00:00
parent c648dedbde
commit 97b8365caf
17478 changed files with 606493 additions and 100744 deletions
+4 -12
View File
@@ -1,5 +1,5 @@
/* Boolean.java -- object wrapper for boolean
Copyright (C) 1998, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,7 +49,7 @@ import java.io.Serializable;
* @since 1.0
* @status updated to 1.5
*/
public final class Boolean implements Serializable, Comparable
public final class Boolean implements Serializable, Comparable<Boolean>
{
/**
* Compatible with JDK 1.0.2+.
@@ -78,7 +78,7 @@ public final class Boolean implements Serializable, Comparable
*
* @since 1.1
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('Z');
public static final Class<Boolean> TYPE = (Class<Boolean>) VMClassLoader.getPrimitiveClass('Z');
/**
* The immutable value of this Boolean.
@@ -236,14 +236,6 @@ public final class Boolean implements Serializable, Comparable
return value == other.value ? 0 : (value ? 1 : -1);
}
/**
* Bridge method
*/
public int compareTo(Object other)
{
return compareTo((Boolean)other);
}
/**
* If the String argument is "true", ignoring case, return true.
* Otherwise, return false.
@@ -255,5 +247,5 @@ public final class Boolean implements Serializable, Comparable
{
return "true".equalsIgnoreCase(b) ? true : false;
}
}
+10 -24
View File
@@ -1,5 +1,5 @@
/* Byte.java -- object wrapper for byte
Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author John Keiser
* @author Per Bothner
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.1
* @status updated to 1.5
*/
public final class Byte extends Number implements Comparable
public final class Byte extends Number implements Comparable<Byte>
{
/**
* Compatible with JDK 1.1+.
@@ -75,7 +77,7 @@ public final class Byte extends Number implements Comparable
* The primitive type <code>byte</code> is represented by this
* <code>Class</code> object.
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('B');
public static final Class<Byte> TYPE = (Class<Byte>) VMClassLoader.getPrimitiveClass('B');
/**
* The number of bits needed to represent a <code>byte</code>.
@@ -87,6 +89,7 @@ public final class Byte extends Number implements Comparable
// valueOf(). We're required to cache all possible values here.
private static Byte[] byteCache = new Byte[MAX_VALUE - MIN_VALUE + 1];
/**
* The immutable value of this Byte.
*
@@ -208,20 +211,18 @@ public final class Byte extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Byte</code>
*
* @since 1.5
*/
public static Byte valueOf(byte val)
{
synchronized (byteCache)
{
if (byteCache[val - MIN_VALUE] == null)
byteCache[val - MIN_VALUE] = new Byte(val);
return byteCache[val - MIN_VALUE];
if (byteCache[val - MIN_VALUE] == null)
byteCache[val - MIN_VALUE] = new Byte(val);
return byteCache[val - MIN_VALUE];
}
}
/**
/**
* Convert the specified <code>String</code> into a <code>Byte</code>.
* The <code>String</code> may represent decimal, hexadecimal, or
* octal numbers.
@@ -369,19 +370,4 @@ public final class Byte extends Number implements Comparable
return value - b.value;
}
/**
* Behaves like <code>compareTo(Byte)</code> unless the Object
* is not a <code>Byte</code>.
*
* @param o the object to compare
* @return the comparison
* @throws ClassCastException if the argument is not a <code>Byte</code>
* @see #compareTo(Byte)
* @see Comparable
* @since 1.2
*/
public int compareTo(Object o)
{
return compareTo((Byte) o);
}
}
+113 -133
View File
@@ -1,5 +1,5 @@
/* java.lang.Character -- Wrapper class for char, and Unicode subsets
Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -65,11 +65,12 @@ import java.util.Locale;
* @author Paul N. Fisher
* @author Jochen Hoenicke
* @author Eric Blake (ebb9@email.byu.edu)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see CharData
* @since 1.0
* @status updated to 1.4
* @status partly updated to 1.5; some things still missing
*/
public final class Character implements Serializable, Comparable
public final class Character implements Serializable, Comparable<Character>
{
/**
* A subset of Unicode blocks.
@@ -154,10 +155,8 @@ public final class Character implements Serializable, Comparable
/** The canonical name of the block according to the Unicode standard. */
private final String canonicalName;
/** Constants for the <code>forName()</code> method */
private static final int CANONICAL_NAME = 0;
private static final int NO_SPACES_NAME = 1;
private static final int CONSTANT_NAME = 2;
/** Enumeration for the <code>forName()</code> method */
private enum NameType { CANONICAL, NO_SPACES, CONSTANT; };
/**
* Constructor for strictly defined blocks.
@@ -169,7 +168,7 @@ public final class Character implements Serializable, Comparable
* standard.
*/
private UnicodeBlock(int start, int end, String name,
String canonicalName)
String canonicalName)
{
super(name);
this.start = start;
@@ -203,8 +202,8 @@ public final class Character implements Serializable, Comparable
public static UnicodeBlock of(int codePoint)
{
if (codePoint > MAX_CODE_POINT)
throw new IllegalArgumentException("The supplied integer value is " +
"too large to be a codepoint.");
throw new IllegalArgumentException("The supplied integer value is " +
"too large to be a codepoint.");
// Simple binary search for the correct block.
int low = 0;
int hi = sets.length - 1;
@@ -258,59 +257,51 @@ public final class Character implements Serializable, Comparable
*/
public static final UnicodeBlock forName(String blockName)
{
int type;
NameType type;
if (blockName.indexOf(' ') != -1)
type = CANONICAL_NAME;
type = NameType.CANONICAL;
else if (blockName.indexOf('_') != -1)
type = CONSTANT_NAME;
type = NameType.CONSTANT;
else
type = NO_SPACES_NAME;
type = NameType.NO_SPACES;
Collator usCollator = Collator.getInstance(Locale.US);
usCollator.setStrength(Collator.PRIMARY);
/* Special case for deprecated blocks not in sets */
switch (type)
{
case CANONICAL_NAME:
case CANONICAL:
if (usCollator.compare(blockName, "Surrogates Area") == 0)
return SURROGATES_AREA;
break;
case NO_SPACES_NAME:
case NO_SPACES:
if (usCollator.compare(blockName, "SurrogatesArea") == 0)
return SURROGATES_AREA;
break;
case CONSTANT_NAME:
case CONSTANT:
if (usCollator.compare(blockName, "SURROGATES_AREA") == 0)
return SURROGATES_AREA;
break;
}
/* Other cases */
int setLength = sets.length;
switch (type)
{
case CANONICAL_NAME:
for (int i = 0; i < setLength; i++)
{
UnicodeBlock block = sets[i];
if (usCollator.compare(blockName, block.canonicalName) == 0)
return block;
}
case CANONICAL:
for (UnicodeBlock block : sets)
if (usCollator.compare(blockName, block.canonicalName) == 0)
return block;
break;
case NO_SPACES_NAME:
for (int i = 0; i < setLength; i++)
{
UnicodeBlock block = sets[i];
String nsName = block.canonicalName.replaceAll(" ","");
if (usCollator.compare(blockName, nsName) == 0)
return block;
}
break;
case CONSTANT_NAME:
for (int i = 0; i < setLength; i++)
{
UnicodeBlock block = sets[i];
if (usCollator.compare(blockName, block.toString()) == 0)
return block;
}
case NO_SPACES:
for (UnicodeBlock block : sets)
{
String nsName = block.canonicalName.replaceAll(" ","");
if (usCollator.compare(blockName, nsName) == 0)
return block;
}
break;
case CONSTANT:
for (UnicodeBlock block : sets)
if (usCollator.compare(blockName, block.toString()) == 0)
return block;
break;
}
throw new IllegalArgumentException("No Unicode block found for " +
@@ -1513,10 +1504,11 @@ public final class Character implements Serializable, Comparable
* this. These are also returned from calls to <code>of(int)</code>
* and <code>of(char)</code>.
*/
@Deprecated
public static final UnicodeBlock SURROGATES_AREA
= new UnicodeBlock(0xD800, 0xDFFF,
"SURROGATES_AREA",
"Surrogates Area");
"Surrogates Area");
/**
* The defined subsets.
@@ -1978,12 +1970,79 @@ public final class Character implements Serializable, Comparable
*/
public static final char MAX_VALUE = '\uFFFF';
/**
* The minimum Unicode 4.0 code point. This value is <code>0</code>.
* @since 1.5
*/
public static final int MIN_CODE_POINT = 0;
/**
* The maximum Unicode 4.0 code point, which is greater than the range
* of the char data type.
* This value is <code>0x10FFFF</code>.
* @since 1.5
*/
public static final int MAX_CODE_POINT = 0x10FFFF;
/**
* The minimum Unicode high surrogate code unit, or
* <emph>leading-surrogate</emph>, in the UTF-16 character encoding.
* This value is <code>'\uD800'</code>.
* @since 1.5
*/
public static final char MIN_HIGH_SURROGATE = '\uD800';
/**
* The maximum Unicode high surrogate code unit, or
* <emph>leading-surrogate</emph>, in the UTF-16 character encoding.
* This value is <code>'\uDBFF'</code>.
* @since 1.5
*/
public static final char MAX_HIGH_SURROGATE = '\uDBFF';
/**
* The minimum Unicode low surrogate code unit, or
* <emph>trailing-surrogate</emph>, in the UTF-16 character encoding.
* This value is <code>'\uDC00'</code>.
* @since 1.5
*/
public static final char MIN_LOW_SURROGATE = '\uDC00';
/**
* The maximum Unicode low surrogate code unit, or
* <emph>trailing-surrogate</emph>, in the UTF-16 character encoding.
* This value is <code>'\uDFFF'</code>.
* @since 1.5
*/
public static final char MAX_LOW_SURROGATE = '\uDFFF';
/**
* The minimum Unicode surrogate code unit in the UTF-16 character encoding.
* This value is <code>'\uD800'</code>.
* @since 1.5
*/
public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
/**
* The maximum Unicode surrogate code unit in the UTF-16 character encoding.
* This value is <code>'\uDFFF'</code>.
* @since 1.5
*/
public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
/**
* The lowest possible supplementary Unicode code point (the first code
* point outside the basic multilingual plane (BMP)).
* This value is <code>0x10000</code>.
*/
public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
/**
* Class object representing the primitive char data type.
*
* @since 1.1
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('C');
public static final Class<Character> TYPE = (Class<Character>) VMClassLoader.getPrimitiveClass('C');
/**
* The number of bits needed to represent a <code>char</code>.
@@ -2378,7 +2437,7 @@ public final class Character implements Serializable, Comparable
* Stores unicode attribute offset lookup table. Exploit package visibility
* of String.value to avoid copying the array.
* @see CharData#DATA
*/
*/
private static final char[][] data =
new char[][]{
String.zeroBasedStringValue(CharData.DATA[0]),
@@ -2527,71 +2586,6 @@ public final class Character implements Serializable, Comparable
*/
private static final int MIRROR_MASK = 0x40;
/**
* Min value for supplementary code point.
*
* @since 1.5
*/
public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
/**
* Min value for code point.
*
* @since 1.5
*/
public static final int MIN_CODE_POINT = 0;
/**
* Max value for code point.
*
* @since 1.5
*/
public static final int MAX_CODE_POINT = 0x010ffff;
/**
* Minimum high surrogate code in UTF-16 encoding.
*
* @since 1.5
*/
public static final char MIN_HIGH_SURROGATE = '\ud800';
/**
* Maximum high surrogate code in UTF-16 encoding.
*
* @since 1.5
*/
public static final char MAX_HIGH_SURROGATE = '\udbff';
/**
* Minimum low surrogate code in UTF-16 encoding.
*
* @since 1.5
*/
public static final char MIN_LOW_SURROGATE = '\udc00';
/**
* Maximum low surrogate code in UTF-16 encoding.
*
* @since 1.5
*/
public static final char MAX_LOW_SURROGATE = '\udfff';
/**
* Minimum surrogate code in UTF-16 encoding.
*
* @since 1.5
*/
public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
/**
* Maximum low surrogate code in UTF-16 encoding.
*
* @since 1.5
*/
public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
/**
* Grabs an attribute offset from the Unicode attribute database. The lower
* 5 bits are the character type, the next 2 bits are flags, and the top
@@ -2605,6 +2599,7 @@ public final class Character implements Serializable, Comparable
* @see CharData#DATA
* @see CharData#SHIFT
*/
// Package visible for use in String.
static char readCodePoint(int codePoint)
{
int plane = codePoint >>> 16;
@@ -2778,7 +2773,7 @@ public final class Character implements Serializable, Comparable
{
return isTitleCase((int)ch);
}
/**
* Determines if a character is a Unicode titlecase letter. For example,
* the character "Lj" (Latin capital L with small letter j) is titlecase.
@@ -3282,7 +3277,7 @@ public final class Character implements Serializable, Comparable
| (1 << CURRENCY_SYMBOL)
| (1 << CONNECTOR_PUNCTUATION))) != 0;
}
/**
* Determines if a character can follow the first letter in
* a Java identifier. This is the combination of isJavaLetter (isLetter,
@@ -3468,6 +3463,7 @@ public final class Character implements Serializable, Comparable
{
return isIdentifierIgnorable((int)ch);
}
/**
* Determines if a character is ignorable in a Unicode identifier. This
* includes the non-whitespace ISO control characters (<code>'\u0000'</code>
@@ -3610,7 +3606,7 @@ public final class Character implements Serializable, Comparable
return title[i + 1];
return toUpperCase(ch);
}
/**
* Converts a Unicode character into its titlecase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
@@ -4103,6 +4099,7 @@ public final class Character implements Serializable, Comparable
// The result will correctly be signed.
return getDirectionality((int)ch);
}
/**
* Returns the Unicode directionality property of the character. This
@@ -4197,23 +4194,6 @@ public final class Character implements Serializable, Comparable
return value - anotherCharacter.value;
}
/**
* Compares an object to this Character. Assuming the object is a
* Character object, this method performs the same comparison as
* compareTo(Character).
*
* @param o object to compare
* @return the comparison value
* @throws ClassCastException if o is not a Character object
* @throws NullPointerException if o is null
* @see #compareTo(Character)
* @since 1.2
*/
public int compareTo(Object o)
{
return compareTo((Character) o);
}
/**
* Returns an <code>Character</code> object wrapping the value.
* In contrast to the <code>Character</code> constructor, this method
@@ -4221,7 +4201,7 @@ public final class Character implements Serializable, Comparable
*
* @param val the value to wrap
* @return the <code>Character</code>
*
*
* @since 1.5
*/
public static Character valueOf(char val)
@@ -4230,9 +4210,9 @@ public final class Character implements Serializable, Comparable
return new Character(val);
synchronized (charCache)
{
if (charCache[val - MIN_VALUE] == null)
charCache[val - MIN_VALUE] = new Character(val);
return charCache[val - MIN_VALUE];
if (charCache[val - MIN_VALUE] == null)
charCache[val - MIN_VALUE] = new Character(val);
return charCache[val - MIN_VALUE];
}
}
+66 -70
View File
@@ -42,17 +42,14 @@ import gnu.classpath.VMStackWalker;
import gnu.java.lang.reflect.ClassSignatureParser;
import java.io.InputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.annotation.Inherited;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.GenericSignatureFormatError;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.MalformedParameterizedTypeException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -66,6 +63,7 @@ import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -97,11 +95,10 @@ import java.util.HashSet;
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @author Tom Tromey (tromey@cygnus.com)
* @since 1.0
* @see ClassLoader
*/
public final class Class
public final class Class<T>
implements Serializable, Type, AnnotatedElement, GenericDeclaration
{
/**
@@ -147,7 +144,7 @@ public final class Class
final transient Object vmdata;
/** newInstance() caches the default constructor */
private transient Constructor constructor;
private transient Constructor<T> constructor;
/**
* Class is non-instantiable from Java code; only the VM can create
@@ -184,7 +181,7 @@ public final class Class
* @throws ExceptionInInitializerError if the class loads, but an exception
* occurs during initialization
*/
public static Class forName(String name) throws ClassNotFoundException
public static Class<?> forName(String name) throws ClassNotFoundException
{
return VMClass.forName(name, true, VMStackWalker.getCallingClassLoader());
}
@@ -216,8 +213,8 @@ public final class Class
* @see ClassLoader
* @since 1.2
*/
public static Class forName(String name, boolean initialize,
ClassLoader classloader)
public static Class<?> forName(String name, boolean initialize,
ClassLoader classloader)
throws ClassNotFoundException
{
if (classloader == null)
@@ -232,7 +229,7 @@ public final class Class
sm.checkPermission(new RuntimePermission("getClassLoader"));
}
}
return VMClass.forName(name, initialize, classloader);
return (Class<?>) VMClass.forName(name, initialize, classloader);
}
/**
@@ -247,7 +244,7 @@ public final class Class
* @throws SecurityException if the security check fails
* @since 1.1
*/
public Class[] getClasses()
public Class<?>[] getClasses()
{
memberAccessCheck(Member.PUBLIC);
return internalGetClasses();
@@ -256,14 +253,14 @@ public final class Class
/**
* Like <code>getClasses()</code> but without the security checks.
*/
private Class[] internalGetClasses()
private Class<?>[] internalGetClasses()
{
ArrayList list = new ArrayList();
ArrayList<Class> list = new ArrayList<Class>();
list.addAll(Arrays.asList(getDeclaredClasses(true)));
Class superClass = getSuperclass();
if (superClass != null)
list.addAll(Arrays.asList(superClass.internalGetClasses()));
return (Class[])list.toArray(new Class[list.size()]);
return list.toArray(new Class<?>[list.size()]);
}
/**
@@ -307,7 +304,7 @@ public final class Class
* @see Array
* @since 1.1
*/
public Class getComponentType()
public Class<?> getComponentType()
{
return VMClass.getComponentType (this);
}
@@ -326,7 +323,8 @@ public final class Class
* @see #getConstructors()
* @since 1.1
*/
public Constructor getConstructor(Class[] types) throws NoSuchMethodException
public Constructor<T> getConstructor(Class<?>... types)
throws NoSuchMethodException
{
memberAccessCheck(Member.PUBLIC);
Constructor[] constructors = getDeclaredConstructors(true);
@@ -351,7 +349,7 @@ public final class Class
* @throws SecurityException if the security check fails
* @since 1.1
*/
public Constructor[] getConstructors()
public Constructor<?>[] getConstructors()
{
memberAccessCheck(Member.PUBLIC);
return getDeclaredConstructors(true);
@@ -371,7 +369,7 @@ public final class Class
* @see #getDeclaredConstructors()
* @since 1.1
*/
public Constructor getDeclaredConstructor(Class[] types)
public Constructor<T> getDeclaredConstructor(Class<?>... types)
throws NoSuchMethodException
{
memberAccessCheck(Member.DECLARED);
@@ -397,13 +395,13 @@ public final class Class
* @throws SecurityException if the security check fails
* @since 1.1
*/
public Class[] getDeclaredClasses()
public Class<?>[] getDeclaredClasses()
{
memberAccessCheck(Member.DECLARED);
return getDeclaredClasses(false);
}
Class[] getDeclaredClasses (boolean publicOnly)
Class<?>[] getDeclaredClasses (boolean publicOnly)
{
return VMClass.getDeclaredClasses (this, publicOnly);
}
@@ -420,13 +418,13 @@ public final class Class
* @throws SecurityException if the security check fails
* @since 1.1
*/
public Constructor[] getDeclaredConstructors()
public Constructor<?>[] getDeclaredConstructors()
{
memberAccessCheck(Member.DECLARED);
return getDeclaredConstructors(false);
}
Constructor[] getDeclaredConstructors (boolean publicOnly)
Constructor<?>[] getDeclaredConstructors (boolean publicOnly)
{
return VMClass.getDeclaredConstructors (this, publicOnly);
}
@@ -500,7 +498,7 @@ public final class Class
* @see #getDeclaredMethods()
* @since 1.1
*/
public Method getDeclaredMethod(String methodName, Class[] types)
public Method getDeclaredMethod(String methodName, Class<?>... types)
throws NoSuchMethodException
{
memberAccessCheck(Member.DECLARED);
@@ -544,7 +542,7 @@ public final class Class
* @return the declaring class of this class
* @since 1.1
*/
public Class getDeclaringClass()
public Class<?> getDeclaringClass()
{
return VMClass.getDeclaringClass (this);
}
@@ -597,7 +595,7 @@ public final class Class
*/
private Field[] internalGetFields()
{
HashSet set = new HashSet();
HashSet<Field> set = new HashSet<Field>();
set.addAll(Arrays.asList(getDeclaredFields(true)));
Class[] interfaces = getInterfaces();
for (int i = 0; i < interfaces.length; i++)
@@ -605,7 +603,7 @@ public final class Class
Class superClass = getSuperclass();
if (superClass != null)
set.addAll(Arrays.asList(superClass.internalGetFields()));
return (Field[])set.toArray(new Field[set.size()]);
return set.toArray(new Field[set.size()]);
}
/**
@@ -633,7 +631,7 @@ public final class Class
*
* @return the interfaces this class directly implements
*/
public Class[] getInterfaces()
public Class<?>[] getInterfaces()
{
return VMClass.getInterfaces (this);
}
@@ -663,7 +661,7 @@ public final class Class
{
MethodKey m = (MethodKey) o;
if (m.name.equals(name) && m.params.length == params.length
&& m.returnType == returnType)
&& m.returnType == returnType)
{
for (int i = 0; i < params.length; i++)
{
@@ -704,7 +702,7 @@ public final class Class
* @see #getMethods()
* @since 1.1
*/
public Method getMethod(String methodName, Class[] types)
public Method getMethod(String methodName, Class<?>... types)
throws NoSuchMethodException
{
memberAccessCheck(Member.PUBLIC);
@@ -821,7 +819,7 @@ public final class Class
*/
private Method[] internalGetMethods()
{
HashMap map = new HashMap();
HashMap<MethodKey,Method> map = new HashMap<MethodKey,Method>();
Method[] methods;
Class[] interfaces = getInterfaces();
for(int i = 0; i < interfaces.length; i++)
@@ -846,7 +844,7 @@ public final class Class
{
map.put(new MethodKey(methods[i]), methods[i]);
}
return (Method[])map.values().toArray(new Method[map.size()]);
return map.values().toArray(new Method[map.size()]);
}
/**
@@ -1003,7 +1001,7 @@ public final class Class
*
* @return the direct superclass of this class
*/
public Class getSuperclass()
public Class<? super T> getSuperclass()
{
return VMClass.getSuperclass (this);
}
@@ -1033,7 +1031,7 @@ public final class Class
* @throws NullPointerException if c is null
* @since 1.1
*/
public boolean isAssignableFrom(Class c)
public boolean isAssignableFrom(Class<?> c)
{
return VMClass.isAssignableFrom (this, c);
}
@@ -1103,11 +1101,11 @@ public final class Class
* @throws ExceptionInInitializerError if class initialization caused by
* this call fails with an exception
*/
public Object newInstance()
public T newInstance()
throws InstantiationException, IllegalAccessException
{
memberAccessCheck(Member.PUBLIC);
Constructor constructor;
Constructor<T> constructor;
synchronized(this)
{
constructor = this.constructor;
@@ -1307,12 +1305,11 @@ public final class Class
* type, <code>U</code>.
* @since 1.5
*/
/* FIXME[GENERICS]: Should be <U> Class<? extends U> asSubClass(Class<U> klass */
public Class asSubclass(Class klass)
public <U> Class<? extends U> asSubclass(Class<U> klass)
{
if (! klass.isAssignableFrom(this))
throw new ClassCastException();
return this; /* FIXME[GENERICS]: Should cast to Class<? extends U> */
return (Class<? extends U>) this;
}
/**
@@ -1322,12 +1319,11 @@ public final class Class
* @throws ClassCastException if obj is not an instance of this class
* @since 1.5
*/
/* FIXME[GENERICS]: Should be T cast(Object obj) */
public Object cast(Object obj)
public T cast(Object obj)
{
if (obj != null && ! isInstance(obj))
throw new ClassCastException();
return obj; /* FIXME[GENERICS]: Should be cast to T */
return (T) obj;
}
/**
@@ -1395,15 +1391,13 @@ public final class Class
* class is not an <code>enum</code>.
* @since 1.5
*/
/* FIXME[GENERICS]: T[] getEnumConstants() */
public Object[] getEnumConstants()
public T[] getEnumConstants()
{
if (isEnum())
{
try
{
return (Object[])
getMethod("values", new Class[0]).invoke(null, new Object[0]);
return (T[]) getMethod("values").invoke(null);
}
catch (NoSuchMethodException exception)
{
@@ -1490,14 +1484,13 @@ public final class Class
* <code>null</code> if no such annotation exists.
* @since 1.5
*/
/* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
public Annotation getAnnotation(Class annotationClass)
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
{
Annotation foundAnnotation = null;
A foundAnnotation = null;
Annotation[] annotations = getAnnotations();
for (int i = 0; i < annotations.length; i++)
if (annotations[i].annotationType() == annotationClass)
foundAnnotation = annotations[i];
for (Annotation annotation : annotations)
if (annotation.annotationType() == annotationClass)
foundAnnotation = (A) annotation;
return foundAnnotation;
}
@@ -1514,15 +1507,22 @@ public final class Class
*/
public Annotation[] getAnnotations()
{
HashSet set = new HashSet();
set.addAll(Arrays.asList(getDeclaredAnnotations()));
Class[] interfaces = getInterfaces();
for (int i = 0; i < interfaces.length; i++)
set.addAll(Arrays.asList(interfaces[i].getAnnotations()));
Class superClass = getSuperclass();
if (superClass != null)
set.addAll(Arrays.asList(superClass.getAnnotations()));
return (Annotation[]) set.toArray(new Annotation[set.size()]);
HashMap<Class, Annotation> map = new HashMap<Class, Annotation>();
for (Annotation a : getDeclaredAnnotations())
map.put((Class) a.annotationType(), a);
for (Class<? super T> s = getSuperclass();
s != null;
s = s.getSuperclass())
{
for (Annotation a : s.getDeclaredAnnotations())
{
Class k = (Class) a.annotationType();
if (! map.containsKey(k) && k.isAnnotationPresent(Inherited.class))
map.put(k, a);
}
}
Collection<Annotation> v = map.values();
return v.toArray(new Annotation[v.size()]);
}
/**
@@ -1588,8 +1588,7 @@ public final class Class
* a top-level class.
* @since 1.5
*/
/* FIXME[GENERICS]: Should return Class<?> */
public Class getEnclosingClass()
public Class<?> getEnclosingClass()
{
return VMClass.getEnclosingClass(this);
}
@@ -1605,8 +1604,7 @@ public final class Class
* is returned.
* @since 1.5
*/
/* FIXME[GENERICS]: Should return Constructor<?> */
public Constructor getEnclosingConstructor()
public Constructor<?> getEnclosingConstructor()
{
return VMClass.getEnclosingConstructor(this);
}
@@ -1731,12 +1729,11 @@ public final class Class
* specification, version 3.
* @since 1.5
*/
/* FIXME[GENERICS]: Should return TypeVariable<Class<T>> */
public TypeVariable[] getTypeParameters()
public TypeVariable<Class<T>>[] getTypeParameters()
{
String sig = VMClass.getClassSignature(this);
if (sig == null)
return new TypeVariable[0];
return (TypeVariable<Class<T>>[])new TypeVariable[0];
ClassSignatureParser p = new ClassSignatureParser(this, sig);
return p.getTypeParameters();
@@ -1751,8 +1748,7 @@ public final class Class
* @return true if an annotation exists for the specified type.
* @since 1.5
*/
/* FIXME[GENERICS]: Should be Class<? extends Annotation> */
public boolean isAnnotationPresent(Class
public boolean isAnnotationPresent(Class<? extends Annotation>
annotationClass)
{
return getAnnotation(annotationClass) != null;
+36 -35
View File
@@ -120,7 +120,6 @@ import java.util.StringTokenizer;
* @author Eric Blake (ebb9@email.byu.edu)
* @see Class
* @since 1.0
* @status still missing 1.4 functionality
*/
public abstract class ClassLoader
{
@@ -128,7 +127,7 @@ public abstract class ClassLoader
* All packages defined by this classloader. It is not private in order to
* allow native code (and trusted subclasses) access to this field.
*/
final HashMap definedPackages = new HashMap();
final HashMap<String, Package> definedPackages = new HashMap<String, Package>();
/**
* The classloader that is consulted before this classloader.
@@ -227,7 +226,7 @@ public abstract class ClassLoader
* by the null key. This map must be synchronized on this instance.
*/
// Package visible for use by Class.
Map packageAssertionStatus;
Map<String, Boolean> packageAssertionStatus;
/**
* The map of class assertion status overrides, or null if no class
@@ -236,7 +235,7 @@ public abstract class ClassLoader
* instance.
*/
// Package visible for use by Class.
Map classAssertionStatus;
Map<String, Boolean> classAssertionStatus;
/**
* VM private data.
@@ -289,7 +288,7 @@ public abstract class ClassLoader
* @return the loaded class
* @throws ClassNotFoundException if the class cannot be found
*/
public Class loadClass(String name) throws ClassNotFoundException
public Class<?> loadClass(String name) throws ClassNotFoundException
{
return loadClass(name, false);
}
@@ -314,11 +313,11 @@ public abstract class ClassLoader
* @return the loaded class
* @throws ClassNotFoundException if the class cannot be found
*/
protected synchronized Class loadClass(String name, boolean resolve)
protected synchronized Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
// Have we already loaded this class?
Class c = findLoadedClass(name);
Class<?> c = findLoadedClass(name);
if (c == null)
{
// Can the class be loaded by a parent?
@@ -335,11 +334,11 @@ public abstract class ClassLoader
return parent.loadClass(name, resolve);
}
}
catch (ClassNotFoundException e)
catch (ClassNotFoundException e)
{
}
// Still not found, we have to do it ourself.
c = findClass(name);
// Still not found, we have to do it ourself.
c = findClass(name);
}
if (resolve)
resolveClass(c);
@@ -388,7 +387,7 @@ public abstract class ClassLoader
* @throws ClassNotFoundException when the class can not be found
* @since 1.2
*/
protected Class findClass(String name) throws ClassNotFoundException
protected Class<?> findClass(String name) throws ClassNotFoundException
{
throw new ClassNotFoundException(name);
}
@@ -406,7 +405,7 @@ public abstract class ClassLoader
* offset + len exceeds data
* @deprecated use {@link #defineClass(String, byte[], int, int)} instead
*/
protected final Class defineClass(byte[] data, int offset, int len)
protected final Class<?> defineClass(byte[] data, int offset, int len)
throws ClassFormatError
{
return defineClass(null, data, offset, len);
@@ -431,8 +430,8 @@ public abstract class ClassLoader
* @throws SecurityException if name starts with "java."
* @since 1.1
*/
protected final Class defineClass(String name, byte[] data, int offset,
int len) throws ClassFormatError
protected final Class<?> defineClass(String name, byte[] data, int offset,
int len) throws ClassFormatError
{
return defineClass(name, data, offset, len, null);
}
@@ -460,9 +459,9 @@ public abstract class ClassLoader
* do not match up
* @since 1.2
*/
protected final synchronized Class defineClass(String name, byte[] data,
int offset, int len,
ProtectionDomain domain)
protected final synchronized Class<?> defineClass(String name, byte[] data,
int offset, int len,
ProtectionDomain domain)
throws ClassFormatError
{
checkInitialized();
@@ -493,8 +492,8 @@ public abstract class ClassLoader
* do not match up
* @since 1.5
*/
protected final Class defineClass(String name, ByteBuffer buf,
ProtectionDomain domain)
protected final Class<?> defineClass(String name, ByteBuffer buf,
ProtectionDomain domain)
throws ClassFormatError
{
byte[] data = new byte[buf.remaining()];
@@ -510,7 +509,7 @@ public abstract class ClassLoader
* @throws NullPointerException if c is null
* @throws LinkageError if linking fails
*/
protected final void resolveClass(Class c)
protected final void resolveClass(Class<?> c)
{
checkInitialized();
VMClassLoader.resolveClass(c);
@@ -525,7 +524,7 @@ public abstract class ClassLoader
* @return the found class
* @throws ClassNotFoundException if the class cannot be found
*/
protected final Class findSystemClass(String name)
protected final Class<?> findSystemClass(String name)
throws ClassNotFoundException
{
checkInitialized();
@@ -563,7 +562,7 @@ public abstract class ClassLoader
* @param signers the signers to set
* @since 1.1
*/
protected final void setSigners(Class c, Object[] signers)
protected final void setSigners(Class<?> c, Object[] signers)
{
checkInitialized();
c.setSigners(signers);
@@ -576,7 +575,7 @@ public abstract class ClassLoader
* @return the found Class, or null if it is not found
* @since 1.1
*/
protected final synchronized Class findLoadedClass(String name)
protected final synchronized Class<?> findLoadedClass(String name)
{
checkInitialized();
return VMClassLoader.findLoadedClass(this, name);
@@ -631,14 +630,14 @@ public abstract class ClassLoader
* @since 1.2
* @specnote this was <code>final</code> prior to 1.5
*/
public Enumeration getResources(String name) throws IOException
public Enumeration<URL> getResources(String name) throws IOException
{
Enumeration parentResources;
Enumeration<URL> parentResources;
if (parent == null)
parentResources = VMClassLoader.getResources(name);
else
parentResources = parent.getResources(name);
return new DoubleEnumeration(parentResources, findResources(name));
return new DoubleEnumeration<URL>(parentResources, findResources(name));
}
/**
@@ -658,9 +657,9 @@ public abstract class ClassLoader
* @throws IOException if I/O errors occur in the process
* @since 1.2
*/
protected Enumeration findResources(String name) throws IOException
protected Enumeration<URL> findResources(String name) throws IOException
{
return EmptyEnumeration.getInstance();
return (Enumeration<URL>) EmptyEnumeration.getInstance();
}
/**
@@ -705,7 +704,8 @@ public abstract class ClassLoader
* @throws IOException if I/O errors occur in the process
* @since 1.2
*/
public static Enumeration getSystemResources(String name) throws IOException
public static Enumeration<URL> getSystemResources(String name)
throws IOException
{
return StaticData.systemClassLoader.getResources(name);
}
@@ -865,7 +865,7 @@ public abstract class ClassLoader
{
synchronized (definedPackages)
{
p = (Package) definedPackages.get(name);
p = definedPackages.get(name);
}
}
return p;
@@ -955,7 +955,7 @@ public abstract class ClassLoader
{
if (packageAssertionStatus == null)
packageAssertionStatus
= new HashMap(StaticData.systemPackageAssertionStatus);
= new HashMap<String, Boolean>(StaticData.systemPackageAssertionStatus);
packageAssertionStatus.put(name, Boolean.valueOf(enabled));
}
@@ -975,8 +975,8 @@ public abstract class ClassLoader
boolean enabled)
{
if (classAssertionStatus == null)
classAssertionStatus =
new HashMap(StaticData.systemClassAssertionStatus);
classAssertionStatus
= new HashMap<String, Boolean>(StaticData.systemClassAssertionStatus);
// The toString() hack catches null, as required.
classAssertionStatus.put(name.toString(), Boolean.valueOf(enabled));
}
@@ -994,8 +994,8 @@ public abstract class ClassLoader
public synchronized void clearAssertionStatus()
{
defaultAssertionStatus = false;
packageAssertionStatus = new HashMap();
classAssertionStatus = new HashMap();
packageAssertionStatus = null;
classAssertionStatus = null;
}
/**
@@ -1147,4 +1147,5 @@ public abstract class ClassLoader
if (! initialized)
throw new SecurityException("attempt to use uninitialized class loader");
}
}
+4 -4
View File
@@ -1,5 +1,5 @@
/* Comparable.java -- Interface for comparaing objects to obtain an ordering
Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -66,9 +66,9 @@ package java.lang;
* @see java.util.TreeSet
* @see java.util.TreeMap
* @since 1.2
* @status updated to 1.4
* @status updated to 1.5
*/
public interface Comparable
public interface Comparable<T>
{
/**
* Compares this object with another, and returns a numerical result based
@@ -94,5 +94,5 @@ public interface Comparable
* @throws NullPointerException if o is null
* @throws ClassCastException if o cannot be compared
*/
int compareTo(Object o);
int compareTo(T o);
}
+1 -1
View File
@@ -74,7 +74,7 @@ public final class Compiler
* compilation failed, <code>true</code> if compilation succeeded
* @throws NullPointerException if oneClass is null
*/
public static boolean compileClass(Class oneClass)
public static boolean compileClass(Class<?> oneClass)
{
return VMCompiler.compileClass(oneClass);
}
@@ -0,0 +1,56 @@
/* Deprecated - Annotation to mark elements as deprecated
Copyright (C) 2004, 2005 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.lang.annotation.Documented;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* This annotation is used as a marker to indicate that the annotated
* declaration is deprecated and should not be used in new code.
* This replaces the old "@deprecated" javadoc tag.
*
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
@Documented @Retention(RUNTIME)
public @interface Deprecated
{
}
+6 -21
View File
@@ -1,5 +1,5 @@
/* Double.java -- object wrapper for double
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author Paul Fisher
* @author Andrew Haley (aph@cygnus.com)
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
* @status updated to 1.4
* @status partly updated to 1.5
*/
public final class Double extends Number implements Comparable
public final class Double extends Number implements Comparable<Double>
{
/**
* Compatible with JDK 1.0+.
@@ -98,7 +100,7 @@ public final class Double extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('D');
public static final Class<Double> TYPE = (Class<Double>) VMClassLoader.getPrimitiveClass('D');
/**
* The immutable value of this Double.
@@ -254,7 +256,6 @@ public final class Double extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Double</code>
*
* @since 1.5
*/
public static Double valueOf(double val)
@@ -574,22 +575,6 @@ public final class Double extends Number implements Comparable
return compare(value, d.value);
}
/**
* Behaves like <code>compareTo(Double)</code> unless the Object
* is not an <code>Double</code>.
*
* @param o the object to compare
* @return the comparison
* @throws ClassCastException if the argument is not a <code>Double</code>
* @see #compareTo(Double)
* @see Comparable
* @since 1.2
*/
public int compareTo(Object o)
{
return compare(value, ((Double) o).value);
}
/**
* Behaves like <code>new Double(x).compareTo(new Double(y))</code>; in
* other words this compares two doubles, special casing NaN and zero,
+9 -34
View File
@@ -48,10 +48,8 @@ import java.lang.reflect.Field;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
/* FIXME[GENERICS]: Should be Enum<T extends Enum<T>>
and Comparable<T> */
public abstract class Enum
implements Comparable, Serializable
public abstract class Enum<T extends Enum<T>>
implements Comparable<T>, Serializable
{
/**
@@ -62,13 +60,13 @@ public abstract class Enum
/**
* The name of this enum constant.
*/
String name;
final String name;
/**
* The number of this enum constant. Each constant is given a number
* which matches the order in which it was declared, starting with zero.
*/
int ordinal;
final int ordinal;
/**
* This constructor is used by the compiler to create enumeration constants.
@@ -91,8 +89,8 @@ public abstract class Enum
* @exception IllegalArgumentException when there is no value s in
* the enum etype.
*/
/* FIXME[GENERICS]: Should be <S extends Enum<S>> S valueOf(Class<S>) */
public static Enum valueOf(Class etype, String s)
@SuppressWarnings("unchecked")
public static <S extends Enum<S>> S valueOf(Class<S> etype, String s)
{
if (etype == null || s == null)
throw new NullPointerException();
@@ -102,8 +100,7 @@ public abstract class Enum
Field f = etype.getDeclaredField(s);
if (! f.isEnumConstant())
throw new IllegalArgumentException(s);
/* FIXME[GENERICS]: Should cast to S */
return (Enum) f.get(null);
return (S) f.get(null);
}
catch (NoSuchFieldException exception)
{
@@ -167,34 +164,13 @@ public abstract class Enum
* @throws ClassCastException if <code>e</code> is not an enumeration
* constant of the same class.
*/
public final int compareTo(Enum e)
public final int compareTo(T e)
{
if (getDeclaringClass() != e.getDeclaringClass())
throw new ClassCastException();
return ordinal - e.ordinal;
}
/**
* Returns an integer which represents the relative ordering of this
* enumeration constant. Enumeration constants are ordered by their
* ordinals, which represents their declaration order. So, comparing
* two identical constants yields zero, while one declared prior to
* this returns a positive integer and one declared after yields a
* negative integer.
*
* @param o the enumeration constant to compare.
* @return a negative integer if <code>e.ordinal < this.ordinal</code>,
* zero if <code>e.ordinal == this.ordinal</code> and a positive
* integer if <code>e.ordinal > this.ordinal</code>.
* @throws ClassCastException if <code>e</code> is not an enumeration
* constant of the same class.
*/
/* FIXME[GENERICS]: Remove this method */
public final int compareTo(Object o)
{
return compareTo((Enum)o);
}
/**
* Cloning of enumeration constants is prevented, to maintain their
* singleton status.
@@ -235,8 +211,7 @@ public abstract class Enum
*
* @return the type of this enumeration constant.
*/
/* FIXME[GENERICS]: Should return Class<T> */
public final Class getDeclaringClass()
public final Class<T> getDeclaringClass()
{
Class k = getClass();
// We might be in an anonymous subclass of the enum class, so go
@@ -54,7 +54,7 @@ public class EnumConstantNotPresentException extends RuntimeException
* The enum's type. Note that the name is fixed by the
* serialization spec.
*/
private Class enumType;
private Class<? extends Enum> enumType;
/**
* The name of the missing enum constant. Note that the name is
@@ -68,7 +68,8 @@ public class EnumConstantNotPresentException extends RuntimeException
* @param theEnum the enum's class
* @param name the name of the missing enum constant
*/
public EnumConstantNotPresentException(Class theEnum, String name)
public EnumConstantNotPresentException(Class<? extends Enum> theEnum,
String name)
{
super("enum " + theEnum + " is missing the constant " + name);
enumType = theEnum;
@@ -88,7 +89,7 @@ public class EnumConstantNotPresentException extends RuntimeException
* Return the enum type which is missing a constant.
* @return the enum type which is missing a constant
*/
public Class enumType()
public Class<? extends Enum> enumType()
{
return enumType;
}
+6 -21
View File
@@ -1,5 +1,5 @@
/* Float.java -- object wrapper for float
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author Paul Fisher
* @author Andrew Haley (aph@cygnus.com)
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
* @status updated to 1.4
* @status partly updated to 1.5
*/
public final class Float extends Number implements Comparable
public final class Float extends Number implements Comparable<Float>
{
/**
* Compatible with JDK 1.0+.
@@ -91,7 +93,7 @@ public final class Float extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('F');
public static final Class<Float> TYPE = (Class<Float>) VMClassLoader.getPrimitiveClass('F');
/**
* The number of bits needed to represent a <code>float</code>.
@@ -281,7 +283,6 @@ public final class Float extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Float</code>
*
* @since 1.5
*/
public static Float valueOf(float val)
@@ -583,22 +584,6 @@ public final class Float extends Number implements Comparable
return compare(value, f.value);
}
/**
* Behaves like <code>compareTo(Float)</code> unless the Object
* is not an <code>Float</code>.
*
* @param o the object to compare
* @return the comparison
* @throws ClassCastException if the argument is not a <code>Float</code>
* @see #compareTo(Float)
* @see Comparable
* @since 1.2
*/
public int compareTo(Object o)
{
return compare(value, ((Float) o).value);
}
/**
* Behaves like <code>new Float(x).compareTo(new Float(y))</code>; in
* other words this compares two floats, special casing NaN and zero,
@@ -1,5 +1,5 @@
/* InheritableThreadLocal -- a ThreadLocal which inherits values across threads
Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,12 +54,15 @@ import java.util.Iterator;
*
* @author Mark Wielaard (mark@klomp.org)
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see ThreadLocal
* @since 1.2
* @status updated to 1.4
*/
public class InheritableThreadLocal extends ThreadLocal
public class InheritableThreadLocal<T> extends ThreadLocal<T>
{
/**
* Creates a new InheritableThreadLocal that has no values associated
* with it yet.
@@ -77,7 +80,7 @@ public class InheritableThreadLocal extends ThreadLocal
* the moment of creation of the child
* @return the initial value for the child thread
*/
protected Object childValue(Object parentValue)
protected T childValue(T parentValue)
{
return parentValue;
}
@@ -85,7 +88,7 @@ public class InheritableThreadLocal extends ThreadLocal
/**
* Generates the childValues of all <code>InheritableThreadLocal</code>s
* that are in the heritage of the current Thread for the newly created
* childThread. Should be called from the contructor Thread.
* childThread. Should be called from the constructor Thread.
*
* @param childThread the newly created thread, to inherit from this thread
* @see Thread#Thread(ThreadGroup, Runnable, String)
@@ -102,14 +105,14 @@ public class InheritableThreadLocal extends ThreadLocal
Object key = keys.next();
if (key instanceof InheritableThreadLocal)
{
InheritableThreadLocal local = (InheritableThreadLocal)key;
InheritableThreadLocal local = (InheritableThreadLocal)key;
Object parentValue = parentThread.locals.get(key);
Object childValue = local.childValue(parentValue == NULL
? null : parentValue);
Object childValue = local.childValue(parentValue == sentinel
? null : parentValue);
if (childThread.locals == null)
childThread.locals = new WeakIdentityHashMap();
childThread.locals.put(key, (childValue == null
? NULL : childValue));
? sentinel : childValue));
}
}
}
+4 -19
View File
@@ -51,10 +51,11 @@ package java.lang;
* @author Warren Levy
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
* @status largely updated to 1.5
* @status updated to 1.5
*/
public final class Integer extends Number implements Comparable
public final class Integer extends Number implements Comparable<Integer>
{
/**
* Compatible with JDK 1.0.2+.
@@ -78,7 +79,7 @@ public final class Integer extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('I');
public static final Class<Integer> TYPE = (Class<Integer>) VMClassLoader.getPrimitiveClass('I');
/**
* The number of bits needed to represent an <code>int</code>.
@@ -525,22 +526,6 @@ public final class Integer extends Number implements Comparable
return value > i.value ? 1 : -1;
}
/**
* Behaves like <code>compareTo(Integer)</code> unless the Object
* is not an <code>Integer</code>.
*
* @param o the object to compare
* @return the comparison
* @throws ClassCastException if the argument is not an <code>Integer</code>
* @see #compareTo(Integer)
* @see Comparable
* @since 1.2
*/
public int compareTo(Object o)
{
return compareTo((Integer) o);
}
/**
* Return the number of bits set in x.
* @param x value to examine
+2 -2
View File
@@ -49,12 +49,12 @@ import java.util.*;
* @author Tom Tromey <tromey@redhat.com>
* @since 1.5
*/
public interface Iterable
public interface Iterable<E>
{
/**
* Returns an iterator for the collection.
*
* @return an iterator.
*/
Iterator iterator ();
Iterator<E> iterator ();
}
+5 -20
View File
@@ -1,5 +1,5 @@
/* Long.java -- object wrapper for long
Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,10 +49,12 @@ package java.lang;
* @author John Keiser
* @author Warren Levy
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
* @status updated to 1.5
*/
public final class Long extends Number implements Comparable
public final class Long extends Number implements Comparable<Long>
{
/**
* Compatible with JDK 1.0.2+.
@@ -76,7 +78,7 @@ public final class Long extends Number implements Comparable
* <code>Class</code> object.
* @since 1.1
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass ('J');
public static final Class<Long> TYPE = (Class<Long>) VMClassLoader.getPrimitiveClass ('J');
/**
* The number of bits needed to represent a <code>long</code>.
@@ -292,7 +294,6 @@ public final class Long extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Long</code>
*
* @since 1.5
*/
public static synchronized Long valueOf(long val)
@@ -516,22 +517,6 @@ public final class Long extends Number implements Comparable
return value > l.value ? 1 : -1;
}
/**
* Behaves like <code>compareTo(Long)</code> unless the Object
* is not a <code>Long</code>.
*
* @param o the object to compare
* @return the comparison
* @throws ClassCastException if the argument is not a <code>Long</code>
* @see #compareTo(Long)
* @see Comparable
* @since 1.2
*/
public int compareTo(Object o)
{
return compareTo((Long) o);
}
/**
* Return the number of bits set in x.
* @param x value to examine
+1 -1
View File
@@ -326,7 +326,7 @@ public class Object
*
* @return the class of this Object
*/
public final Class getClass()
public final Class<? extends Object> getClass()
{
return VMObject.getClass(this);
}
+56
View File
@@ -0,0 +1,56 @@
/* Override - Annotation to indicate that a method should be an override
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.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import static java.lang.annotation.ElementType.METHOD;
/**
* This annotation is used as a marker to indicate that the annotated
* method declaration is intended to override another method in the
* class hierarchy. If this is not the case, the compiler will emit a
* warning.
*
* @since 1.5
*/
@Retention(SOURCE) @Target(METHOD)
public @interface Override
{
}
+6 -8
View File
@@ -345,14 +345,13 @@ public class Package
* <code>null</code> if no such annotation exists.
* @since 1.5
*/
/* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
public Annotation getAnnotation(Class annotationClass)
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
{
Annotation foundAnnotation = null;
A foundAnnotation = null;
Annotation[] annotations = getAnnotations();
for (int i = 0; i < annotations.length; i++)
if (annotations[i].annotationType() == annotationClass)
foundAnnotation = annotations[i];
for (Annotation annotation : annotations)
if (annotation.annotationType() == annotationClass)
foundAnnotation = (A) annotation;
return foundAnnotation;
}
@@ -406,8 +405,7 @@ public class Package
* @return true if an annotation exists for the specified type.
* @since 1.5
*/
/* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
public boolean isAnnotationPresent(Class
public boolean isAnnotationPresent(Class<? extends Annotation>
annotationClass)
{
return getAnnotation(annotationClass) != null;
@@ -0,0 +1,337 @@
/* ProcessBuilder.java - Represent spawned system process
Copyright (C) 2005 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.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* <p>
* This class is used to construct new operating system processes.
* A <code>ProcessBuilder</code> instance basically represent a
* template for a new process. Actual processes are generated from
* this template via use of the <code>start()</code> method, which
* may be invoked multiple times, with each invocation spawning a
* new process with the current attributes of the
* <code>ProcessBuilder</code> object. Each spawned process is
* independent of the <code>ProcessBuilder</code> object, and is
* unaffected by changes in its attributes.
* </p>
* <p>
* The following attributes define a process:
* </p>
* <ul>
* <li>The <emphasis>working directory</emphasis>; the activities of a
* process begin with the current directory set to this. By default,
* this is the working directory of the current process, as defined
* by the <code>user.dir</code> property.</li>
* <li>The <emphasis>command</emphasis> which invokes the process. This
* usually consists of the name of the program binary followed by an
* arbitrary number of arguments. For example, <code>find -type f</code>
* invokes the <code>find</code> binary with the arguments "-type" and "f".
* The command is provided a list, the elements of which are defined in a
* system dependent manner; the layout is affected by expected operating
* system conventions. A common method is to split the command on each
* space within the string. Thus, <code>find -type f</code> forms a
* three element list. However, in some cases, the expectation is that
* this split is performed by the program itself; thus, the list consists
* of only two elements (the program name and its arguments).</li>
* <li>The <emphasis>environment map</emphasis>, which links environment
* variables to their corresponding values. The initial contents of the map
* are the current environment values i.e. it contains the contents of the
* map returned by <code>System.getenv()</code>.</li>
* <li>The <emphasis>redirection flag</emphasis>, which specifies whether
* or not the contents of the error stream should be redirected to standard
* output. By default, this is false, and there are two output streams, one
* for normal data ({@link Process#getOutputStream()}) and one for error data
* ({@link Process#getErrorStream()}). When set to true, the two are merged,
* which simplifies the interleaving of the two streams. Data is read using
* the stream returned by {@link Process#getOutputStream()}, and the
* stream returned by {@link Process#getErrorStream()} throws an immediate
* end-of-file exception.</li>
* </ul>
* <p>
* All checks on attribute validity are delayed until <code>start()</code>
* is called. <code>ProcessBuilder</code> objects are <strong>not
* synchronized</strong>; the user must provide external synchronization
* where multiple threads may interact with the same
* <code>ProcessBuilder</code> object.
* </p>
*
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see Process
* @see System#getenv()
* @since 1.5
*/
public final class ProcessBuilder
{
/**
* The working directory of the process.
*/
private File directory = new File(System.getProperty("user.dir"));
/**
* The command line syntax for invoking the process.
*/
private List<String> command;
/**
* The mapping of environment variables to values.
*/
private Map<String, String> environment =
new System.EnvironmentMap(System.getenv());
/**
* A flag indicating whether to redirect the error stream to standard
* output.
*/
private boolean redirect = false;
/**
* Constructs a new <code>ProcessBuilder</code> with the specified
* command being used to invoke the process. The list is used directly;
* external changes are reflected in the <code>ProcessBuilder</code>.
*
* @param command the name of the program followed by its arguments.
*/
public ProcessBuilder(List<String> command)
{
this.command = command;
}
/**
* Constructs a new <code>ProcessBuilder</code> with the specified
* command being used to invoke the process. This constructor
* simplifies creating a new <code>ProcessBuilder</code> by
* converting the provided series of constructor arguments into a
* list of command-line arguments.
*
* @param command the name of the program followed by its arguments.
*/
public ProcessBuilder(String... command)
{
this.command = Arrays.asList(command);
}
/**
* Returns the current command line, used to invoke the process.
* The return value is simply a reference to the list of command
* line arguments used by the <code>ProcessBuilder</code> object;
* any changes made to it will be reflected in the operation of
* the <code>ProcessBuilder</code>.
*
* @return the list of command-line arguments.
*/
public List<String> command()
{
return command;
}
/**
* Sets the command-line arguments to those specified. The list is
* used directly; external changes are reflected in the
* <code>ProcessBuilder</code>.
*
* @param command the name of the program followed by its arguments.
* @return a reference to this process builder.
*/
public ProcessBuilder command(List<String> command)
{
this.command = command;
return this;
}
/**
* Sets the command-line arguments to those specified.
* This simplifies modifying the arguments by converting
* the provided series of constructor arguments into a
* list of command-line arguments.
*
* @param command the name of the program followed by its arguments.
* @return a reference to this process builder.
*/
public ProcessBuilder command(String... command)
{
this.command = Arrays.asList(command);
return this;
}
/**
* Returns the working directory of the process. The
* returned value may be <code>null</code>; this
* indicates that the default behaviour of using the
* working directory of the current process should
* be adopted.
*
* @return the working directory.
*/
public File directory()
{
return directory;
}
/**
* Sets the working directory to that specified.
* The supplied argument may be <code>null</code>,
* which indicates the default value should be used.
* The default is the working directory of the current
* process.
*
* @param directory the new working directory.
* @return a reference to this process builder.
*/
public ProcessBuilder directory(File directory)
{
this.directory = directory;
return this;
}
/**
* <p>
* Returns the system environment variables of the process.
* If the underlying system does not support environment variables,
* an empty map is returned.
* </p>
* <p>
* The returned map does not accept queries using
* null keys or values, or those of a type other than
* <code>String</code>. Attempts to pass in a null value will
* throw a <code>NullPointerException</code>. Types other than
* <code>String</code> throw a <code>ClassCastException</code>.
* </p>
* <p>
* As the returned map is generated using data from the underlying
* platform, it may not comply with the <code>equals()</code>
* and <code>hashCode()</code> contracts. It is also likely that
* the keys of this map will be case-sensitive.
* </p>
* <p>
* Modification of the map is reliant on the underlying platform;
* some may not allow any changes to the environment variables or
* may prevent certain values being used. Attempts to do so will
* throw an <code>UnsupportedOperationException</code> or
* <code>IllegalArgumentException</code>, respectively.
* </p>
* <p>
* Use of this method may require a security check for the
* RuntimePermission "getenv.*".
* </p>
*
* @return a map of the system environment variables for the process.
* @throws SecurityException if the checkPermission method of
* an installed security manager prevents access to
* the system environment variables.
* @since 1.5
*/
public Map<String, String> environment()
{
return environment;
}
/**
* Returns true if the output stream and error stream of the
* process will be merged to form one composite stream. The
* default return value is <code>false</code>.
*
* @return true if the output stream and error stream are to
* be merged.
*/
public boolean redirectErrorStream()
{
return redirect;
}
/**
* Sets the error stream redirection flag. If set, the output
* and error streams are merged to form one composite stream.
*
* @param redirect the new value of the redirection flag.
* @return a reference to this process builder.
*/
public ProcessBuilder redirectErrorStream(boolean redirect)
{
this.redirect = redirect;
return this;
}
/**
* <p>
* Starts execution of a new process, based on the attributes of
* this <code>ProcessBuilder</code> object. This is the point
* at which the command-line arguments are checked. The list
* must be non-empty and contain only non-null string objects.
* The other attributes have default values which are used in
* cases where their values are not explicitly specified.
* </p>
* <p>
* If a security manager is in place, then the
* {@link SecurityManager#checkExec()} method is called to
* ensure that permission is given to execute the process.
* </p>
* <p>
* The execution of the process is system-dependent. Various
* exceptions may result, due to problems at the operating system
* level. These are all returned as a form of {@link IOException}.
* </p>
*
* @return a <code>Process</code> object, representing the spawned
* subprocess.
* @throws IOException if a problem occurs with executing the process
* at the operating system level.
* @throws IndexOutOfBoundsException if the command to execute is
* actually an empty list.
* @throws NullPointerException if the command to execute is null
* or the list contains null elements.
* @throws SecurityException if a security manager exists and prevents
* execution of the subprocess.
*/
public Process start() throws IOException
{
SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null)
sm.checkExec(command.get(0));
return VMProcess.exec(command, environment, directory, redirect);
}
}
@@ -1,5 +1,5 @@
/* SecurityManager.java -- security checks for privileged actions
Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -240,7 +240,7 @@ public class SecurityManager
* @return the most recent non-system Class on the execution stack
* @deprecated use {@link #checkPermission(Permission)} instead
*/
protected Class currentLoadedClass()
protected Class<?> currentLoadedClass()
{
int i = classLoaderDepth();
return i >= 0 ? getClassContext()[i] : null;
@@ -983,7 +983,7 @@ public class SecurityManager
* @see Member#PUBLIC
* @since 1.1
*/
public void checkMemberAccess(Class c, int memberType)
public void checkMemberAccess(Class<?> c, int memberType)
{
if (c == null)
throw new NullPointerException();
+9 -24
View File
@@ -1,5 +1,5 @@
/* Short.java -- object wrapper for short
Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -48,10 +48,12 @@ package java.lang;
* @author Paul Fisher
* @author John Keiser
* @author Eric Blake (ebb9@email.byu.edu)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.1
* @status updated to 1.4
* @status updated to 1.5
*/
public final class Short extends Number implements Comparable
public final class Short extends Number implements Comparable<Short>
{
/**
* Compatible with JDK 1.1+.
@@ -74,7 +76,7 @@ public final class Short extends Number implements Comparable
* The primitive type <code>short</code> is represented by this
* <code>Class</code> object.
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('S');
public static final Class<Short> TYPE = (Class<Short>) VMClassLoader.getPrimitiveClass('S');
/**
* The number of bits needed to represent a <code>short</code>.
@@ -208,7 +210,6 @@ public final class Short extends Number implements Comparable
*
* @param val the value to wrap
* @return the <code>Short</code>
*
* @since 1.5
*/
public static Short valueOf(short val)
@@ -217,9 +218,9 @@ public final class Short extends Number implements Comparable
return new Short(val);
synchronized (shortCache)
{
if (shortCache[val - MIN_CACHE] == null)
shortCache[val - MIN_CACHE] = new Short(val);
return shortCache[val - MIN_CACHE];
if (shortCache[val - MIN_CACHE] == null)
shortCache[val - MIN_CACHE] = new Short(val);
return shortCache[val - MIN_CACHE];
}
}
@@ -370,22 +371,6 @@ public final class Short extends Number implements Comparable
return value - s.value;
}
/**
* Behaves like <code>compareTo(Short)</code> unless the Object
* is not a <code>Short</code>.
*
* @param o the object to compare
* @return the comparison
* @throws ClassCastException if the argument is not a <code>Short</code>
* @see #compareTo(Short)
* @see Comparable
* @since 1.2
*/
public int compareTo(Object o)
{
return compareTo((Short)o);
}
/**
* Reverse the bytes in val.
* @since 1.5
+190 -36
View File
@@ -632,6 +632,94 @@ public final strictfp class StrictMath
return y > 0 ? PI - (z - PI_L) : z - PI_L - PI;
}
/**
* Returns the hyperbolic sine of <code>x</code> which is defined as
* (exp(x) - exp(-x)) / 2.
*
* Special cases:
* <ul>
* <li>If the argument is NaN, the result is NaN</li>
* <li>If the argument is positive infinity, the result is positive
* infinity.</li>
* <li>If the argument is negative infinity, the result is negative
* infinity.</li>
* <li>If the argument is zero, the result is zero.</li>
* </ul>
*
* @param x the argument to <em>sinh</em>
* @return the hyperbolic sine of <code>x</code>
*
* @since 1.5
*/
public static double sinh(double x)
{
// Method :
// mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
// 1. Replace x by |x| (sinh(-x) = -sinh(x)).
// 2.
// E + E/(E+1)
// 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
// 2
//
// 22 <= x <= lnovft : sinh(x) := exp(x)/2
// lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
// ln2ovft < x : sinh(x) := +inf (overflow)
double t, w, h;
long bits;
long h_bits;
long l_bits;
// handle special cases
if (x != x)
return x;
if (x == Double.POSITIVE_INFINITY)
return Double.POSITIVE_INFINITY;
if (x == Double.NEGATIVE_INFINITY)
return Double.NEGATIVE_INFINITY;
if (x < 0)
h = - 0.5;
else
h = 0.5;
bits = Double.doubleToLongBits(x);
h_bits = getHighDWord(bits) & 0x7fffffffL; // ignore sign
l_bits = getLowDWord(bits);
// |x| in [0, 22], return sign(x) * 0.5 * (E+E/(E+1))
if (h_bits < 0x40360000L) // |x| < 22
{
if (h_bits < 0x3e300000L) // |x| < 2^-28
return x; // for tiny arguments return x
t = expm1(abs(x));
if (h_bits < 0x3ff00000L)
return h * (2.0 * t - t * t / (t + 1.0));
return h * (t + t / (t + 1.0));
}
// |x| in [22, log(Double.MAX_VALUE)], return 0.5 * exp(|x|)
if (h_bits < 0x40862e42L)
return h * exp(abs(x));
// |x| in [log(Double.MAX_VALUE), overflowthreshold]
if ((h_bits < 0x408633ceL)
|| ((h_bits == 0x408633ceL) && (l_bits <= 0x8fb9f87dL)))
{
w = exp(0.5 * abs(x));
t = h * w;
return t * w;
}
// |x| > overflowthershold
return h * Double.POSITIVE_INFINITY;
}
/**
* Returns the hyperbolic cosine of <code>x</code>, which is defined as
* (exp(x) + exp(-x)) / 2.
@@ -670,36 +758,36 @@ public final strictfp class StrictMath
double t, w;
long bits;
int hx;
int lx;
long hx;
long lx;
// handle special cases
if (x != x)
return Double.NaN;
return x;
if (x == Double.POSITIVE_INFINITY)
return Double.POSITIVE_INFINITY;
if (x == Double.NEGATIVE_INFINITY)
return Double.POSITIVE_INFINITY;
bits = Double.doubleToLongBits(x);
hx = getHighDWord(bits) & 0x7fffffff; // ignore sign
hx = getHighDWord(bits) & 0x7fffffffL; // ignore sign
lx = getLowDWord(bits);
// |x| in [0, 0.5 * ln(2)], return 1 + expm1(|x|)^2 / (2 * exp(|x|))
if (hx < 0x3fd62e43)
if (hx < 0x3fd62e43L)
{
t = expm1(abs(x));
w = 1.0 + t;
// for tiny arguments return 1.
if (hx < 0x3c800000)
if (hx < 0x3c800000L)
return w;
return 1.0 + (t * t) / (w + w);
}
// |x| in [0.5 * ln(2), 22], return exp(|x|)/2 + 1 / (2 * exp(|x|))
if (hx < 0x40360000)
if (hx < 0x40360000L)
{
t = exp(abs(x));
@@ -707,16 +795,13 @@ public final strictfp class StrictMath
}
// |x| in [22, log(Double.MAX_VALUE)], return 0.5 * exp(|x|)
if (hx < 0x40862e42)
if (hx < 0x40862e42L)
return 0.5 * exp(abs(x));
// |x| in [log(Double.MAX_VALUE), overflowthreshold],
// return exp(x/2)/2 * exp(x/2)
// we need to force an unsigned <= compare, thus can not use lx.
if ((hx < 0x408633ce)
|| ((hx == 0x408633ce)
&& ((bits & 0x00000000ffffffffL) <= 0x8fb9f87dL)))
if ((hx < 0x408633ceL)
|| ((hx == 0x408633ceL) && (lx <= 0x8fb9f87dL)))
{
w = exp(0.5 * abs(x));
t = 0.5 * w;
@@ -728,14 +813,83 @@ public final strictfp class StrictMath
return Double.POSITIVE_INFINITY;
}
/**
* Returns the hyperbolic tangent of <code>x</code>, which is defined as
* (exp(x) - exp(-x)) / (exp(x) + exp(-x)), i.e. sinh(x) / cosh(x).
*
Special cases:
* <ul>
* <li>If the argument is NaN, the result is NaN</li>
* <li>If the argument is positive infinity, the result is 1.</li>
* <li>If the argument is negative infinity, the result is -1.</li>
* <li>If the argument is zero, the result is zero.</li>
* </ul>
*
* @param x the argument to <em>tanh</em>
* @return the hyperbolic tagent of <code>x</code>
*
* @since 1.5
*/
public static double tanh(double x)
{
// Method :
// 0. tanh(x) is defined to be (exp(x) - exp(-x)) / (exp(x) + exp(-x))
// 1. reduce x to non-negative by tanh(-x) = -tanh(x).
// 2. 0 <= x <= 2^-55 : tanh(x) := x * (1.0 + x)
// -t
// 2^-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x)
// t + 2
// 2
// 1 <= x <= 22.0 : tanh(x) := 1 - ----- ; t=expm1(2x)
// t + 2
// 22.0 < x <= INF : tanh(x) := 1.
double t, z;
long bits;
long h_bits;
// handle special cases
if (x != x)
return x;
if (x == Double.POSITIVE_INFINITY)
return 1.0;
if (x == Double.NEGATIVE_INFINITY)
return -1.0;
bits = Double.doubleToLongBits(x);
h_bits = getHighDWord(bits) & 0x7fffffffL; // ingnore sign
if (h_bits < 0x40360000L) // |x| < 22
{
if (h_bits < 0x3c800000L) // |x| < 2^-55
return x * (1.0 + x);
if (h_bits >= 0x3ff00000L) // |x| >= 1
{
t = expm1(2.0 * abs(x));
z = 1.0 - 2.0 / (t + 2.0);
}
else // |x| < 1
{
t = expm1(-2.0 * abs(x));
z = -t / (t + 2.0);
}
}
else // |x| >= 22
z = 1.0;
return (x >= 0) ? z : -z;
}
/**
* Returns the lower two words of a long. This is intended to be
* used like this:
* <code>getLowDWord(Double.doubleToLongBits(x))</code>.
*/
private static int getLowDWord(long x)
private static long getLowDWord(long x)
{
return (int) (x & 0x00000000ffffffffL);
return x & 0x00000000ffffffffL;
}
/**
@@ -743,19 +897,19 @@ public final strictfp class StrictMath
* used like this:
* <code>getHighDWord(Double.doubleToLongBits(x))</code>.
*/
private static int getHighDWord(long x)
private static long getHighDWord(long x)
{
return (int) ((x & 0xffffffff00000000L) >> 32);
return (x & 0xffffffff00000000L) >> 32;
}
/**
* Returns a double with the IEEE754 bit pattern given in the lower
* and higher two words <code>lowDWord</code> and <code>highDWord</code>.
*/
private static double buildDouble(int lowDWord, int highDWord)
private static double buildDouble(long lowDWord, long highDWord)
{
return Double.longBitsToDouble((((long) highDWord & 0xffffffffL) << 32)
| ((long) lowDWord & 0xffffffffL));
return Double.longBitsToDouble(((highDWord & 0xffffffffL) << 32)
| (lowDWord & 0xffffffffL));
}
/**
@@ -788,12 +942,12 @@ public final strictfp class StrictMath
double w;
long bits;
int l;
int h;
long l;
long h;
// handle the special cases
if (x != x)
return Double.NaN;
return x;
if (x == Double.POSITIVE_INFINITY)
return Double.POSITIVE_INFINITY;
if (x == Double.NEGATIVE_INFINITY)
@@ -847,7 +1001,7 @@ public final strictfp class StrictMath
s = t * t; // t * t is exact
r = x / s;
w = t + t;
r = (r - t) / (w + r); // r - s is exact
r = (r - t) / (w + r); // r - t is exact
t = t + t * r;
return negative ? -t : t;
@@ -1008,8 +1162,8 @@ public final strictfp class StrictMath
int k;
long bits;
int h_bits;
int l_bits;
long h_bits;
long l_bits;
c = 0.0;
y = abs(x);
@@ -1019,14 +1173,14 @@ public final strictfp class StrictMath
l_bits = getLowDWord(bits);
// handle special cases and large arguments
if (h_bits >= 0x4043687a) // if |x| >= 56 * ln(2)
if (h_bits >= 0x4043687aL) // if |x| >= 56 * ln(2)
{
if (h_bits >= 0x40862e42) // if |x| >= EXP_LIMIT_H
if (h_bits >= 0x40862e42L) // if |x| >= EXP_LIMIT_H
{
if (h_bits >= 0x7ff00000)
if (h_bits >= 0x7ff00000L)
{
if (((h_bits & 0x000fffff) | (l_bits & 0xffffffff)) != 0)
return Double.NaN; // exp(NaN) = NaN
if (((h_bits & 0x000fffffL) | (l_bits & 0xffffffffL)) != 0)
return x; // exp(NaN) = NaN
else
return negative ? -1.0 : x; // exp({+-inf}) = {+inf, -1}
}
@@ -1040,9 +1194,9 @@ public final strictfp class StrictMath
}
// argument reduction
if (h_bits > 0x3fd62e42) // |x| > 0.5 * ln(2)
if (h_bits > 0x3fd62e42L) // |x| > 0.5 * ln(2)
{
if (h_bits < 0x3ff0a2b2) // |x| < 1.5 * ln(2)
if (h_bits < 0x3ff0a2b2L) // |x| < 1.5 * ln(2)
{
if (negative)
{
@@ -1069,7 +1223,7 @@ public final strictfp class StrictMath
c = (hi - x) - lo;
}
else if (h_bits < 0x3c900000) // |x| < 2^-54 return x
else if (h_bits < 0x3c900000L) // |x| < 2^-54 return x
return x;
else
k = 0;
@@ -1124,7 +1278,7 @@ public final strictfp class StrictMath
if (k < 20)
{
bits = Double.doubleToLongBits(t);
h_bits = 0x3ff00000 - (0x00200000 >> k);
h_bits = 0x3ff00000L - (0x00200000L >> k);
l_bits = getLowDWord(bits);
t = buildDouble(l_bits, h_bits); // t = 1 - 2^(-k)
@@ -1141,7 +1295,7 @@ public final strictfp class StrictMath
else
{
bits = Double.doubleToLongBits(t);
h_bits = (0x000003ff - k) << 20;
h_bits = (0x000003ffL - k) << 20;
l_bits = getLowDWord(bits);
t = buildDouble(l_bits, h_bits); // t = 2^(-k)
+25 -23
View File
@@ -1,5 +1,5 @@
/* String.java -- immutable character sequences; the object of string literals
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,6 +54,7 @@ import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.text.Collator;
import java.util.Comparator;
import java.util.Formatter;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -82,10 +83,13 @@ import java.util.regex.PatternSyntaxException;
* @author Paul N. Fisher
* @author Eric Blake (ebb9@email.byu.edu)
* @author Per Bothner (bothner@cygnus.com)
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.0
* @status updated to 1.4; but could use better data sharing via offset field
*/
public final class String implements Serializable, Comparable, CharSequence
public final class String
implements Serializable, Comparable<String>, CharSequence
{
// WARNING: String is a CORE class in the bootstrap cycle. See the comments
// in vm/reference/java/lang/Runtime for implications of this fact.
@@ -144,7 +148,7 @@ public final class String implements Serializable, Comparable, CharSequence
* compatibility with Sun's JDK.
*/
private static final class CaseInsensitiveComparator
implements Comparator, Serializable
implements Comparator<String>, Serializable
{
/**
* Compatible with JDK 1.2.
@@ -168,9 +172,9 @@ public final class String implements Serializable, Comparable, CharSequence
* @throws ClassCastException if either argument is not a String
* @see #compareToIgnoreCase(String)
*/
public int compare(Object o1, Object o2)
public int compare(String o1, String o2)
{
return ((String) o1).compareToIgnoreCase((String) o2);
return o1.compareToIgnoreCase(o2);
}
} // class CaseInsensitiveComparator
@@ -182,7 +186,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @see Collator#compare(String, String)
* @since 1.2
*/
public static final Comparator CASE_INSENSITIVE_ORDER
public static final Comparator<String> CASE_INSENSITIVE_ORDER
= new CaseInsensitiveComparator();
/**
@@ -918,22 +922,6 @@ public final class String implements Serializable, Comparable, CharSequence
return count - anotherString.count;
}
/**
* Behaves like <code>compareTo(java.lang.String)</code> unless the Object
* is not a <code>String</code>. Then it throws a
* <code>ClassCastException</code>.
*
* @param o the object to compare against
* @return the comparison
* @throws NullPointerException if o is null
* @throws ClassCastException if o is not a <code>String</code>
* @since 1.2
*/
public int compareTo(Object o)
{
return compareTo((String) o);
}
/**
* Compares this String and another String (case insensitive). This
* comparison is <em>similar</em> to equalsIgnoreCase, in that it ignores
@@ -1674,7 +1662,6 @@ public final class String implements Serializable, Comparable, CharSequence
* @return String containing the chars from data[offset..offset+count]
* @throws NullPointerException if data is null
* @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0
* || offset + count &lt; 0 (overflow)
* || offset + count &gt; data.length)
* (while unspecified, this is a StringIndexOutOfBoundsException)
* @see #String(char[], int, int)
@@ -1696,6 +1683,7 @@ public final class String implements Serializable, Comparable, CharSequence
* @throws NullPointerException if data is null
* @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0
* || offset + count &lt; 0 (overflow)
* || offset + count &lt; 0 (overflow)
* || offset + count &gt; data.length)
* (while unspecified, this is a StringIndexOutOfBoundsException)
* @see #String(char[], int, int)
@@ -1792,6 +1780,20 @@ public final class String implements Serializable, Comparable, CharSequence
return Double.toString(d);
}
/** @since 1.5 */
public static String format(Locale locale, String format, Object... args)
{
Formatter f = new Formatter(locale);
return f.format(format, args).toString();
}
/** @since 1.5 */
public static String format(String format, Object... args)
{
return format(Locale.getDefault(), format, args);
}
/**
* If two Strings are considered equal, by the equals() method,
* then intern() will return the same String instance. ie.
+61 -59
View File
@@ -72,8 +72,12 @@ import java.io.Serializable;
* @since 1.0
* @status updated to 1.4
*/
public final class StringBuffer implements Serializable, CharSequence
public final class StringBuffer
implements Serializable, CharSequence, Appendable
{
// Implementation note: if you change this class, you usually will
// want to change StringBuilder as well.
/**
* Compatible with JDK 1.0+.
*/
@@ -148,21 +152,22 @@ public final class StringBuffer implements Serializable, CharSequence
}
/**
* Create a new <code>StringBuffer</code> with the characters from the
* Create a new <code>StringBuffer</code> with the characters in the
* specified <code>CharSequence</code>. Initial capacity will be the
* size of the CharSequence plus 16.
* length of the sequence plus 16; if the sequence reports a length
* less than or equal to 0, then the initial capacity will be 16.
*
* @param sequence the <code>String</code> to convert
* @param seq the initializing <code>CharSequence</code>
* @throws NullPointerException if str is null
*
* @since 1.5
*/
public StringBuffer(CharSequence sequence)
public StringBuffer(CharSequence seq)
{
count = Math.max(0, sequence.length());
int len = seq.length();
count = len <= 0 ? 0 : len;
value = new char[count + DEFAULT_CAPACITY];
for (int i = 0; i < count; ++i)
value[i] = sequence.charAt(i);
for (int i = 0; i < len; ++i)
value[i] = seq.charAt(i);
}
/**
@@ -390,46 +395,6 @@ public final class StringBuffer implements Serializable, CharSequence
return this;
}
/**
* Append the <code>CharSequence</code> value of the argument to this
* <code>StringBuffer</code>.
*
* @param sequence the <code>CharSequence</code> to append
* @return this <code>StringBuffer</code>
* @see #append(Object)
* @since 1.5
*/
public synchronized StringBuffer append(CharSequence sequence)
{
if (sequence == null)
sequence = "null";
return append(sequence, 0, sequence.length());
}
/**
* Append the specified subsequence of the <code>CharSequence</code>
* argument to this <code>StringBuffer</code>.
*
* @param sequence the <code>CharSequence</code> to append
* @param start the starting index
* @param end one past the ending index
* @return this <code>StringBuffer</code>
* @see #append(Object)
* @since 1.5
*/
public synchronized StringBuffer append(CharSequence sequence,
int start, int end)
{
if (sequence == null)
sequence = "null";
if (start < 0 || end < 0 || start > end || end > sequence.length())
throw new IndexOutOfBoundsException();
ensureCapacity_unsynchronized(this.count + end - start);
for (int i = start; i < end; ++i)
value[count++] = sequence.charAt(i);
return this;
}
/**
* Append the <code>char</code> array to this <code>StringBuffer</code>.
* This is similar (but more efficient) than
@@ -469,6 +434,25 @@ public final class StringBuffer implements Serializable, CharSequence
return this;
}
/**
* Append the code point to this <code>StringBuffer</code>.
* This is like #append(char), but will append two characters
* if a supplementary code point is given.
*
* @param code the code point to append
* @return this <code>StringBuffer</code>
* @see Character#toChars(int, char[], int)
* @since 1.5
*/
public synchronized StringBuffer appendCodePoint(int code)
{
int len = Character.charCount(code);
ensureCapacity_unsynchronized(count + len);
Character.toChars(code, value, count);
count += len;
return this;
}
/**
* Append the <code>String</code> value of the argument to this
* <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert
@@ -497,21 +481,39 @@ public final class StringBuffer implements Serializable, CharSequence
}
/**
* Append the code point to this <code>StringBuffer</code>.
* This is like #append(char), but will append two characters
* if a supplementary code point is given.
* Append the characters in the <code>CharSequence</code> to this
* buffer.
*
* @param code the code point to append
* @param seq the <code>CharSequence</code> providing the characters
* @return this <code>StringBuffer</code>
* @see Character#toChars(int, char[], int)
* @since 1.5
*/
public synchronized StringBuffer appendCodePoint(int code)
public synchronized StringBuffer append(CharSequence seq)
{
int len = Character.charCount(code);
ensureCapacity_unsynchronized(count + len);
Character.toChars(code, value, count);
count += len;
return append(seq, 0, seq.length());
}
/**
* Append some characters from the <code>CharSequence</code> to this
* buffer. If the argument is null, the four characters "null" are
* appended.
*
* @param seq the <code>CharSequence</code> providing the characters
* @param start the starting index
* @param end one past the final index
* @return this <code>StringBuffer</code>
* @since 1.5
*/
public synchronized StringBuffer append(CharSequence seq, int start, int end)
{
if (seq == null)
return append("null");
if (end - start > 0)
{
ensureCapacity_unsynchronized(count + end - start);
for (; start < end; ++start)
value[count++] = seq.charAt(start);
}
return this;
}
@@ -74,9 +74,8 @@ import java.io.Serializable;
*
* @since 1.5
*/
// FIX15: Implement Appendable when co-variant methods are available
public final class StringBuilder
implements Serializable, CharSequence
implements Serializable, CharSequence, Appendable
{
// Implementation note: if you change this class, you usually will
// want to change StringBuffer as well.
@@ -0,0 +1,69 @@
/* SuppressWarnings - Annotation to avoid compiler warnings
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.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import static java.lang.annotation.ElementType.*;
/**
* Tell the compiler that a given warning should be suppressed when it
* pertains to the marked program element and its sub-elements.
*
* Note that warning suppression is additive. For instance if a
* constructor has a warning suppressed, and a local variable in the
* constructor has a different warning suppressed, then the resulting
* set of suppressed warnings for that variable will be both warnings.
*
* @since 1.5
*/
@Retention(SOURCE)
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
public @interface SuppressWarnings
{
/**
* The list of warnings to suppress.
*
* It is valid to list a name more than once. Unrecognized names
* are not a compile-time error. At the present there is no
* standard for the names to be recognized by compilers; consult
* your compiler's documentation for this information.
*/
String[] value ();
}
+485 -3
View File
@@ -44,6 +44,14 @@ import gnu.classpath.VMStackWalker;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Properties;
import java.util.PropertyPermission;
@@ -97,6 +105,11 @@ public final class System
*/
public static final PrintStream err = VMSystem.makeStandardErrorStream();
/**
* A cached copy of the environment variable map.
*/
private static Map<String,String> environmentMap;
/**
* This class is uninstantiable.
*/
@@ -118,6 +131,7 @@ public final class System
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPermission(new RuntimePermission("setIO"));
VMSystem.setIn(in);
}
@@ -134,8 +148,7 @@ public final class System
{
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPermission(new RuntimePermission("setIO"));
sm.checkPermission(new RuntimePermission("setIO"));
VMSystem.setOut(out);
}
@@ -221,7 +234,7 @@ public final class System
{
return VMSystem.currentTimeMillis();
}
/**
* <p>
* Returns the current value of a nanosecond-precise system timer.
@@ -492,6 +505,60 @@ public final class System
return VMSystem.getenv(name);
}
/**
* <p>
* Returns an unmodifiable view of the system environment variables.
* If the underlying system does not support environment variables,
* an empty map is returned.
* </p>
* <p>
* The returned map is read-only and does not accept queries using
* null keys or values, or those of a type other than <code>String</code>.
* Attempts to modify the map will throw an
* <code>UnsupportedOperationException</code>, while attempts
* to pass in a null value will throw a
* <code>NullPointerException</code>. Types other than <code>String</code>
* throw a <code>ClassCastException</code>.
* </p>
* <p>
* As the returned map is generated using data from the underlying
* platform, it may not comply with the <code>equals()</code>
* and <code>hashCode()</code> contracts. It is also likely that
* the keys of this map will be case-sensitive.
* </p>
* <p>
* Use of this method may require a security check for the
* RuntimePermission "getenv.*".
* </p>
*
* @return a map of the system environment variables.
* @throws SecurityException if the checkPermission method of
* an installed security manager prevents access to
* the system environment variables.
* @since 1.5
*/
public static Map<String, String> getenv()
{
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPermission(new RuntimePermission("getenv.*"));
if (environmentMap == null)
{
List<String> environ = (List<String>)VMSystem.environ();
Map<String,String> variables = new EnvironmentMap();
for (String pair : environ)
{
String[] parts = pair.split("=");
if (parts.length == 2)
variables.put(parts[0], parts[1]);
else
variables.put(parts[0], "");
}
environmentMap = Collections.unmodifiableMap(variables);
}
return environmentMap;
}
/**
* Terminate the Virtual Machine. This just calls
* <code>Runtime.getRuntime().exit(status)</code>, and never returns.
@@ -604,4 +671,419 @@ public final class System
return VMRuntime.mapLibraryName(libname);
}
/**
* This is a specialised <code>Collection</code>, providing
* the necessary provisions for the collections used by the
* environment variable map. Namely, it prevents
* querying anything but <code>String</code>s.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
private static class EnvironmentCollection
extends AbstractCollection<String>
{
/**
* The wrapped collection.
*/
protected Collection<String> c;
/**
* Constructs a new environment collection, which
* wraps the elements of the supplied collection.
*
* @param coll the collection to use as a base for
* this collection.
*/
public EnvironmentCollection(Collection<String> coll)
{
c = coll;
}
/**
* Blocks queries containing a null object or an object which
* isn't of type <code>String</code>. All other queries
* are forwarded to the underlying collection.
*
* @param obj the object to look for.
* @return true if the object exists in the collection.
* @throws NullPointerException if the specified object is null.
* @throws ClassCastException if the specified object is not a String.
*/
public boolean contains(Object obj)
{
if (obj == null)
throw new
NullPointerException("This collection does not support " +
"null values.");
if (!(obj instanceof String))
throw new
ClassCastException("This collection only supports Strings.");
return c.contains(obj);
}
/**
* Blocks queries where the collection contains a null object or
* an object which isn't of type <code>String</code>. All other
* queries are forwarded to the underlying collection.
*
* @param coll the collection of objects to look for.
* @return true if the collection contains all elements in the collection.
* @throws NullPointerException if the collection is null.
* @throws NullPointerException if any collection entry is null.
* @throws ClassCastException if any collection entry is not a String.
*/
public boolean containsAll(Collection<?> coll)
{
for (Object o: coll)
{
if (o == null)
throw new
NullPointerException("This collection does not support " +
"null values.");
if (!(o instanceof String))
throw new
ClassCastException("This collection only supports Strings.");
}
return c.containsAll(coll);
}
/**
* This returns an iterator over the map elements, with the
* same provisions as for the collection and underlying map.
*
* @return an iterator over the map elements.
*/
public Iterator<String> iterator()
{
return c.iterator();
}
/**
* Blocks the removal of elements from the collection.
*
* @return true if the removal was sucessful.
* @throws NullPointerException if the collection is null.
* @throws NullPointerException if any collection entry is null.
* @throws ClassCastException if any collection entry is not a String.
*/
public boolean remove(Object key)
{
if (key == null)
throw new
NullPointerException("This collection does not support " +
"null values.");
if (!(key instanceof String))
throw new
ClassCastException("This collection only supports Strings.");
return c.contains(key);
}
/**
* Blocks the removal of all elements in the specified
* collection from the collection.
*
* @param coll the collection of elements to remove.
* @return true if the elements were removed.
* @throws NullPointerException if the collection is null.
* @throws NullPointerException if any collection entry is null.
* @throws ClassCastException if any collection entry is not a String.
*/
public boolean removeAll(Collection<?> coll)
{
for (Object o: coll)
{
if (o == null)
throw new
NullPointerException("This collection does not support " +
"null values.");
if (!(o instanceof String))
throw new
ClassCastException("This collection only supports Strings.");
}
return c.removeAll(coll);
}
/**
* Blocks the retention of all elements in the specified
* collection from the collection.
*
* @param c the collection of elements to retain.
* @return true if the other elements were removed.
* @throws NullPointerException if the collection is null.
* @throws NullPointerException if any collection entry is null.
* @throws ClassCastException if any collection entry is not a String.
*/
public boolean retainAll(Collection<?> coll)
{
for (Object o: coll)
{
if (o == null)
throw new
NullPointerException("This collection does not support " +
"null values.");
if (!(o instanceof String))
throw new
ClassCastException("This collection only supports Strings.");
}
return c.containsAll(coll);
}
/**
* This simply calls the same method on the wrapped
* collection.
*
* @return the size of the underlying collection.
*/
public int size()
{
return c.size();
}
} // class EnvironmentCollection<String>
/**
* This is a specialised <code>HashMap</code>, which
* prevents the addition or querying of anything other than
* <code>String</code> objects.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
static class EnvironmentMap
extends HashMap<String,String>
{
/**
* Cache the entry set.
*/
private transient Set<Map.Entry<String,String>> entries;
/**
* Cache the key set.
*/
private transient Set<String> keys;
/**
* Cache the value collection.
*/
private transient Collection<String> values;
/**
* Constructs a new empty <code>EnvironmentMap</code>.
*/
EnvironmentMap()
{
super();
}
/**
* Constructs a new <code>EnvironmentMap</code> containing
* the contents of the specified map.
*
* @param m the map to be added to this.
* @throws NullPointerException if a key or value is null.
* @throws ClassCastException if a key or value is not a String.
*/
EnvironmentMap(Map<String,String> m)
{
super(m);
}
/**
* Blocks queries containing a null key or one which is not
* of type <code>String</code>. All other queries
* are forwarded to the superclass.
*
* @param key the key to look for in the map.
* @return true if the key exists in the map.
* @throws NullPointerException if the specified key is null.
*/
public boolean containsKey(Object key)
{
if (key == null)
throw new
NullPointerException("This map does not support null keys.");
if (!(key instanceof String))
throw new
ClassCastException("This map only allows queries using Strings.");
return super.containsKey(key);
}
/**
* Blocks queries using a null or non-<code>String</code> value.
* All other queries are forwarded to the superclass.
*
* @param value the value to look for in the map.
* @return true if the value exists in the map.
* @throws NullPointerException if the specified value is null.
*/
public boolean containsValue(Object value)
{
if (value == null)
throw new
NullPointerException("This map does not support null values.");
if (!(value instanceof String))
throw new
ClassCastException("This map only allows queries using Strings.");
return super.containsValue(value);
}
/**
* Returns a set view of the map entries, with the same
* provisions as for the underlying map.
*
* @return a set containing the map entries.
*/
public Set<Map.Entry<String,String>> entrySet()
{
if (entries == null)
entries = super.entrySet();
return entries;
}
/**
* Blocks queries containing a null or non-<code>String</code> key.
* All other queries are passed on to the superclass.
*
* @param key the key to retrieve the value for.
* @return the value associated with the given key.
* @throws NullPointerException if the specified key is null.
* @throws ClassCastException if the specified key is not a String.
*/
public String get(Object key)
{
if (key == null)
throw new
NullPointerException("This map does not support null keys.");
if (!(key instanceof String))
throw new
ClassCastException("This map only allows queries using Strings.");
return super.get(key);
}
/**
* Returns a set view of the keys, with the same
* provisions as for the underlying map.
*
* @return a set containing the keys.
*/
public Set<String> keySet()
{
if (keys == null)
keys = new EnvironmentSet(super.keySet());
return keys;
}
/**
* Associates the given key to the given value. If the
* map already contains the key, its value is replaced.
* The map does not accept null keys or values, or keys
* and values not of type {@link String}.
*
* @param key the key to map.
* @param value the value to be mapped.
* @return the previous value of the key, or null if there was no mapping
* @throws NullPointerException if a key or value is null.
* @throws ClassCastException if a key or value is not a String.
*/
public String put(String key, String value)
{
if (key == null)
throw new NullPointerException("A new key is null.");
if (value == null)
throw new NullPointerException("A new value is null.");
if (!(key instanceof String))
throw new ClassCastException("A new key is not a String.");
if (!(value instanceof String))
throw new ClassCastException("A new value is not a String.");
return super.put(key, value);
}
/**
* Removes a key-value pair from the map. The queried key may not
* be null or of a type other than a <code>String</code>.
*
* @param key the key of the entry to remove.
* @return the removed value.
* @throws NullPointerException if the specified key is null.
* @throws ClassCastException if the specified key is not a String.
*/
public String remove(Object key)
{
if (key == null)
throw new
NullPointerException("This map does not support null keys.");
if (!(key instanceof String))
throw new
ClassCastException("This map only allows queries using Strings.");
return super.remove(key);
}
/**
* Returns a collection view of the values, with the same
* provisions as for the underlying map.
*
* @return a collection containing the values.
*/
public Collection<String> values()
{
if (values == null)
values = new EnvironmentCollection(super.values());
return values;
}
}
/**
* This is a specialised <code>Set</code>, providing
* the necessary provisions for the collections used by the
* environment variable map. Namely, it prevents
* modifications and the use of queries with null
* or non-<code>String</code> values.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
private static class EnvironmentSet
extends EnvironmentCollection
implements Set<String>
{
/**
* Constructs a new environment set, which
* wraps the elements of the supplied set.
*
* @param set the set to use as a base for
* this set.
*/
public EnvironmentSet(Set<String> set)
{
super(set);
}
/**
* This simply calls the same method on the wrapped
* collection.
*
* @param obj the object to compare with.
* @return true if the two objects are equal.
*/
public boolean equals(Object obj)
{
return c.equals(obj);
}
/**
* This simply calls the same method on the wrapped
* collection.
*
* @return the hashcode of the collection.
*/
public int hashCode()
{
return c.hashCode();
}
} // class EnvironmentSet<String>
} // class System
+65 -28
View File
@@ -143,6 +143,9 @@ public class Thread implements Runnable
/** This thread's ID. */
private final long threadId;
/** The park blocker. See LockSupport. */
Object parkBlocker;
/** The next thread number to use. */
private static int numAnonymousThreadsCreated;
@@ -352,9 +355,9 @@ public class Thread implements Runnable
if (group == null)
{
if (sm != null)
group = sm.getThreadGroup();
group = sm.getThreadGroup();
if (group == null)
group = current.group;
group = current.group;
}
if (sm != null)
sm.checkAccess(group);
@@ -398,7 +401,7 @@ public class Thread implements Runnable
this.vmThread = vmThread;
this.runnable = null;
if (name == null)
name = createAnonymousThreadName();
name = createAnonymousThreadName();
this.name = name;
this.priority = priority;
this.daemon = daemon;
@@ -413,11 +416,11 @@ public class Thread implements Runnable
// (and, as above, the constructiong sequence calls Thread.currenThread()).
contextClassLoaderIsSystemClassLoader = true;
synchronized (Thread.class)
{
this.threadId = ++totalThreadsCreated;
}
{
this.threadId = ++totalThreadsCreated;
}
}
/**
* Generate a name for an anonymous thread.
*/
@@ -466,7 +469,7 @@ public class Thread implements Runnable
{
VMThread t = vmThread;
if (t == null || group == null)
throw new IllegalThreadStateException();
throw new IllegalThreadStateException();
return t.countStackFrames();
}
@@ -610,7 +613,7 @@ public class Thread implements Runnable
checkAccess();
VMThread t = vmThread;
if (t != null)
t.interrupt();
t.interrupt();
}
/**
@@ -701,12 +704,12 @@ public class Thread implements Runnable
*/
public final void join(long ms, int ns) throws InterruptedException
{
if(ms < 0 || ns < 0 || ns > 999999)
throw new IllegalArgumentException();
if (ms < 0 || ns < 0 || ns > 999999)
throw new IllegalArgumentException();
VMThread t = vmThread;
if(t != null)
t.join(ms, ns);
if (t != null)
t.join(ms, ns);
}
/**
@@ -724,7 +727,7 @@ public class Thread implements Runnable
checkAccess();
VMThread t = vmThread;
if (t != null)
t.resume();
t.resume();
}
/**
@@ -828,9 +831,9 @@ public class Thread implements Runnable
throw new NullPointerException();
VMThread t = vmThread;
if (t != null)
t.setName(name);
t.setName(name);
else
this.name = name;
this.name = name;
}
/**
@@ -850,11 +853,13 @@ public class Thread implements Runnable
* are no guarantees which thread will be next to run, but most VMs will
* choose the highest priority thread that has been waiting longest.
*
* @param ms the number of milliseconds to sleep.
* @param ms the number of milliseconds to sleep, or 0 for forever
* @throws InterruptedException if the Thread is (or was) interrupted;
* it's <i>interrupted status</i> will be cleared
* @throws IllegalArgumentException if ms is negative
* @see #interrupt()
* @see #notify()
* @see #wait(long)
*/
public static void sleep(long ms) throws InterruptedException
{
@@ -874,17 +879,18 @@ public class Thread implements Runnable
* immediately when time expires, because some other thread may be
* active. So don't expect real-time performance.
*
* @param ms the number of milliseconds to sleep
* @param ms the number of milliseconds to sleep, or 0 for forever
* @param ns the number of extra nanoseconds to sleep (0-999999)
* @throws InterruptedException if the Thread is (or was) interrupted;
* it's <i>interrupted status</i> will be cleared
* @throws IllegalArgumentException if ms or ns is negative
* or ns is larger than 999999.
* @see #interrupt()
* @see #notify()
* @see #wait(long, int)
*/
public static void sleep(long ms, int ns) throws InterruptedException
{
// Check parameters
if (ms < 0 )
throw new IllegalArgumentException("Negative milliseconds: " + ms);
@@ -909,7 +915,7 @@ public class Thread implements Runnable
public synchronized void start()
{
if (vmThread != null || group == null)
throw new IllegalThreadStateException();
throw new IllegalThreadStateException();
VMThread.create(this, stacksize);
}
@@ -1006,7 +1012,7 @@ public class Thread implements Runnable
checkAccess();
VMThread t = vmThread;
if (t != null)
t.suspend();
t.suspend();
}
/**
@@ -1033,9 +1039,9 @@ public class Thread implements Runnable
priority = Math.min(priority, group.getMaxPriority());
VMThread t = vmThread;
if (t != null)
t.setPriority(priority);
t.setPriority(priority);
else
this.priority = priority;
this.priority = priority;
}
/**
@@ -1229,6 +1235,37 @@ public class Thread implements Runnable
void uncaughtException(Thread thr, Throwable exc);
}
/**
* <p>
* Represents the current state of a thread, according to the VM rather
* than the operating system. It can be one of the following:
* </p>
* <ul>
* <li>NEW -- The thread has just been created but is not yet running.</li>
* <li>RUNNABLE -- The thread is currently running or can be scheduled
* to run.</li>
* <li>BLOCKED -- The thread is blocked waiting on an I/O operation
* or to obtain a lock.</li>
* <li>WAITING -- The thread is waiting indefinitely for another thread
* to do something.</li>
* <li>TIMED_WAITING -- The thread is waiting for a specific amount of time
* for another thread to do something.</li>
* <li>TERMINATED -- The thread has exited.</li>
* </ul>
*
* @since 1.5
*/
public enum State
{
BLOCKED, NEW, RUNNABLE, TERMINATED, TIMED_WAITING, WAITING;
/**
* For compatability with Sun's JDK
*/
private static final long serialVersionUID = 605505746047245783L;
}
/**
* Returns the current state of the thread. This
* is designed for monitoring thread behaviour, rather
@@ -1236,14 +1273,14 @@ public class Thread implements Runnable
*
* @return the current thread state.
*/
public String getState()
public State getState()
{
VMThread t = vmThread;
if (t != null)
return t.getState();
return State.valueOf(t.getState());
if (group == null)
return "TERMINATED";
return "NEW";
return State.TERMINATED;
return State.NEW;
}
/**
@@ -1279,7 +1316,7 @@ public class Thread implements Runnable
* @since 1.5
* @see #getStackTrace()
*/
public static Map getAllStackTraces()
public static Map<Thread, StackTraceElement[]> getAllStackTraces()
{
ThreadGroup group = currentThread().group;
while (group.getParent() != null)
+12 -12
View File
@@ -1,5 +1,5 @@
/* ThreadLocal -- a variable with a unique value per thread
Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation, Inc.
Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -84,16 +84,16 @@ import java.util.Map;
* @author Mark Wielaard (mark@klomp.org)
* @author Eric Blake (ebb9@email.byu.edu)
* @since 1.2
* @status updated to 1.4
* @status updated to 1.5
*/
public class ThreadLocal
public class ThreadLocal<T>
{
/**
* Placeholder to distinguish between uninitialized and null set by the
* user. Do not expose this to the public. Package visible for use by
* InheritableThreadLocal
*/
static final Object NULL = new Object();
static final Object sentinel = new Object();
/**
* Creates a ThreadLocal object without associating any value to it yet.
@@ -110,7 +110,7 @@ public class ThreadLocal
*
* @return the initial value of the variable in this thread
*/
protected Object initialValue()
protected T initialValue()
{
return null;
}
@@ -123,18 +123,18 @@ public class ThreadLocal
*
* @return the value of the variable in this thread
*/
public Object get()
public T get()
{
Map map = Thread.getThreadLocals();
Map<ThreadLocal<T>,T> map = (Map<ThreadLocal<T>,T>) Thread.getThreadLocals();
// Note that we don't have to synchronize, as only this thread will
// ever modify the map.
Object value = map.get(this);
T value = map.get(this);
if (value == null)
{
value = initialValue();
map.put(this, value == null ? NULL : value);
map.put(this, (T) (value == null ? sentinel : value));
}
return value == NULL ? null : value;
return value == (T) sentinel ? null : value;
}
/**
@@ -145,12 +145,12 @@ public class ThreadLocal
*
* @param value the value to set this thread's view of the variable to
*/
public void set(Object value)
public void set(T value)
{
Map map = Thread.getThreadLocals();
// Note that we don't have to synchronize, as only this thread will
// ever modify the map.
map.put(this, value == null ? NULL : value);
map.put(this, value == null ? sentinel : value);
}
/**
+3 -3
View File
@@ -1,5 +1,5 @@
/* Void.class - defines void.class
Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -49,7 +49,7 @@ package java.lang;
* @author John Keiser
* @author Eric Blake (ebb9@email.byu.edu)
* @since 1.1
* @status updated to 1.4
* @status updated to 1.5
*/
public final class Void
{
@@ -57,7 +57,7 @@ public final class Void
* The return type <code>void</code> is represented by this
* <code>Class</code> object.
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('V');
public static final Class<Void> TYPE = (Class<Void>) VMClassLoader.getPrimitiveClass('V');
/**
* Void is non-instantiable.
@@ -54,8 +54,7 @@ public interface Annotation
*
* @return the class of which this annotation is an instance.
*/
/* FIXME[GENERICS]: Should return Class<? extends Annotation> */
Class annotationType();
Class<? extends Annotation> annotationType();
/**
* <p>
@@ -0,0 +1,50 @@
/* Documented.java - Indicates documented source element
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.annotation;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
@Documented @Retention(RUNTIME)
public @interface Documented
{
}
@@ -0,0 +1,59 @@
/* ElementType.java - Enum listing Java source elements
Copyright (C) 2004 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.annotation;
/**
* @since 1.5
*/
public enum ElementType
{
ANNOTATION_TYPE,
CONSTRUCTOR,
FIELD,
LOCAL_VARIABLE,
METHOD,
PACKAGE,
PARAMETER,
TYPE;
/**
* For compatability with Sun's JDK
*/
private static final long serialVersionUID = 2798216111136361587L;
}
@@ -58,7 +58,8 @@ public class IncompleteAnnotationException extends RuntimeException
* @param type the type of annotation from which an element is missing.
* @param name the name of the missing element.
*/
public IncompleteAnnotationException(Class type, String name)
public IncompleteAnnotationException(Class<? extends Annotation> type,
String name)
{
this.annotationType = type;
this.elementName = name;
@@ -70,7 +71,7 @@ public class IncompleteAnnotationException extends RuntimeException
*
* @return the type of annotation.
*/
public Class annotationType()
public Class<? extends Annotation> annotationType()
{
return annotationType;
}
@@ -94,7 +95,7 @@ public class IncompleteAnnotationException extends RuntimeException
* @serial the type of the annotation from which an
* element was missing.
*/
private Class annotationType;
private Class<? extends Annotation> annotationType;
/**
* The name of the missing element.
@@ -0,0 +1,51 @@
/* Inherited.java - Indicates inherited annotation
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.annotation;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
/**
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE)
public @interface Inherited
{
}
@@ -0,0 +1,59 @@
/* Retention.java - Retention policy for an annotation
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.annotation;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
/**
* This annotation is used to specify the desired lifetime of another
* annotation.
*
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @see RetentionPolicy
* @since 1.5
*/
@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE)
public @interface Retention
{
/**
* The value holds the lifetime of the annotation.
*/
RetentionPolicy value();
}
@@ -0,0 +1,66 @@
/* RetentionPolicy.java - Enum listing lifetimes for an annotation
Copyright (C) 2004 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.annotation;
/**
* This enum is used to control the lifetime of an annotation.
*
* @see Retention
*
* @since 1.5
*/
public enum RetentionPolicy
{
/** Indicates that the annotation should be stored in class files. */
CLASS,
/** Indicates that the annotation should be available at runtime. */
RUNTIME,
/**
* Indicates that the annotation should only be available when
* parsing the source code.
*/
SOURCE;
/**
* For compatability with Sun's JDK
*/
private static final long serialVersionUID = -1700821648800605045L;
}
@@ -0,0 +1,52 @@
/* Target.java - Indicate where an annotation may be applied
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.annotation;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
/**
* @author Tom Tromey (tromey@redhat.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE)
public @interface Target
{
ElementType[] value();
}
@@ -0,0 +1,58 @@
# This property file contains dependencies of classes, methods, and
# field on other methods or classes.
#
# Syntax:
#
# <used>: <needed 1> [... <needed N>]
#
# means that when <used> is included, <needed 1> (... <needed N>) must
# be included as well.
#
# <needed X> and <used> are of the form
#
# <class.methodOrField(signature)>
#
# or just
#
# <class>
#
# Within dependencies, variables can be used. A variable is defined as
# follows:
#
# {variable}: value1 value2 ... value<n>
#
# variables can be used on the right side of dependencies as follows:
#
# <used>: com.bla.blu.{variable}.Class.m()V
#
# The use of the variable will expand to <n> dependencies of the form
#
# <used>: com.bla.blu.value1.Class.m()V
# <used>: com.bla.blu.value2.Class.m()V
# ...
# <used>: com.bla.blu.value<n>.Class.m()V
#
# Variables can be redefined when building a system to select the
# required support for features like encodings, protocols, etc.
#
# Hints:
#
# - For methods and fields, the signature is mandatory. For
# specification, please see the Java Virtual Machine Specification by
# SUN. Unlike in the spec, field signatures (types) are in brackets.
#
# - Package names must be separated by '/' (and not '.'). E.g.,
# java/lang/Class (this is necessary, because the '.' is used to
# separate method or field names from classes)
#
# - In case <needed> refers to a class, only the class itself will be
# included in the resulting binary, NOT necessarily all its methods
# and fields. If you want to refer to all methods and fields, you can
# write class.* as an abbreviation.
#
# - Abbreviations for packages are also possible: my/package/* means all
# methods and fields of all classes in my/package.
#
# - A line with a trailing '\' continues in the next line.
# end of file
@@ -60,8 +60,7 @@ public final class ClassDefinition
* @param theClassFile the new class file
* @throws NullPointerException if one of the argument is null
*/
/* FIXME[GENERICS]: Signature should be (Class<?>, byte[]) */
public ClassDefinition(Class theClass, byte[] theClassFile)
public ClassDefinition(Class<?> theClass, byte[] theClassFile)
{
if (theClass == null || theClassFile == null)
throw new NullPointerException();
@@ -72,8 +71,7 @@ public final class ClassDefinition
/**
* @return the Class
*/
/* FIXME[GENERICS]: Should return Class<?> */
public Class getDefinitionClass()
public Class<?> getDefinitionClass()
{
return theClass;
}
@@ -75,10 +75,9 @@ public interface ClassFileTransformer
* @see Instrumentation#redefineClasses(java.lang.instrument.ClassDefinition[])
*
*/
/* FIXME[GENERICS]: Class should be Class<?> */
byte[] transform(ClassLoader loader,
String className,
Class classBeingRedefined,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer)
throws IllegalClassFormatException;
@@ -50,9 +50,18 @@ import gnu.java.lang.management.RuntimeMXBeanImpl;
import gnu.java.lang.management.ThreadMXBeanImpl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.LogManager;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
/**
* <p>
@@ -66,7 +75,55 @@ import javax.management.NotCompliantMBeanException;
* <ol>
* <li>Calling the appropriate static method of this factory.
* </li>
* <li>Using the platform {@link javax.management.MBeanServer}
* to access the beans locally, or an
* {@link javax.management.MBeanServerConnection} for remote
* access. The attributes and operations use the limited
* range of data types specified below.</li>
* </ol>
* <h2>Open Data Types</h2>
* <p>
* The data types used by the management beans are restricted
* to <emph>open</emph> data types to aid interoperability. This
* allows the beans to be accessed remotely, including from non-Java
* clients. Below is a table which lists the types used by the beans
* on the left, and the types they are converted to when returned via
* a bean server on the right. Type information is provided for each
* bean by obtaining its instance of {@link javax.management.MBeanInfo}.
* </p>
* <table>
* <th><td>Data Type Used</td><td>Data Type Returned</td></th>
* <tr>
* <td>Primitive types (<code>int</code>, <code>char</code>, etc.)</td>
* <td>Same</td>
* </tr><tr>
* <td>Wrapper classes ({@link{java.lang.Integer},
* @link{java.lang.Character}, etc.)</td>
* <td>Same</td>
* </tr><tr>
* <td>An {@link java.lang.Enum}</td>
* <td>The <code>name</code> of the enumeration constant</td>
* </tr><tr>
* <td>An array of type <code>E</code></td>
* <td>An array of the same dimensions with this mapping applied
* to <code>E</code>.</td>
* </tr><tr>
* <td>A class with `getter' methods and a
* <code>from({@link javax.management.openmbean.CompositeData})</code>
* method.</td>
* <td>The equivalent {@link javax.management.openmbean.CompositeData}
* instance, specified by the <code>from</code> method.</td>
* </tr><tr>
* <td>A map with keys of type <code>K</code> and values of
* type <code>V</code>.</td>
* <td>A {@link javax.management.openmbean.TabularData} instance,
* with the row type containing two items, <code>"key"</code> and
* <code>"value"</code> with the types <code>K</code> and <code>V</code>
* respectively (with translation applied).</td>
* </tr><tr>
* <td>A list of type <code>E</code>.</td>
* <td>An array with this mapping applied to <code>E</code>.</td>
* </tr></table>
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
@@ -74,6 +131,60 @@ import javax.management.NotCompliantMBeanException;
public class ManagementFactory
{
/**
* The object name for the class loading bean.
*/
public static final String CLASS_LOADING_MXBEAN_NAME =
"java.lang:type=ClassLoading";
/**
* The object name for the compilation bean.
*/
public static final String COMPILATION_MXBEAN_NAME =
"java.lang:type=Compilation";
/**
* The domain for the garbage collecting beans.
*/
public static final String GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE =
"java.lang:type=GarbageCollector";
/**
* The domain for the memory manager beans.
*/
public static final String MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE =
"java.lang:type=MemoryManager";
/**
* The object name for the memory bean.
*/
public static final String MEMORY_MXBEAN_NAME =
"java.lang:type=Memory";
/**
* The domain for the memory pool beans.
*/
public static final String MEMORY_POOL_MXBEAN_DOMAIN_TYPE =
"java.lang:type=MemoryPool";
/**
* The object name for the operating system bean.
*/
public static final String OPERATING_SYSTEM_MXBEAN_NAME =
"java.lang:type=OperatingSystem";
/**
* The object name for the runtime bean.
*/
public static final String RUNTIME_MXBEAN_NAME =
"java.lang:type=Runtime";
/**
* The object name for the threading bean.
*/
public static final String THREAD_MXBEAN_NAME =
"java.lang:type=Threading";
/**
* The operating system management bean.
*/
@@ -104,6 +215,11 @@ public class ManagementFactory
*/
private static CompilationMXBean compilationBean;
/**
* The platform server.
*/
private static MBeanServer platformServer;
/**
* Private constructor to prevent instance creation.
*/
@@ -258,9 +374,10 @@ public class ManagementFactory
*
* @return a list of memory pool beans, one for each pool.
*/
public static List getMemoryPoolMXBeans()
public static List<MemoryPoolMXBean> getMemoryPoolMXBeans()
{
List poolBeans = new ArrayList();
List<MemoryPoolMXBean> poolBeans =
new ArrayList<MemoryPoolMXBean>();
String[] names = VMManagementFactory.getMemoryPoolNames();
for (int a = 0; a < names.length; ++a)
try
@@ -283,9 +400,10 @@ public class ManagementFactory
*
* @return a list of memory manager beans, one for each manager.
*/
public static List getMemoryManagerMXBeans()
public static List<MemoryManagerMXBean> getMemoryManagerMXBeans()
{
List managerBeans = new ArrayList();
List<MemoryManagerMXBean> managerBeans =
new ArrayList<MemoryManagerMXBean>();
String[] names = VMManagementFactory.getMemoryManagerNames();
for (int a = 0; a < names.length; ++a)
try
@@ -309,9 +427,10 @@ public class ManagementFactory
*
* @return a list of garbage collector beans, one for each pool.
*/
public static List getGarbageCollectorMXBeans()
public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans()
{
List gcBeans = new ArrayList();
List<GarbageCollectorMXBean> gcBeans =
new ArrayList<GarbageCollectorMXBean>();
String[] names = VMManagementFactory.getGarbageCollectorNames();
for (int a = 0; a < names.length; ++a)
try
@@ -328,4 +447,106 @@ public class ManagementFactory
return gcBeans;
}
/**
* <p>
* Returns the platform {@link javax.management.MBeanServer}. On the
* first call to this method, a server instance is retrieved from
* the {@link javax.management.MBeanServerFactory} and each of the
* beans are registered with it. Subsequent calls return the existing
* instance. If the property <code>javax.management.builder.initial</code>
* is set, its value will be used as the name of the class which is used
* to provide the server instance.
* </p>
* <p>
* It is recommended that the platform server is used for other beans as
* well, in order to simplify their discovery and publication. Name conflicts
* should be avoided.
* </p>
*
* @return the platform {@link javax.management.MBeanServer}
* @throws SecurityException if a security manager exists and the
* caller's permissions don't imply {@link
* MBeanServerPermission(String)}("createMBeanServer")
* @see javax.management.MBeanServerFactory
* @see javax.management.MBeanServerFactory#createMBeanServer()
*/
public static MBeanServer getPlatformMBeanServer()
{
if (platformServer == null)
{
platformServer = MBeanServerFactory.createMBeanServer();
try
{
platformServer.registerMBean(getOperatingSystemMXBean(),
new ObjectName(OPERATING_SYSTEM_MXBEAN_NAME));
platformServer.registerMBean(getRuntimeMXBean(),
new ObjectName(RUNTIME_MXBEAN_NAME));
platformServer.registerMBean(getClassLoadingMXBean(),
new ObjectName(CLASS_LOADING_MXBEAN_NAME));
platformServer.registerMBean(getThreadMXBean(),
new ObjectName(THREAD_MXBEAN_NAME));
platformServer.registerMBean(getMemoryMXBean(),
new ObjectName(MEMORY_MXBEAN_NAME));
CompilationMXBean compBean = getCompilationMXBean();
if (compBean != null)
platformServer.registerMBean(compBean,
new ObjectName(COMPILATION_MXBEAN_NAME));
Iterator beans = getMemoryPoolMXBeans().iterator();
while (beans.hasNext())
{
MemoryPoolMXBean bean = (MemoryPoolMXBean) beans.next();
platformServer.registerMBean(bean,
new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE +
",name=" +
bean.getName()));
}
beans = getMemoryManagerMXBeans().iterator();
while (beans.hasNext())
{
MemoryManagerMXBean bean = (MemoryManagerMXBean) beans.next();
platformServer.registerMBean(bean,
new ObjectName(MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE +
",name=" +
bean.getName()));
}
beans = getGarbageCollectorMXBeans().iterator();
while (beans.hasNext())
{
GarbageCollectorMXBean bean = (GarbageCollectorMXBean) beans.next();
platformServer.registerMBean(bean,
new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE +
",name=" +
bean.getName()));
}
platformServer.registerMBean(LogManager.getLoggingMXBean(),
new ObjectName(LogManager.LOGGING_MXBEAN_NAME));
}
catch (InstanceAlreadyExistsException e)
{
throw (Error)
(new InternalError("One of the management beans is " +
"already registered.").initCause(e));
}
catch (MBeanRegistrationException e)
{
throw (Error)
(new InternalError("One of the management beans' preRegister " +
"methods threw an exception.").initCause(e));
}
catch (NotCompliantMBeanException e)
{
throw (Error)
(new InternalError("One of the management beans is " +
"not compliant.").initCause(e));
}
catch (MalformedObjectNameException e)
{
throw (Error)
(new InternalError("The object name of a management bean is " +
"not compliant.").initCause(e));
}
}
return platformServer;
}
}
@@ -162,7 +162,7 @@ public interface MemoryPoolMXBean
*
* @return the type of this pool.
*/
String getType();
MemoryType getType();
/**
* Returns memory usage statistics for the current memory usage
@@ -0,0 +1,51 @@
/* MemoryType.java - Enumeration of the types of memory pools.
Copyright (C) 2006 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.management;
/**
* Enumerates the possible types of memory pools. A value of this
* type is returned by {@link MemoryPoolMXBean#getMemoryType()}.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public enum MemoryType
{
HEAP, NON_HEAP;
}
@@ -106,7 +106,7 @@ public interface RuntimeMXBean
* denies ManagementPermission("monitor").
* @see java.lang.management.ManagementPermission
*/
List getInputArguments();
List<String> getInputArguments();
/**
* Returns the library path. This is equivalent to obtaining the
@@ -212,7 +212,7 @@ public interface RuntimeMXBean
*
* @return the map of system properties.
*/
Map getSystemProperties();
Map<String,String> getSystemProperties();
/**
* Returns the uptime of the virtual machine in milliseconds.
@@ -102,7 +102,7 @@ public class ThreadInfo
/**
* The state of the thread which this instance concerns.
*/
private String threadState;
private Thread.State threadState;
/**
* The number of times the thread has been blocked.
@@ -200,10 +200,12 @@ public class ThreadInfo
long waitedTime, boolean isInNative, boolean isSuspended,
StackTraceElement[] trace)
{
this(thread.getId(), thread.getName(), thread.getState(), blockedCount,
blockedTime, lock.getClass().getName() + "@" +
Integer.toHexString(System.identityHashCode(lock)), lockOwner.getId(),
lockOwner.getName(), waitedCount, waitedTime, isInNative, isSuspended,
this(thread.getId(), thread.getName(), thread.getState(), blockedCount, blockedTime,
lock == null ? null : lock.getClass().getName() + "@" +
Integer.toHexString(System.identityHashCode(lock)),
lockOwner == null ? -1 : lockOwner.getId(),
lockOwner == null ? null : lockOwner.getName(),
waitedCount, waitedTime, isInNative, isSuspended,
trace);
}
@@ -240,7 +242,7 @@ public class ThreadInfo
* @param trace the stack trace of the thread to a pre-determined
* depth (see VMThreadMXBeanImpl)
*/
private ThreadInfo(long threadId, String threadName, String threadState,
private ThreadInfo(long threadId, String threadName, Thread.State threadState,
long blockedCount, long blockedTime, String lockName,
long lockOwnerId, String lockOwnerName, long waitedCount,
long waitedTime, boolean isInNative, boolean isSuspended,
@@ -387,7 +389,7 @@ public class ThreadInfo
dTraces[a].get("lineNumber")).intValue());
return new ThreadInfo(((Long) data.get("threadId")).longValue(),
(String) data.get("threadName"),
(String) data.get("threadState"),
Thread.State.valueOf((String) data.get("threadState")),
((Long) data.get("blockedCount")).longValue(),
((Long) data.get("blockedTime")).longValue(),
(String) data.get("lockName"),
@@ -484,7 +486,7 @@ public class ThreadInfo
*/
public String getLockName()
{
if (threadState.equals("BLOCKED"))
if (threadState != Thread.State.BLOCKED)
return null;
return lockName;
}
@@ -502,7 +504,7 @@ public class ThreadInfo
*/
public long getLockOwnerId()
{
if (threadState.equals("BLOCKED"))
if (threadState != Thread.State.BLOCKED)
return -1;
return lockOwnerId;
}
@@ -520,7 +522,7 @@ public class ThreadInfo
*/
public String getLockOwnerName()
{
if (threadState.equals("BLOCKED"))
if (threadState != Thread.State.BLOCKED)
return null;
return lockOwnerName;
}
@@ -577,7 +579,7 @@ public class ThreadInfo
*
* @return the thread's state.
*/
public String getThreadState()
public Thread.State getThreadState()
{
return threadState;
}
@@ -695,7 +697,7 @@ public class ThreadInfo
", waitedCount=" + waitedCount +
", isInNative=" + isInNative +
", isSuspended=" + isSuspended +
(threadState.equals("BLOCKED") ?
(threadState == Thread.State.BLOCKED ?
", lockOwnerId=" + lockOwnerId +
", lockOwnerName=" + lockOwnerName : "") +
"]";
@@ -1,5 +1,5 @@
/* java.lang.ref.PhantomReference
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -46,8 +46,8 @@ package java.lang.ref;
*
* @author Jochen Hoenicke
*/
public class PhantomReference
extends Reference
public class PhantomReference<T>
extends Reference<T>
{
/**
* Creates a new phantom reference.
@@ -56,7 +56,7 @@ public class PhantomReference
* finalized. This mustn't be <code>null</code>.
* @exception NullPointerException if q is null.
*/
public PhantomReference(Object referent, ReferenceQueue q)
public PhantomReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
@@ -66,7 +66,7 @@ public class PhantomReference
* @return <code>null</code>, since the refered object may be
* finalized and thus not accessible.
*/
public Object get()
public T get()
{
return null;
}
+11 -12
View File
@@ -1,5 +1,5 @@
/* java.lang.ref.Reference
Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -70,19 +70,19 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see java.util.WeakHashMap
*/
public abstract class Reference
public abstract class Reference<T>
{
/**
* The underlying object. This field is handled in a special way by
* the garbage collector.
*/
Object referent;
T referent;
/**
* The queue this reference is registered on. This is null, if this
* wasn't registered to any queue or reference was already enqueued.
*/
ReferenceQueue queue;
volatile ReferenceQueue<? super T> queue;
/**
* Link to the next entry on the queue. If this is null, this
@@ -91,7 +91,7 @@ public abstract class Reference
* (not to null, that value is used to mark a not enqueued
* reference).
*/
Reference nextOnQueue;
volatile Reference nextOnQueue;
/**
* This lock should be taken by the garbage collector, before
@@ -106,7 +106,7 @@ public abstract class Reference
* class in a different package.
* @param ref the object we refer to.
*/
Reference(Object ref)
Reference(T ref)
{
referent = ref;
}
@@ -119,7 +119,7 @@ public abstract class Reference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
Reference(Object ref, ReferenceQueue q)
Reference(T ref, ReferenceQueue<? super T> q)
{
if (q == null)
throw new NullPointerException();
@@ -132,7 +132,7 @@ public abstract class Reference
* @return the object, this reference refers to, or null if the
* reference was cleared.
*/
public Object get()
public T get()
{
synchronized (lock)
{
@@ -166,11 +166,10 @@ public abstract class Reference
*/
public boolean enqueue()
{
if (queue != null && nextOnQueue == null)
ReferenceQueue q = queue;
if (q != null)
{
queue.enqueue(this);
queue = null;
return true;
return q.enqueue(this);
}
return false;
}
@@ -1,5 +1,5 @@
/* java.lang.ref.ReferenceQueue
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -50,7 +50,7 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see Reference#enqueue()
*/
public class ReferenceQueue
public class ReferenceQueue<T>
{
/**
* This is a linked list of references. If this is null, the list is
@@ -60,7 +60,13 @@ public class ReferenceQueue
* itself (not to null, since <code>nextOnQueue</code> is used to
* determine if a reference is enqueued).
*/
private Reference first;
private Reference<? extends T> first;
/**
* This is the lock that protects our linked list and is used to signal
* a thread waiting in remove().
*/
private final Object lock = new Object();
/**
* Creates a new empty reference queue.
@@ -76,7 +82,7 @@ public class ReferenceQueue
* @return a reference on the queue, if there is one,
* <code>null</code> otherwise.
*/
public synchronized Reference poll()
public Reference<? extends T> poll()
{
return dequeue();
}
@@ -84,29 +90,41 @@ public class ReferenceQueue
/**
* This is called by reference to enqueue itself on this queue.
* @param ref the reference that should be enqueued.
* @return true if successful, false if not.
*/
synchronized void enqueue(Reference ref)
{
/* last reference will point to itself */
ref.nextOnQueue = first == null ? ref : first;
first = ref;
/* this wakes only one remove thread. */
notify();
final boolean enqueue(Reference<? extends T> ref)
{
synchronized (lock)
{
if (ref.queue != this)
return false;
/* last reference will point to itself */
ref.nextOnQueue = first == null ? ref : first;
ref.queue = null;
first = ref;
/* this wakes only one remove thread. */
lock.notify();
return true;
}
}
/**
* Remove a reference from the queue, if there is one.
* @return the first element of the queue, or null if there isn't any.
*/
private Reference dequeue()
private Reference<? extends T> dequeue()
{
if (first == null)
return null;
Reference result = first;
first = (first == first.nextOnQueue) ? null : first.nextOnQueue;
result.nextOnQueue = null;
return result;
synchronized (lock)
{
if (first == null)
return null;
Reference<? extends T> result = first;
first = (first == first.nextOnQueue) ? null : first.nextOnQueue;
result.nextOnQueue = null;
return result;
}
}
/**
@@ -118,12 +136,13 @@ public class ReferenceQueue
* <code>null</code> if timeout period expired.
* @exception InterruptedException if the wait was interrupted.
*/
public synchronized Reference remove(long timeout)
public Reference<? extends T> remove(long timeout)
throws InterruptedException
{
if (first == null)
synchronized (lock)
{
wait(timeout);
if (first == null)
lock.wait(timeout);
}
return dequeue();
@@ -137,7 +156,7 @@ public class ReferenceQueue
* @return the reference removed from the queue.
* @exception InterruptedException if the wait was interrupted.
*/
public Reference remove()
public Reference<? extends T> remove()
throws InterruptedException
{
return remove(0L);
@@ -1,5 +1,5 @@
/* java.lang.ref.SoftReference
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -47,14 +47,14 @@ package java.lang.ref;
*
* @author Jochen Hoenicke
*/
public class SoftReference
extends Reference
public class SoftReference<T>
extends Reference<T>
{
/**
* Create a new soft reference, that is not registered to any queue.
* @param referent the object we refer to.
*/
public SoftReference(Object referent)
public SoftReference(T referent)
{
super(referent);
}
@@ -65,7 +65,7 @@ public class SoftReference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
public SoftReference(Object referent, ReferenceQueue q)
public SoftReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
@@ -75,7 +75,7 @@ public class SoftReference
* @return the object, this reference refers to, or null if the
* reference was cleared.
*/
public Object get()
public T get()
{
/* Why is this overloaded???
* Maybe for a kind of LRU strategy. */
@@ -1,5 +1,5 @@
/* java.lang.ref.WeakReference
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,14 +54,14 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see java.util.WeakHashMap
*/
public class WeakReference
extends Reference
public class WeakReference<T>
extends Reference<T>
{
/**
* Create a new weak reference, that is not registered to any queue.
* @param referent the object we refer to.
*/
public WeakReference(Object referent)
public WeakReference(T referent)
{
super(referent);
}
@@ -72,7 +72,7 @@ public class WeakReference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
public WeakReference(Object referent, ReferenceQueue q)
public WeakReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
@@ -160,8 +160,7 @@ public class AccessibleObject
this.flag = flag;
}
/* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
public Annotation getAnnotation(Class annotationClass)
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
{
throw new AssertionError("Subclass must override this method");
}
@@ -176,8 +175,7 @@ public class AccessibleObject
throw new AssertionError("Subclass must override this method");
}
/* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
public boolean isAnnotationPresent(Class annotationClass)
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
{
return getAnnotation(annotationClass) != null;
}
@@ -74,8 +74,7 @@ public interface AnnotatedElement
* <code>null</code> if no such annotation exists.
* @throws NullPointerException if the annotation class is <code>null</code>.
*/
/* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
Annotation getAnnotation(Class annotationClass);
<T extends Annotation> T getAnnotation(Class<T> annotationClass);
/**
* Returns all annotations associated with the element. If there are
@@ -111,7 +110,6 @@ public interface AnnotatedElement
* @return true if an annotation exists for the specified type.
* @since 1.5
*/
/* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
boolean isAnnotationPresent(Class annotationClass);
boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
}
@@ -95,7 +95,7 @@ public final class Array
* @throws NegativeArraySizeException when length is less than 0
* @throws OutOfMemoryError if memory allocation fails
*/
public static Object newInstance(Class componentType, int length)
public static Object newInstance(Class<?> componentType, int length)
{
if (! componentType.isPrimitive())
return VMArray.createObjectArray(componentType, length);
@@ -143,7 +143,7 @@ public final class Array
* than 0
* @throws OutOfMemoryError if memory allocation fails
*/
public static Object newInstance(Class componentType, int[] dimensions)
public static Object newInstance(Class<?> componentType, int[] dimensions)
{
if (dimensions.length <= 0)
throw new IllegalArgumentException ("Empty dimensions array.");
@@ -58,6 +58,5 @@ public interface GenericDeclaration
* class file does not conform to that specified in the 3rd edition
* of the Java Virtual Machine Specification.
*/
/* FIXME[GENERICS]: Should be TypeVariable<?>[] */
TypeVariable[] getTypeParameters();
TypeVariable<?>[] getTypeParameters();
}
@@ -156,7 +156,7 @@ import java.util.Set;
* @see Class
* @author Eric Blake (ebb9@email.byu.edu)
* @since 1.3
* @status updated to 1.4, except for the use of ProtectionDomain
* @status updated to 1.5, except for the use of ProtectionDomain
*/
public class Proxy implements Serializable
{
@@ -255,8 +255,8 @@ public class Proxy implements Serializable
*/
// synchronized so that we aren't trying to build the same class
// simultaneously in two threads
public static synchronized Class getProxyClass(ClassLoader loader,
Class[] interfaces)
public static synchronized Class<?> getProxyClass(ClassLoader loader,
Class<?>... interfaces)
{
interfaces = (Class[]) interfaces.clone();
ProxyType pt = new ProxyType(loader, interfaces);
@@ -310,7 +310,7 @@ public class Proxy implements Serializable
* @see Constructor#newInstance(Object[])
*/
public static Object newProxyInstance(ClassLoader loader,
Class[] interfaces,
Class<?>[] interfaces,
InvocationHandler handler)
{
try
@@ -358,7 +358,7 @@ public class Proxy implements Serializable
*/
// This is synchronized on the off chance that another thread is
// trying to add a class to the map at the same time we read it.
public static synchronized boolean isProxyClass(Class clazz)
public static synchronized boolean isProxyClass(Class<?> clazz)
{
if (! Proxy.class.isAssignableFrom(clazz))
return false;
@@ -58,9 +58,7 @@ package java.lang.reflect;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
/* FIXME[GENERICS]: Should be TypeVariable<T extends GenericDeclaration> */
public interface TypeVariable
extends Type
public interface TypeVariable<T extends GenericDeclaration> extends Type
{
/**
@@ -86,8 +84,7 @@ public interface TypeVariable
* @return the <code>GenericDeclaration</code> object for this type
* variable.
*/
/* FIXME[GENERICS]: Should return type T */
GenericDeclaration getGenericDeclaration();
T getGenericDeclaration();
/**
* Returns the name of the type variable, as written in the source