Remove the generic location (replace by Comparable)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / parsers / custom / CustomTxtTrace.java
index 08f8d69458f41095e23cae3fead96dfa09934d06..c12031e5afc8033edc481497be587827658516d9 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************\r
  * Copyright (c) 2010 Ericsson\r
- * \r
+ *\r
  * All rights reserved. This program and the accompanying materials are\r
  * made available under the terms of the Eclipse Public License v1.0 which\r
  * accompanies this distribution, and is available at\r
  * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
+ *\r
  * Contributors:\r
  *   Patrick Tasse - Initial API and implementation\r
  *******************************************************************************/\r
@@ -24,6 +24,7 @@ import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;\r
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;\r
 import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;\r
@@ -31,12 +32,12 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;\r
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;\r
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;\r
+import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;\r
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;\r
 \r
-public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEventParser<CustomTxtEvent> {\r
+public class CustomTxtTrace extends TmfTrace implements ITmfEventParser {\r
 \r
-    private static final TmfLocation<Long> NULL_LOCATION = new TmfLocation<Long>((Long) null);\r
+    private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation((Long) null);\r
     private static final int DEFAULT_CACHE_SIZE = 100;\r
 \r
     private final CustomTxtTraceDefinition fDefinition;\r
@@ -46,17 +47,17 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
     public CustomTxtTrace(final CustomTxtTraceDefinition definition) {\r
         fDefinition = definition;\r
         fEventType = new CustomTxtEventType(fDefinition);\r
+        setCacheSize(DEFAULT_CACHE_SIZE);\r
     }\r
 \r
-    public CustomTxtTrace(final IResource resource, final CustomTxtTraceDefinition definition, final String path, final int pageSize) throws TmfTraceException {\r
-        super(resource, CustomTxtEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE);\r
-        fDefinition = definition;\r
-        fEventType = new CustomTxtEventType(fDefinition);\r
-        indexTrace(false);\r
+    public CustomTxtTrace(final IResource resource, final CustomTxtTraceDefinition definition, final String path, final int cacheSize) throws TmfTraceException {\r
+        this(definition);\r
+        setCacheSize((cacheSize > 0) ? cacheSize : DEFAULT_CACHE_SIZE);\r
+        initTrace(resource, path, CustomTxtEvent.class);\r
     }\r
 \r
     @Override\r
-    public void initTrace(final IResource resource, final String path, final Class<CustomTxtEvent> eventType) throws TmfTraceException {\r
+    public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType) throws TmfTraceException {\r
         super.initTrace(resource, path, eventType);\r
         try {\r
             fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
@@ -80,7 +81,7 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
     }\r
 \r
     @Override\r
-    public synchronized TmfContext seekEvent(final ITmfLocation<?> location) {\r
+    public synchronized TmfContext seekEvent(final ITmfLocation location) {\r
         final CustomTxtTraceContext context = new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
         if (NULL_LOCATION.equals(location) || fFile == null) {\r
             return context;\r
@@ -88,8 +89,8 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
         try {\r
             if (location == null) {\r
                 fFile.seek(0);\r
-            } else if (location.getLocation() instanceof Long) {\r
-                fFile.seek((Long) location.getLocation());\r
+            } else if (location.getLocationData() instanceof Long) {\r
+                fFile.seek((Long) location.getLocationData());\r
             }\r
             String line;\r
             long rawPos = fFile.getFilePointer();\r
@@ -97,7 +98,7 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
                 for (final InputLine input : getFirstLines()) {\r
                     final Matcher matcher = input.getPattern().matcher(line);\r
                     if (matcher.find()) {\r
-                        context.setLocation(new TmfLocation<Long>(rawPos));\r
+                        context.setLocation(new TmfLongLocation(rawPos));\r
                         context.firstLineMatcher = matcher;\r
                         context.firstLine = line;\r
                         context.nextLineLocation = fFile.getFilePointer();\r
@@ -132,7 +133,7 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
                 }\r
                 pos--;\r
             }\r
-            final ITmfLocation<?> location = new TmfLocation<Long>(pos);\r
+            final ITmfLocation location = new TmfLongLocation(pos);\r
             final TmfContext context = seekEvent(location);\r
             context.setRank(ITmfContext.UNKNOWN_RANK);\r
             return context;\r
@@ -143,13 +144,13 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
     }\r
 \r
     @Override\r
-    public synchronized double getLocationRatio(final ITmfLocation<?> location) {\r
+    public synchronized double getLocationRatio(final ITmfLocation location) {\r
         if (fFile == null) {\r
             return 0;\r
         }\r
         try {\r
-            if (location.getLocation() instanceof Long) {\r
-                return (double) ((Long) location.getLocation()) / fFile.length();\r
+            if (location.getLocationData() instanceof Long) {\r
+                return (double) ((Long) location.getLocationData()) / fFile.length();\r
             }\r
         } catch (final IOException e) {\r
             Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$\r
@@ -158,7 +159,7 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
     }\r
 \r
     @Override\r
-    public ITmfLocation<?> getCurrentLocation() {\r
+    public ITmfLocation getCurrentLocation() {\r
         // TODO Auto-generated method stub\r
         return null;\r
     }\r
@@ -189,7 +190,7 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
         }\r
 \r
         final CustomTxtTraceContext context = (CustomTxtTraceContext) tmfContext;\r
-        if (!(context.getLocation().getLocation() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {\r
+        if (!(context.getLocation().getLocationData() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {\r
             return null;\r
         }\r
 \r
@@ -214,7 +215,7 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
                     for (final InputLine input : getFirstLines()) {\r
                         final Matcher matcher = input.getPattern().matcher(line);\r
                         if (matcher.find()) {\r
-                            context.setLocation(new TmfLocation<Long>(rawPos));\r
+                            context.setLocation(new TmfLongLocation(rawPos));\r
                             context.firstLineMatcher = matcher;\r
                             context.firstLine = line;\r
                             context.nextLineLocation = fFile.getFilePointer();\r
@@ -229,7 +230,7 @@ public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> implements ITmfEven
                             for (final InputLine input : getFirstLines()) {\r
                                 final Matcher matcher = input.getPattern().matcher(line);\r
                                 if (matcher.find()) {\r
-                                    context.setLocation(new TmfLocation<Long>(rawPos));\r
+                                    context.setLocation(new TmfLongLocation(rawPos));\r
                                     context.firstLineMatcher = matcher;\r
                                     context.firstLine = line;\r
                                     context.nextLineLocation = fFile.getFilePointer();\r
This page took 0.026765 seconds and 5 git commands to generate.