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

2002/css-validator/org/w3c/css/util Warning.java,1.12,1.13 Warnings.java,1.7,1.8

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Fri, 12 Aug 2011 13:04:27 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1QrrPX-0006TO-Hf@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv24857

Modified Files:
	Warning.java Warnings.java 
Log Message:
more warnings cleanup

Index: Warning.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Warning.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- Warning.java	12 Aug 2011 09:02:50 -0000	1.12
+++ Warning.java	12 Aug 2011 13:04:25 -0000	1.13
@@ -16,8 +16,9 @@
  */
 public class Warning implements Comparable<Warning> {
     String sourceFile;
-    int hashSource;
-    int line;
+    int hashSource = 0;
+    int level = 0;
+    int line = 0;
     CssSelectors selector;
     String warningMessage;
 
@@ -36,8 +37,8 @@
         this.sourceFile = sourceFile;
         this.hashSource = sourceFile.hashCode() % 100;
         this.line = line;
-        this.warningMessage = warm(warningMessage, messages, ac);
-        this.line = getLevel(warningMessage, level, ac) + (line * 10);
+        this.warningMessage = warn(warningMessage, messages, ac);
+        this.level = getLevel(warningMessage, level, ac);
     }
 
     /**
@@ -51,7 +52,7 @@
      */
     public Warning(String sourceFile, int line,
                    String warningMessage, int level, ApplContext ac) {
-        this(sourceFile, line, warningMessage, level, new String[]{}, ac);
+        this(sourceFile, line, warningMessage, level, null, ac);
     }
 
     /**
@@ -70,10 +71,10 @@
         if (sourceFile != null) {
             this.hashSource = sourceFile.hashCode() % 100;
         }
-        this.warningMessage = warm(warningMessage, new String[]{message1,
+        this.warningMessage = warn(warningMessage, new String[]{message1,
                 message2}, ac);
-        this.line = getLevel(warningMessage, level, ac)
-                + (property.getLine() * 10);
+        this.level = getLevel(warningMessage, level, ac);
+        this.line = property.getLine();
     }
 
     /**
@@ -91,9 +92,9 @@
         if (sourceFile != null) {
             this.hashSource = sourceFile.hashCode() % 100;
         }
-        this.warningMessage = warm(warningMessage, messages, ac);
-        this.line = getLevel(warningMessage, level, ac)
-                + (property.getLine() * 10);
+        this.warningMessage = warn(warningMessage, messages, ac);
+        this.level = getLevel(warningMessage, level, ac);
+        this.line = property.getLine();
     }
 
     /**
@@ -168,7 +169,7 @@
      * Get the line number.
      */
     public int getLine() {
-        return line / 10;
+        return line;
     }
 
     /**
@@ -189,7 +190,7 @@
      * Get the warning level.
      */
     public int getLevel() {
-        return line % 10;
+        return level;
     }
 
     /**
@@ -200,7 +201,7 @@
     }
 
     public int getInternalOrder() {
-        return (hashSource * 100000) + line;
+        return (100000 * hashSource + 10 * line + level);
     }
 
     /**
@@ -213,15 +214,17 @@
         System.err.println(getLevel());
     }
 
-    private String warm(String warning, String[] args, ApplContext ac) {
+    private String warn(String warning, String[] args, ApplContext ac) {
         String str = ac.getMsg().getWarningString(warning);
         int j;
         if (str == null) {
             return "can't find the warning message for " + warning;
         } else {
             // replace all parameters.
-            for (j = 0; j < args.length; j++) {
-                str = str.replaceFirst("%s", args[j]);
+            if (args != null) {
+                for (j = 0; j < args.length; j++) {
+                    str = str.replaceFirst("%s", args[j]);
+                }
             }
             return str;
         }

Index: Warnings.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Warnings.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Warnings.java	12 Aug 2011 09:02:50 -0000	1.7
+++ Warnings.java	12 Aug 2011 13:04:25 -0000	1.8
@@ -6,7 +6,8 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.util;
 
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
 
 /**
  * Controls all warnings in the validator
@@ -15,8 +16,7 @@
  * @see java.util.Vector
  */
 public final class Warnings {
-    private Warning[] warningData = new Warning[20];
-    private int warningCount = 0;
+    private ArrayList<Warning> warningData = new ArrayList<Warning>(16);
     private int ignoredWarningCount = 0;
     private int warningLevel = 0;
 
@@ -38,14 +38,13 @@
     /**
      * Add a warning.
      *
-     * @param warm the warning
+     * @param warn the warning
      */
-    public final void addWarning(Warning warm) {
-        if (warm.getLevel() > warningLevel) {
+    public final void addWarning(Warning warn) {
+        if (warn.getLevel() > warningLevel) {
             ignoredWarningCount++;
         } else {
-            resize(1);
-            warningData[warningCount++] = warm;
+            warningData.add(warn);
         }
     }
 
@@ -56,21 +55,21 @@
      */
     public final void addWarnings(Warnings warnings) {
         //resize(warnings.warningCount);
-        for (int i = 0; i < warnings.warningCount; i++) {
-            addWarning(warnings.warningData[i]);
-        }
+        warningData.addAll(warnings.warningData);
     }
 
     /**
      * Get the number of warnings
+     * @return the number of warnings
      */
     public final int getWarningCount() {
-        return warningCount;
+        return warningData.size();
     }
 
     /**
      * Get the number of ignored warnings 
      * (not corresponding to the warning level)
+     * @return the number of ignored warnings
      */
     public final int getIgnoredWarningCount() {
         return ignoredWarningCount;
@@ -80,22 +79,16 @@
      * Get an array with all warnings.
      */
     public final Warning[] getWarnings() {
-        int oldCapacity = warningData.length;
-        if (warningCount < oldCapacity) {
-            Warning oldData[] = warningData;
-            warningData = new Warning[warningCount];
-            System.arraycopy(oldData, 0, warningData, 0, warningCount);
-        }
-        return warningData;
+        Warning out[] = new Warning[warningData.size()];
+        warningData.toArray(out);
+        return out;
     }
 
     /**
      * Sort all warnings by line and level
      */
     public final void sort() {
-        if (warningCount > 0) {
-            Arrays.sort(warningData, 0, warningCount);
-        }
+        Collections.sort(warningData);
     }
 
     /**
@@ -104,15 +97,6 @@
      * @param index the warning index.
      */
     public final Warning getWarningAt(int index) {
-        return warningData[index];
-    }
-
-    private final void resize(int increment) {
-        int oldCapacity = warningData.length;
-        if (warningCount + increment + 1 > oldCapacity) {
-            Warning oldData[] = warningData;
-            warningData = new Warning[oldCapacity + increment + 1];
-            System.arraycopy(oldData, 0, warningData, 0, warningCount);
-        }
+        return warningData.get(index);
     }
 }
Received on Friday, 12 August 2011 13:04:28 UTC

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