import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* {@inheritDoc}
* <p>
- * The default implementation computes the confidence as the percentage of
- * lines in the first 100 lines of the file which match the first line
- * pattern.
+ * The default implementation computes the confidence as the sum of weighted
+ * values of the first 100 lines of the file which match any of the provided
+ * validation patterns. For each matching line a weighted value between 1.5
+ * and 2.0 is assigned based on the group count of the matching patterns.
+ * The higher the group count, the closer the weighted value will be to 2.0.
*/
@Override
public IStatus validate(IProject project, String path) {
int lineCount = 0;
double matches = 0.0;
String line = rafile.getNextLine();
+ List<Pattern> validationPatterns = getValidationPatterns();
while ((line != null) && (lineCount++ < MAX_LINES)) {
- Matcher matcher = getFirstLinePattern().matcher(line);
- if (matcher.matches()) {
- int groupCount = matcher.groupCount();
- matches += (1.0 + groupCount / ((double) groupCount + 1));
+ for(Pattern pattern : validationPatterns) {
+ Matcher matcher = pattern.matcher(line);
+ if (matcher.matches()) {
+ int groupCount = matcher.groupCount();
+ matches += (1.0 + groupCount / ((double) groupCount + 1));
+ }
}
confidence = (int) (MAX_CONFIDENCE * matches / lineCount);
line = rafile.getNextLine();
protected abstract Pattern getFirstLinePattern();
/**
- * Parses the first line data and returns a new event.
+ * Parses the first line data and returns a new event. When constructing the
+ * event, the concrete trace should use the trace's timestamp transform to
+ * create the timestamp, by either transforming the parsed time value
+ * directly or by using the method {@link #createTimestamp(long)}.
*
* @param matcher
* The matcher
*/
protected abstract void parseNextLine(T event, String line);
+ /**
+ * Returns a ordered list of validation patterns that will be used in
+ * the default {@link #validate(IProject, String)} method to match
+ * the first 100 to compute the confidence level
+ *
+ * @return collection of patterns to validate against
+ * @since 3.2
+ */
+ protected List<Pattern> getValidationPatterns() {
+ return Collections.singletonList(getFirstLinePattern());
+ }
+
// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------