Calendar.java: Implement Comparable<Calendar>.

* java/util/Calendar.java: Implement Comparable<Calendar>.  Update
	comments.
	(clear): Call complete.
	(setTimeZone): Call computeTime, computeFields.
	(compareTo): New method.
	* java/nio/charset/Charset.java: Implement Comparable<Charset>.
	(availableCharsets): Genericized.
	(aliases): Likewise.
	(compareTo): Changed argument type.
	* java/lang/ClassLoader.java (loadClass): Genericized.
	(findClass): Likewise.
	(defineClass): Likewise.
	(resolveClass): Likewise.
	(findSystemClass): Likewise.
	(setSigners): Likewise.
	(findLoadedClass): Likewise.
	(getResources): Likewise.
	(findResources): Likewise.
	(getSystemResources): Likewise.
	(checkInitialized): New method.
	* java/lang/Class.java (getCanonicalName): New method.

From-SVN: r121471
This commit is contained in:
Tom Tromey
2007-02-01 20:34:08 +00:00
committed by Tom Tromey
parent 62e5bf5d42
commit 0a32f469ac
11 changed files with 193 additions and 46 deletions
+58 -6
View File
@@ -1,5 +1,6 @@
/* Calendar.java --
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -103,7 +104,8 @@ day_of_week + week_of_year</pre>
* @see TimeZone
* @see java.text.DateFormat
*/
public abstract class Calendar implements Serializable, Cloneable
public abstract class Calendar
implements Serializable, Cloneable, Comparable<Calendar>
{
/**
* Constant representing the era time field.
@@ -460,6 +462,8 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Creates a calendar representing the actual time, using the default
* time zone and locale.
*
* @return The new calendar.
*/
public static synchronized Calendar getInstance()
{
@@ -469,7 +473,12 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Creates a calendar representing the actual time, using the given
* time zone and the default locale.
* @param zone a time zone.
*
* @param zone a time zone (<code>null</code> not permitted).
*
* @return The new calendar.
*
* @throws NullPointerException if <code>zone</code> is <code>null</code>.
*/
public static synchronized Calendar getInstance(TimeZone zone)
{
@@ -479,7 +488,12 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Creates a calendar representing the actual time, using the default
* time zone and the given locale.
* @param locale a locale.
*
* @param locale a locale (<code>null</code> not permitted).
*
* @return The new calendar.
*
* @throws NullPointerException if <code>locale</code> is <code>null</code>.
*/
public static synchronized Calendar getInstance(Locale locale)
{
@@ -501,8 +515,14 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Creates a calendar representing the actual time, using the given
* time zone and locale.
* @param zone a time zone.
* @param locale a locale.
*
* @param zone a time zone (<code>null</code> not permitted).
* @param locale a locale (<code>null</code> not permitted).
*
* @return The new calendar.
*
* @throws NullPointerException if <code>zone</code> or <code>locale</code>
* is <code>null</code>.
*/
public static synchronized Calendar getInstance(TimeZone zone, Locale locale)
{
@@ -600,6 +620,10 @@ public abstract class Calendar implements Serializable, Cloneable
/**
* Sets this Calendar's time to the given Date. All time fields
* are invalidated by this method.
*
* @param date the date (<code>null</code> not permitted).
*
* @throws NullPointerException if <code>date</code> is <code>null</code>.
*/
public final void setTime(Date date)
{
@@ -860,6 +884,7 @@ public abstract class Calendar implements Serializable, Cloneable
1, 1970, JANUARY, 1, 1, 1, 1, THURSDAY, 1, AM, 0, 0, 0,
0, 0, zone.getRawOffset(), 0
};
complete();
isTimeSet = false;
areFieldsSet = false;
isSet[field] = false;
@@ -1020,6 +1045,8 @@ public abstract class Calendar implements Serializable, Cloneable
public void setTimeZone(TimeZone zone)
{
this.zone = zone;
computeTime();
computeFields();
}
/**
@@ -1175,6 +1202,31 @@ public abstract class Calendar implements Serializable, Cloneable
return max;
}
/**
* Compares the time of two calendar instances.
* @param calendar the calendar to which the time should be compared.
* @return 0 if the two calendars are set to the same time,
* less than 0 if the time of this calendar is before that of
* <code>cal</code>, or more than 0 if the time of this calendar is after
* that of <code>cal</code>.
*
* @param cal the calendar to compare this instance with.
* @throws NullPointerException if <code>cal</code> is null.
* @throws IllegalArgumentException if either calendar has fields set to
* invalid values.
* @since 1.5
*/
public int compareTo(Calendar cal)
{
long t1 = getTimeInMillis();
long t2 = cal.getTimeInMillis();
if(t1 == t2)
return 0;
if(t1 > t2)
return 1;
return -1;
}
/**
* Return a clone of this object.
*/