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

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