DateFormat.java (format): Throw IllegalArgumentException if j' is not a Number or...
authorBryce McKinlay <bryce@mckinlay.net.nz>
Sun, 28 Sep 2003 04:23:29 +0000 (04:23 +0000)
committerBryce McKinlay <bryce@gcc.gnu.org>
Sun, 28 Sep 2003 04:23:29 +0000 (05:23 +0100)
* java/text/DateFormat.java (format): Throw IllegalArgumentException
if j' is not a Number or Date instance.
* java/text/SimpleDateFormat.java (tokens): Make it an ArrayList
instead of Vector.

From-SVN: r71871

libjava/ChangeLog
libjava/java/text/DateFormat.java
libjava/java/text/SimpleDateFormat.java

index 1aa4f49b200a45d1d9ab4395ae3110edeccc9a84..b8e67b6d1224813bfe5a85db66a3ba84df81fc5e 100644 (file)
@@ -1,6 +1,13 @@
 2003-09-28  Bryce McKinlay  <bryce@mckinlay.net.nz>
 
-       * java/text/SimpleDateFormat (parse): Revert patch of 2003-09-25.
+       * java/text/DateFormat.java (format): Throw IllegalArgumentException
+       if `obj' is not a Number or Date instance.
+       * java/text/SimpleDateFormat.java (tokens): Make it an ArrayList
+       instead of Vector.
+
+2003-09-28  Bryce McKinlay  <bryce@mckinlay.net.nz>
+
+       * java/text/SimpleDateFormat.java (parse): Revert patch of 2003-09-25.
        Don't call setTimeZone on calendar.
 
 2003-09-27  Michael Koch  <konqueror@gmx.de>
index df2b270e4f34d05456a66eb2d65aa56bba6931eb..76bf535577a6cb483c73b6706e4779c1eb2baba3 100644 (file)
@@ -151,6 +151,8 @@ public abstract class DateFormat extends Format implements Cloneable
   {
     if (obj instanceof Number)
       obj = new Date(((Number) obj).longValue());
+    else if (! (obj instanceof Date))
+      throw new IllegalArgumentException ("Cannot format given Object as a Date");
     return format ((Date) obj, buf, pos);
   }
 
index 84bc49be298873f0fe7e860d380b14dddc56069d..804234f78a25c13b1aab81ccd889296c6d075417 100644 (file)
@@ -39,14 +39,14 @@ exception statement from your version. */
 
 package java.text;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
-import java.util.Enumeration;
 import java.util.GregorianCalendar;
+import java.util.Iterator;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.util.SimpleTimeZone;
-import java.util.Vector;
 import java.io.ObjectInputStream;
 import java.io.IOException;
 
@@ -71,7 +71,7 @@ public class SimpleDateFormat extends DateFormat
     }
   }
 
-  private transient Vector tokens;
+  private transient ArrayList tokens;
   private DateFormatSymbols formatData;  // formatData
   private Date defaultCenturyStart;
   private transient int defaultCentury;
@@ -98,7 +98,7 @@ public class SimpleDateFormat extends DateFormat
       set2DigitYearStart(defaultCenturyStart);
 
     // Set up items normally taken care of by the constructor.
-    tokens = new Vector();
+    tokens = new ArrayList();
     compileFormat(pattern);
   }
 
@@ -119,24 +119,24 @@ public class SimpleDateFormat extends DateFormat
        current = null;
        if (Character.isLetter(thisChar)) {
          // Not a valid letter
-         tokens.addElement(new FieldSizePair(-1,0));
+         tokens.add(new FieldSizePair(-1,0));
        } else if (thisChar == '\'') {
          // Quoted text section; skip to next single quote
          pos = pattern.indexOf('\'',i+1);
          if (pos == -1) {
            // This ought to be an exception, but spec does not
            // let us throw one.
-           tokens.addElement(new FieldSizePair(-1,0));
+           tokens.add(new FieldSizePair(-1,0));
          }
          if ((pos+1 < pattern.length()) && (pattern.charAt(pos+1) == '\'')) {
-           tokens.addElement(pattern.substring(i+1,pos+1));
+           tokens.add(pattern.substring(i+1,pos+1));
          } else {
-           tokens.addElement(pattern.substring(i+1,pos));
+           tokens.add(pattern.substring(i+1,pos));
          }
          i = pos;
        } else {
          // A special character
-         tokens.addElement(new Character(thisChar));
+         tokens.add(new Character(thisChar));
        }
       } else {
        // A valid field
@@ -144,22 +144,22 @@ public class SimpleDateFormat extends DateFormat
          current.size++;
        } else {
          current = new FieldSizePair(field,1);
-         tokens.addElement(current);
+         tokens.add(current);
        }
       }
     }
   }
-    
+
   public String toString() 
   {
     StringBuffer output = new StringBuffer();
-    Enumeration e = tokens.elements();
-    while (e.hasMoreElements()) {
-      output.append(e.nextElement().toString());
+    Iterator i = tokens.iterator();
+    while (i.hasNext()) {
+      output.append(i.next().toString());
     }
     return output.toString();
   }
-      
+
   /**
    * Constructs a SimpleDateFormat using the default pattern for
    * the default locale.
@@ -175,7 +175,7 @@ public class SimpleDateFormat extends DateFormat
     Locale locale = Locale.getDefault();
     calendar = new GregorianCalendar(locale);
     computeCenturyStart();
-    tokens = new Vector();
+    tokens = new ArrayList();
     formatData = new DateFormatSymbols(locale);
     pattern = (formatData.dateFormats[DEFAULT] + ' '
               + formatData.timeFormats[DEFAULT]);
@@ -203,7 +203,7 @@ public class SimpleDateFormat extends DateFormat
     super();
     calendar = new GregorianCalendar(locale);
     computeCenturyStart();
-    tokens = new Vector();
+    tokens = new ArrayList();
     formatData = new DateFormatSymbols(locale);
     compileFormat(pattern);
     this.pattern = pattern;
@@ -221,7 +221,7 @@ public class SimpleDateFormat extends DateFormat
     super();
     calendar = new GregorianCalendar();
     computeCenturyStart ();
-    tokens = new Vector();
+    tokens = new ArrayList();
     this.formatData = formatData;
     compileFormat(pattern);
     this.pattern = pattern;
@@ -264,7 +264,7 @@ public class SimpleDateFormat extends DateFormat
    */
   public void applyPattern(String pattern)
   {
-    tokens = new Vector();
+    tokens = new ArrayList();
     compileFormat(pattern);
     this.pattern = pattern;
   }
@@ -418,10 +418,10 @@ public class SimpleDateFormat extends DateFormat
     String temp;
     calendar.setTime(date);
     
-    // go through vector, filling in fields where applicable, else toString
-    Enumeration e = tokens.elements();
-    while (e.hasMoreElements()) {
-      Object o = e.nextElement();
+    // go through ArrayList, filling in fields where applicable, else toString
+    Iterator i = tokens.iterator();
+    while (i.hasNext()) {
+      Object o = i.next();
       if (o instanceof FieldSizePair) {
        FieldSizePair p = (FieldSizePair) o;
        int beginIndex = buffer.length();