- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 12 Aug 2011 09:02:52 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv22979
Modified Files:
Warning.java Warnings.java
Log Message:
small warning cleanup
Index: Warning.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Warning.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Warning.java 5 Jan 2010 13:50:00 -0000 1.11
+++ Warning.java 12 Aug 2011 09:02:50 -0000 1.12
@@ -11,9 +11,10 @@
/**
* This class is use to manage all warning every where
+ *
* @version $Revision$
*/
-public class Warning {
+public class Warning implements Comparable<Warning> {
String sourceFile;
int hashSource;
int line;
@@ -23,80 +24,76 @@
/**
* Create a new Warning with message parameters.
*
- * @param sourceFile the source file
- * @param line the line number in the source file
+ * @param sourceFile the source file
+ * @param line the line number in the source file
* @param warningMessage the warning message to find in the properties file
- * @param level the warning level
- * @param message1 the first message to add
- * @param message2 the second message to add
- *
+ * @param level the warning level
+ * @param messages the array of messages to add
* @see org.w3c.css.util.Messages
*/
- public Warning(String sourceFile, int line, String warningMessage, int level,
- String[] messages, ApplContext ac) {
- 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);
+ public Warning(String sourceFile, int line, String warningMessage,
+ int level, String[] messages, ApplContext ac) {
+ 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);
}
/**
* Create a new Warning.
*
- * @param sourceFile the source file
- * @param line the line number in the source file
+ * @param sourceFile the source file
+ * @param line the line number in the source file
* @param warningMessage the warning message to find in the properties file
- * @param level the warning level
- *
+ * @param level the warning level
* @see org.w3c.css.util.Messages
*/
public Warning(String sourceFile, int line,
- String warningMessage, int level, ApplContext ac) {
- this(sourceFile, line, warningMessage, level, new String[] {}, ac);
+ String warningMessage, int level, ApplContext ac) {
+ this(sourceFile, line, warningMessage, level, new String[]{}, ac);
}
/**
* Create a new Warning with a property and insert two messages inside.
*
- * @param property The property where the warning came
+ * @param property The property where the warning came
* @param warningMessage The warning message to find in the properties file
- * @param level the warning level
- * @param message1 the first message to add
- * @param message2 the second message to add
- *
+ * @param level the warning level
+ * @param message1 the first message to add
+ * @param message2 the second message to add
* @see org.w3c.css.util.Messages
*/
public Warning(CssProperty property, String warningMessage, int level,
- String message1, String message2, ApplContext ac, int i) {
- this.sourceFile = property.getSourceFile();
- if (sourceFile != null) {
- this.hashSource = sourceFile.hashCode() % 100;
- }
- this.warningMessage = warm(warningMessage, new String[] { message1, message2 }, ac);
- this.line = getLevel(warningMessage, level, ac)
- + (property.getLine() * 10);
+ String message1, String message2, ApplContext ac, int i) {
+ this.sourceFile = property.getSourceFile();
+ if (sourceFile != null) {
+ this.hashSource = sourceFile.hashCode() % 100;
+ }
+ this.warningMessage = warm(warningMessage, new String[]{message1,
+ message2}, ac);
+ this.line = getLevel(warningMessage, level, ac)
+ + (property.getLine() * 10);
}
/**
* Create a new Warning with a property and insert n message(s) inside.
*
- * @param property The property where the warning came
+ * @param property The property where the warning came
* @param warningMessage The warning message to find in the properties file
- * @param level the warning level
- * @param messages the list of messages to add
- *
+ * @param level the warning level
+ * @param messages the list of messages to add
* @see org.w3c.css.util.Messages
*/
public Warning(CssProperty property, String warningMessage, int level,
- String[] messages, ApplContext ac) {
- this.sourceFile = property.getSourceFile();
- if (sourceFile != null) {
- this.hashSource = sourceFile.hashCode() % 100;
- }
- this.warningMessage = warm(warningMessage, messages, ac);
- this.line = getLevel(warningMessage, level, ac)
- + (property.getLine() * 10);
+ String[] messages, ApplContext ac) {
+ this.sourceFile = property.getSourceFile();
+ if (sourceFile != null) {
+ this.hashSource = sourceFile.hashCode() % 100;
+ }
+ this.warningMessage = warm(warningMessage, messages, ac);
+ this.line = getLevel(warningMessage, level, ac)
+ + (property.getLine() * 10);
}
/**
@@ -104,131 +101,147 @@
* <P>Be careful ! Be sure that all informations in your property is
* available.
*
- * @param property The property where the warning came
+ * @param property The property where the warning came
* @param warningMessage The warning message to find in the properties file
- * @param level the warning level
- *
+ * @param level the warning level
* @see org.w3c.css.util.Messages
* @see org.w3c.css.properties.css.CssProperty#setInfo
*/
public Warning(CssProperty property, String warningMessage, int level,
- ApplContext ac) {
- this(property, warningMessage, level,
- new String[] { property.getPropertyName() }, ac);
- this.selector = property.getSelectors();
+ ApplContext ac) {
+ this(property, warningMessage, level,
+ new String[]{property.getPropertyName()}, ac);
+ this.selector = property.getSelectors();
}
/**
* Create a new Warning with a property and insert an other property name
* inside.
*
- * @param property The property where the warning came
+ * @param property The property where the warning came
* @param warningMessage The warning message to find in the properties file
- * @param level the warning level
- * @param property2 The property in conflicts with the first
- *
+ * @param level the warning level
+ * @param property2 The property in conflicts with the first
* @see org.w3c.css.util.Messages
*/
public Warning(CssProperty property, String warningMessage, int level,
- CssProperty property2, ApplContext ac) {
- this(property, warningMessage, level,
- new String[] { property.getPropertyName(), property2.getPropertyName() }, ac);
- this.selector = property.getSelectors();
+ CssProperty property2, ApplContext ac) {
+ this(property, warningMessage, level,
+ new String[]{property.getPropertyName(),
+ property2.getPropertyName()}, ac);
+ this.selector = property.getSelectors();
+ }
+
+ /**
+ * Compares this <tt>Warning</tt> instance with another.
+ *
+ * @param w the <tt>Warning</tt> instance to be compared
+ * @see Comparable
+ */
+ public int compareTo(Warning w) {
+ int wo = w.getInternalOrder();
+ int o = getInternalOrder();
+ if (wo == o) {
+ return 0;
+ }
+ if (o < wo) {
+ return -1;
+ }
+ return 1;
}
/**
* Get the source file
*/
public String getSourceFile() {
- return sourceFile;
+ return sourceFile;
}
/**
* Get the source file
*/
public String getSourceFileEscaped() {
- return Messages.escapeString(sourceFile);
+ return Messages.escapeString(sourceFile);
}
/**
* Get the line number.
*/
public int getLine() {
- return line / 10;
+ return line / 10;
}
/**
* Get the message.
*/
public String getWarningMessage() {
- return warningMessage;
+ return warningMessage;
}
/**
* Get the message.
*/
public String getWarningMessageEscaped() {
- return Messages.escapeString(warningMessage);
+ return Messages.escapeString(warningMessage);
}
/**
* Get the warning level.
*/
public int getLevel() {
- return line % 10;
+ return line % 10;
}
/**
* Get the context.
*/
public CssSelectors getContext() {
- return selector;
+ return selector;
}
public int getInternalOrder() {
- return (hashSource * 100000) + line;
+ return (hashSource * 100000) + line;
}
/**
* debug trace
*/
public void dump() {
- System.err.println( getSourceFile() );
- System.err.println( getLine() );
- System.err.println( getWarningMessage() );
- System.err.println( getLevel() );
+ System.err.println(getSourceFile());
+ System.err.println(getLine());
+ System.err.println(getWarningMessage());
+ System.err.println(getLevel());
}
private String warm(String warning, String[] args, ApplContext ac) {
- String str = ac.getMsg().getWarningString(warning);
- if (str == null) {
- return "can't find the warning message for " + warning;
- } else {
- // replace all parameters.
- int j = 0;
- for (int i = 0; (i = str.indexOf("%s", i)) >= 0 && j < args.length; ) {
- StringBuilder stb = new StringBuilder(str.substring(0, i));
- str = stb.append(args[j++]).append(str.substring(i+2)).toString();
- }
- return str;
- }
+ 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]);
+ }
+ return str;
+ }
}
private int getLevel(String warning, int defaultLevel, ApplContext ac) {
- String str = ac.getMsg().getWarningLevelString(warning);
- if (str == null)
- return defaultLevel;
- else {
- try {
- int level = Integer.parseInt(str);
- if (level > 9 || level < 0) {
- return defaultLevel;
- }
- return level;
- } catch (Exception e) {
- return defaultLevel;
- }
- }
+ String str = ac.getMsg().getWarningLevelString(warning);
+ if (str == null)
+ return defaultLevel;
+ else {
+ try {
+ int level = Integer.parseInt(str);
+ if (level > 9 || level < 0) {
+ return defaultLevel;
+ }
+ return level;
+ } catch (Exception e) {
+ return defaultLevel;
+ }
+ }
}
}
Index: Warnings.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Warnings.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Warnings.java 13 Jul 2007 13:32:21 -0000 1.6
+++ Warnings.java 12 Aug 2011 09:02:50 -0000 1.7
@@ -6,6 +6,8 @@
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.util;
+import java.util.Arrays;
+
/**
* Controls all warnings in the validator
*
@@ -13,145 +15,104 @@
* @see java.util.Vector
*/
public final class Warnings {
+ private Warning[] warningData = new Warning[20];
+ private int warningCount = 0;
+ private int ignoredWarningCount = 0;
+ private int warningLevel = 0;
- private Warning[] warningData = new Warning[20];
-
- private int warningCount = 0;
-
- private int ignoredWarningCount = 0;
-
- private int warningLevel = 0;
-
- public Warnings() {
-
- }
-
- public Warnings(int level) {
- this.warningLevel = level;
- }
-
- public int getWarningLevel() {
- return warningLevel;
- }
-
- public void setWarningLevel(int warningLevel) {
- this.warningLevel = warningLevel;
- }
+ public Warnings() {
+ }
-/**
- * Add a warning.
- *
- * @param warm the warning
- */
- public final void addWarning(Warning warm) {
- if(warm.getLevel() > warningLevel) {
- ignoredWarningCount++;
- }
- else {
- resize(1);
- warningData[warningCount++] = warm;
- }
- }
+ public Warnings(int level) {
+ this.warningLevel = level;
+ }
- /**
- * Add warnings.
- *
- * @param warnings All warnings
- */
- public final void addWarnings(Warnings warnings) {
- //resize(warnings.warningCount);
- for(int i=0; i < warnings.warningCount; i++) {
- addWarning(warnings.warningData[i]);
+ public int getWarningLevel() {
+ return warningLevel;
}
- }
- /**
- * Get the number of warnings
- */
- public final int getWarningCount() {
- return warningCount;
- }
+ public void setWarningLevel(int warningLevel) {
+ this.warningLevel = warningLevel;
+ }
- /**
- * Get the number of ignored warnings (not corresponding to the warning level)
- */
- public final int getIgnoredWarningCount() {
- return ignoredWarningCount;
- }
-
- /**
- * 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);
+ /**
+ * Add a warning.
+ *
+ * @param warm the warning
+ */
+ public final void addWarning(Warning warm) {
+ if (warm.getLevel() > warningLevel) {
+ ignoredWarningCount++;
+ } else {
+ resize(1);
+ warningData[warningCount++] = warm;
+ }
}
- return warningData;
- }
- /**
- * Sort all warnings by line and level
- */
- public final void sort() {
- quickSort(0, warningCount-1);
- }
+ /**
+ * Add warnings.
+ *
+ * @param warnings All warnings
+ */
+ public final void addWarnings(Warnings warnings) {
+ //resize(warnings.warningCount);
+ for (int i = 0; i < warnings.warningCount; i++) {
+ addWarning(warnings.warningData[i]);
+ }
+ }
- private int partition(int part_low_ind, int part_high_ind) {
- int lastsmall;
- long median_val;
- int comp1;
- Warning transit;
+ /**
+ * Get the number of warnings
+ */
+ public final int getWarningCount() {
+ return warningCount;
+ }
- // swap median value an first value of array
- comp1 = ( part_low_ind + part_high_ind ) / 2;
+ /**
+ * Get the number of ignored warnings
+ * (not corresponding to the warning level)
+ */
+ public final int getIgnoredWarningCount() {
+ return ignoredWarningCount;
+ }
- transit = warningData[part_low_ind];
- warningData[part_low_ind] = warningData[comp1];
- warningData[comp1] = transit;
- median_val = warningData[part_low_ind].getInternalOrder();
- lastsmall = part_low_ind;
- for (int i = part_low_ind + 1; i<=part_high_ind; i++) {
- if (warningData[i].getInternalOrder() < median_val) {
- lastsmall++;
- // swap lastsmall and i
- transit=warningData[lastsmall];
- warningData[lastsmall]=warningData[i];
- warningData[i]=transit;
+ /**
+ * 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;
}
- // swap part_low_ind and lastsmall
- transit=warningData[part_low_ind];
- warningData[part_low_ind]=warningData[lastsmall];
- warningData[lastsmall]=transit;
- return lastsmall;
- }
-
- private void quickSort(int qk_low_ind, int qk_high_ind) {
- if (qk_low_ind < qk_high_ind) {
- int median = partition(qk_low_ind, qk_high_ind);
- quickSort(qk_low_ind, median);
- quickSort(median+1, qk_high_ind);
+ /**
+ * Sort all warnings by line and level
+ */
+ public final void sort() {
+ if (warningCount > 0) {
+ Arrays.sort(warningData, 0, warningCount);
+ }
}
- }
- /**
- * Get a warning with an index.
- * @param index the warning index.
- */
- public final Warning getWarningAt(int index) {
- return warningData[index];
- }
+ /**
+ * Get a warning with an index.
+ *
+ * @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);
+ 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);
+ }
}
- }
}
Received on Friday, 12 August 2011 09:02:53 UTC