diff options
author | Tom Tromey <tromey@redhat.com> | 2007-02-01 20:34:08 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-02-01 20:34:08 +0000 |
commit | 0a32f469ac256a842ac1f721c37dab7ad2cf5e21 (patch) | |
tree | 045d28c226132bbb212ffd4956739e8e6fde799b /libjava/java/util | |
parent | 62e5bf5d4203458b41813a79213b3f513a4ca98c (diff) | |
download | gcc-0a32f469ac256a842ac1f721c37dab7ad2cf5e21.zip gcc-0a32f469ac256a842ac1f721c37dab7ad2cf5e21.tar.gz gcc-0a32f469ac256a842ac1f721c37dab7ad2cf5e21.tar.bz2 |
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
Diffstat (limited to 'libjava/java/util')
-rw-r--r-- | libjava/java/util/Calendar.java | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/libjava/java/util/Calendar.java b/libjava/java/util/Calendar.java index 5559d8c..6c0d721 100644 --- a/libjava/java/util/Calendar.java +++ b/libjava/java/util/Calendar.java @@ -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(); } /** @@ -1176,6 +1203,31 @@ public abstract class Calendar implements Serializable, Cloneable } /** + * 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. */ public Object clone() |