From 501270975a91bb86caf11a27390868612ca897d3 Mon Sep 17 00:00:00 2001 From: tromey Date: Thu, 1 Feb 2007 20:34:08 +0000 Subject: * java/util/Calendar.java: Implement Comparable. Update comments. (clear): Call complete. (setTimeZone): Call computeTime, computeFields. (compareTo): New method. * java/nio/charset/Charset.java: Implement Comparable. (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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121471 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/util/Calendar.java | 64 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 'libjava/java/util/Calendar.java') diff --git a/libjava/java/util/Calendar.java b/libjava/java/util/Calendar.java index 5559d8c53f4..6c0d7213dea 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 * @see TimeZone * @see java.text.DateFormat */ -public abstract class Calendar implements Serializable, Cloneable +public abstract class Calendar + implements Serializable, Cloneable, Comparable { /** * 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 (null not permitted). + * + * @return The new calendar. + * + * @throws NullPointerException if zone is null. */ 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 (null not permitted). + * + * @return The new calendar. + * + * @throws NullPointerException if locale is null. */ 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 (null not permitted). + * @param locale a locale (null not permitted). + * + * @return The new calendar. + * + * @throws NullPointerException if zone or locale + * is null. */ 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 (null not permitted). + * + * @throws NullPointerException if date is null. */ 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 + * cal, or more than 0 if the time of this calendar is after + * that of cal. + * + * @param cal the calendar to compare this instance with. + * @throws NullPointerException if cal 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. */ -- cgit v1.2.1