W3C home > Mailing lists > Public > www-validator-cvs@w3.org > August 2011

2002/css-validator/org/w3c/css/parser Errors.java,1.5,1.6

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Sun, 21 Aug 2011 13:52:05 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Qv8RZ-0005K1-Po@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/parser
In directory hutz:/tmp/cvs-serv20439/org/w3c/css/parser

Modified Files:
	Errors.java 
Log Message:
old code revamped a bit

Index: Errors.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/Errors.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Errors.java	14 Sep 2005 15:14:18 -0000	1.5
+++ Errors.java	21 Aug 2011 13:52:03 -0000	1.6
@@ -7,19 +7,15 @@
 
 package org.w3c.css.parser;
 
-import java.util.Vector;
+import java.util.ArrayList;
 
 /**
  * Controls all errors in the validator
  * @version $Revision$
- * @see Vector.java
  */
 public final class Errors {
 
-  private CssError[] errorData = new CssError[10];
-  private int      errorCount;
-
-  private final static int capacityIncrement = 10;
+  private ArrayList<CssError> errorData = new ArrayList<CssError>();
 
   /**
    * Add an error.
@@ -27,13 +23,7 @@
    * @param error The new error.
    */
   public final void addError(CssError error) {
-    int oldCapacity = errorData.length;
-    if (errorCount + 1 > oldCapacity) {
-      CssError oldData[] = errorData;
-      errorData = new CssError[oldCapacity + capacityIncrement];
-      System.arraycopy(oldData, 0, errorData, 0, errorCount);
-    }
-    errorData[errorCount++] = error;
+      errorData.add(error);
   }
 
   /**
@@ -42,36 +32,23 @@
    * @param errors All errors
    */
   public final void addErrors(Errors errors) {
-    int oldCapacity = errorData.length;
-    if (errorCount + errors.errorCount + 1 > oldCapacity) {
-      CssError oldData[] = errorData;
-      errorData =
-	new CssError[oldCapacity + errors.errorCount + capacityIncrement];
-      System.arraycopy(oldData, 0, errorData, 0, errorCount);
-    }
-    System.arraycopy(errors.errorData, 0, errorData,
-		     errorCount, errors.errorCount);
-    errorCount += errors.errorCount;
+      errorData.addAll(errors.errorData);
   }
 
   /**
    * Get the number of errors.
    */
   public final int getErrorCount() {
-    return errorCount;
+      return errorData.size();
   }
 
   /**
    * Get an array with all errors.
    */
   public final CssError[] getErrors() {
-    int oldCapacity = errorData.length;
-    if (errorCount < oldCapacity) {
-      CssError oldData[] = errorData;
-      errorData = new CssError[errorCount];
-      System.arraycopy(oldData, 0, errorData, 0, errorCount);
-    }
-    return errorData;
+      CssError out[] = new CssError[errorData.size()];
+      errorData.toArray(out);
+      return out;
   }
 
   /**
@@ -80,7 +57,7 @@
    * @param index the error index.
    */
   public final CssError getErrorAt(int index) {
-    return errorData[index];
+      return errorData.get(index);
   }
 
 }
Received on Sunday, 21 August 2011 13:52:06 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:46 UTC