\r
/**\r
* The generic TMF Events table events cache\r
- * \r
+ *\r
+ * This can help avoid re-reading the trace when the user scrolls a window,\r
+ * for example.\r
+ *\r
* @version 1.0\r
* @author Patrick Tasse\r
*/\r
\r
/**\r
* The generic TMF Events table cached event\r
- * \r
+ *\r
* @version 1.0\r
* @author Patrick Tasse\r
*/\r
ITmfEvent event;\r
long rank;\r
\r
+ /**\r
+ * Constructor for new cached events.\r
+ *\r
+ * @param iTmfEvent\r
+ * The original trace event\r
+ * @param rank\r
+ * The rank of this event in the trace\r
+ */\r
public CachedEvent (ITmfEvent iTmfEvent, long rank) {\r
this.event = iTmfEvent;\r
this.rank = rank;\r
private ITmfFilter fFilter;\r
private final List<Integer> fFilterIndex = new ArrayList<Integer>(); // contains the event rank at each 'cache size' filtered events\r
\r
+ /**\r
+ * Constructor for the event cache\r
+ *\r
+ * @param cacheSize\r
+ * The size of the cache, in number of events\r
+ * @param table\r
+ * The Events table this cache will cover\r
+ */\r
public TmfEventsCache(int cacheSize, TmfEventsTable table) {\r
fCache = new CachedEvent[cacheSize];\r
fTable = table;\r
}\r
\r
+ /**\r
+ * Assign a new trace to this events cache. This clears the current\r
+ * contents.\r
+ *\r
+ * @param trace\r
+ * The trace to assign.\r
+ */\r
public void setTrace(ITmfTrace<?> trace) {\r
fTrace = trace;\r
clear();\r
}\r
\r
+ /**\r
+ * Clear the current contents of this cache.\r
+ */\r
public synchronized void clear() {\r
fCacheStartIndex = 0;\r
fCacheEndIndex = 0;\r
fFilterIndex.clear();\r
}\r
\r
+ /**\r
+ * Apply a filter on this event cache. This clears the current cache\r
+ * contents.\r
+ *\r
+ * @param filter\r
+ * The ITmfFilter to apply.\r
+ */\r
public void applyFilter(ITmfFilter filter) {\r
fFilter = filter;\r
clear();\r
}\r
\r
+ /**\r
+ * Clear the current filter on this cache. This also clears the current\r
+ * cache contents.\r
+ */\r
public void clearFilter() {\r
fFilter = null;\r
clear();\r
}\r
\r
+ /**\r
+ * Get an event from the cache. This will remove the event from the cache.\r
+ *\r
+ * FIXME this does not currently remove the event!\r
+ *\r
+ * @param index\r
+ * The index of this event in the cache\r
+ * @return The cached event, or 'null' if there is no event at that index\r
+ */\r
public synchronized CachedEvent getEvent(int index) {\r
if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) {\r
int i = index - fCacheStartIndex;\r
return null;\r
}\r
\r
+ /**\r
+ * Read an event, but without removing it from the cache.\r
+ *\r
+ * @param index\r
+ * Index of the event to peek\r
+ * @return A reference to the event, or 'null' if there is no event at this\r
+ * index\r
+ */\r
public synchronized CachedEvent peekEvent(int index) {\r
if ((index >= fCacheStartIndex) && (index < fCacheEndIndex)) {\r
int i = index - fCacheStartIndex;\r
return null;\r
}\r
\r
+ /**\r
+ * Add a trace event to the cache.\r
+ *\r
+ * @param event\r
+ * The original trace event to be cached\r
+ * @param rank\r
+ * The rank of this event in the trace\r
+ * @param index\r
+ * The index this event will occupy in the cache\r
+ */\r
public synchronized void storeEvent(ITmfEvent event, long rank, int index) {\r
if (index == fCacheEndIndex) {\r
int i = index - fCacheStartIndex;\r
}\r
}\r
\r
+ /**\r
+ * Get the cache index of an event from his rank in the trace. This will\r
+ * take in consideration any filter that might be applied.\r
+ *\r
+ * @param rank\r
+ * The rank of the event in the trace\r
+ * @return The position (index) this event should use once cached\r
+ */\r
@SuppressWarnings("unchecked")\r
public int getFilteredEventIndex(final long rank) {\r
int current;\r
// Flag the UI thread that the cache is ready\r
if (monitor.isCanceled()) {\r
return Status.CANCEL_STATUS;\r
- } else {\r
- return Status.OK_STATUS;\r
}\r
+ return Status.OK_STATUS;\r
}\r
};\r
//job.setSystem(true);\r