tmf: Replace "find" with "matches" for TextTrace.java
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 25 Feb 2014 22:07:38 +0000 (17:07 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 27 Feb 2014 16:01:43 +0000 (11:01 -0500)
This means that if a pattern is not 100% correct, it will
fail to read an event. However, performance should increase.

If we have for example a pattern (\\d\\d)\s(\S+)
and "123 blabla" will work with find(), returning "23 blabla"
but will fail with matches().

Change-Id: I54e259f31b44fa2996316150665e5ca011576825
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/22539
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/text/TextTrace.java

index d03bddc3c684d388cfeee676b48c34fbf7e05416..2cf0666b870ad603cac5205bed84f53bae2a3554 100644 (file)
@@ -86,7 +86,7 @@ public abstract class TextTrace<T extends TmfEvent> extends TmfTrace implements
             String line = rafile.getNextLine();
             while ((line != null) && (lineCount++ < MAX_LINES)) {
                 Matcher matcher = getFirstLinePattern().matcher(line);
-                if (matcher.find()) {
+                if (matcher.matches()) {
                     matches++;
                 }
                 confidence = MAX_CONFIDENCE * matches / lineCount;
@@ -140,11 +140,8 @@ public abstract class TextTrace<T extends TmfEvent> extends TmfTrace implements
             String line = fFile.getNextLine();
             while (line != null) {
                 Matcher matcher = getFirstLinePattern().matcher(line);
-                if (matcher.find()) {
-                    context.setLocation(new TmfLongLocation(rawPos));
-                    context.firstLineMatcher = matcher;
-                    context.firstLine = line;
-                    context.nextLineLocation = fFile.getFilePointer();
+                if (matcher.matches()) {
+                    setupContext(context, rawPos, line, matcher);
                     return context;
                 }
                 rawPos = fFile.getFilePointer();
@@ -157,6 +154,13 @@ public abstract class TextTrace<T extends TmfEvent> extends TmfTrace implements
         }
     }
 
+    private void setupContext(TextTraceContext context, long rawPos, String line, Matcher matcher) throws IOException {
+        context.setLocation(new TmfLongLocation(rawPos));
+        context.firstLineMatcher = matcher;
+        context.firstLine = line;
+        context.nextLineLocation = fFile.getFilePointer();
+    }
+
     @Override
     public synchronized TmfContext seekEvent(double ratio) {
         if (fFile == null) {
@@ -251,11 +255,8 @@ public abstract class TextTrace<T extends TmfEvent> extends TmfTrace implements
             String line = fFile.getNextLine();
             while (line != null) {
                 Matcher matcher = getFirstLinePattern().matcher(line);
-                if (matcher.find()) {
-                    context.setLocation(new TmfLongLocation(rawPos));
-                    context.firstLineMatcher = matcher;
-                    context.firstLine = line;
-                    context.nextLineLocation = fFile.getFilePointer();
+                if (matcher.matches()) {
+                    setupContext(context, rawPos, line, matcher);
                     return event;
                 }
                 parseNextLine(event, line);
This page took 0.026105 seconds and 5 git commands to generate.