Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Montplaisir2013-11-29 21:45:21 +0000
committerAlexandre Montplaisir2013-11-29 23:51:32 +0000
commit5fbc0fc468a717e202c4dcf1fbdaf72d4a92919d (patch)
tree89928b25cfdddaabbc5420f2d2a76a267fbf7c72
parent05d5bf173896a3c811b176d2041367ec5b3e7c40 (diff)
downloadorg.eclipse.linuxtools-5fbc0fc468a717e202c4dcf1fbdaf72d4a92919d.tar.gz
org.eclipse.linuxtools-5fbc0fc468a717e202c4dcf1fbdaf72d4a92919d.tar.xz
org.eclipse.linuxtools-5fbc0fc468a717e202c4dcf1fbdaf72d4a92919d.zip
tmf: Update Javadoc in CtfIterator
And removed the clone() method, it wasn't used and clone() is bad. Change-Id: Ib82eb78a50fe4ad1a0836cb98f99f4cc0da9606a Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-on: https://git.eclipse.org/r/19155 Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java9
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java260
2 files changed, 108 insertions, 161 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java
index c228d079f9..9e4e380b62 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java
@@ -115,15 +115,6 @@ public class CtfIteratorTest {
}
/**
- * Run the CtfIterator clone() method test.
- */
- @Test
- public void testClone() {
- CtfIterator result = iterator.clone();
- assertNotNull(result);
- }
-
- /**
* Run the int compareTo(CtfIterator) method test.
* @throws CTFReaderException error
*/
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
index d7529bcab2..641d155eda 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
@@ -6,8 +6,10 @@
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
*******************************************************************************/
+
package org.eclipse.linuxtools.tmf.core.ctfadaptor;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
@@ -23,104 +25,107 @@ import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
* It doesn't reserve a file handle, so many iterators can be used without
* worries of I/O errors or resource exhaustion.
*
- * @version 1.0
* @author Matthew Khouzam
*/
-public class CtfIterator extends CTFTraceReader implements ITmfContext,
- Comparable<CtfIterator> {
-
- private final CtfTmfTrace ctfTmfTrace;
+public class CtfIterator extends CTFTraceReader
+ implements ITmfContext, Comparable<CtfIterator> {
- /**
- * An invalid location
- */
+ /** An invalid location */
public static final CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
- private CtfLocation curLocation;
- private long curRank;
+ private final CtfTmfTrace fTrace;
+
+ private CtfLocation fCurLocation;
+ private long fCurRank;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
/**
* Create a new CTF trace iterator, which initially points at the first
* event in the trace.
*
* @param trace
- * the trace to iterate over
+ * The trace to iterate over
* @throws CTFReaderException
- * error
+ * If the iterator couldn't not be instantiated, probably due to
+ * a read error.
*/
- public CtfIterator(final CtfTmfTrace trace) throws CTFReaderException {
+ public CtfIterator(CtfTmfTrace trace) throws CTFReaderException {
super(trace.getCTFTrace());
- this.ctfTmfTrace = trace;
+ fTrace = trace;
if (this.hasMoreEvents()) {
- this.curLocation = new CtfLocation(trace.getStartTime());
- this.curRank = 0;
+ fCurLocation = new CtfLocation(trace.getStartTime());
+ fCurRank = 0;
} else {
setUnknownLocation();
}
}
- private void setUnknownLocation() {
- this.curLocation = NULL_LOCATION;
- this.curRank = UNKNOWN_RANK;
- }
-
/**
- * Constructor for CtfIterator.
+ * Create a new CTF trace iterator, which will initially point to the given
+ * location/rank.
*
* @param trace
- * CtfTmfTrace the trace
+ * The trace to iterate over
* @param ctfLocationData
- * long the timestamp in ns of the trace for positioning
+ * The initial timestamp the iterator will be pointing to
* @param rank
- * long the index of the trace for positioning
+ * The initial rank
* @throws CTFReaderException
- * error
+ * If the iterator couldn't not be instantiated, probably due to
+ * a read error.
* @since 2.0
*/
- public CtfIterator(final CtfTmfTrace trace,
- final CtfLocationInfo ctfLocationData, final long rank) throws CTFReaderException {
+ public CtfIterator(CtfTmfTrace trace, CtfLocationInfo ctfLocationData, long rank)
+ throws CTFReaderException {
super(trace.getCTFTrace());
- this.ctfTmfTrace = trace;
+ this.fTrace = trace;
if (this.hasMoreEvents()) {
- this.curLocation = new CtfLocation(ctfLocationData);
+ this.fCurLocation = new CtfLocation(ctfLocationData);
if (this.getCurrentEvent().getTimestamp().getValue() != ctfLocationData.getTimestamp()) {
this.seek(ctfLocationData);
- this.curRank = rank;
+ this.fCurRank = rank;
}
} else {
setUnknownLocation();
}
}
+ private void setUnknownLocation() {
+ fCurLocation = NULL_LOCATION;
+ fCurRank = UNKNOWN_RANK;
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+
/**
- * Method getCtfTmfTrace. gets a CtfTmfTrace
+ * Return this iterator's trace.
*
- * @return CtfTmfTrace
+ * @return CtfTmfTrace The iterator's trace
*/
public CtfTmfTrace getCtfTmfTrace() {
- return ctfTmfTrace;
+ return fTrace;
}
/**
- * Method getCurrentEvent. gets the current event
+ * Return the current event pointed to by the iterator.
*
- * @return CtfTmfEvent
+ * @return CtfTmfEvent The current event
*/
public CtfTmfEvent getCurrentEvent() {
final StreamInputReader top = super.getPrio().peek();
if (top != null) {
return CtfTmfEventFactory.createEvent(top.getCurrentEvent(),
- top.getFilename(), ctfTmfTrace);
+ top.getFilename(), fTrace);
}
return null;
}
- @Override
- public boolean seek(long timestamp) {
- return seek(new CtfLocationInfo(timestamp, 0));
- }
-
/**
* Seek this iterator to a given location.
*
@@ -130,11 +135,11 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
* error seeking.
* @since 2.0
*/
- public synchronized boolean seek(final CtfLocationInfo ctfLocationData) {
+ public synchronized boolean seek(CtfLocationInfo ctfLocationData) {
boolean ret = false;
/* Avoid the cost of seeking at the current location. */
- if (curLocation.getLocationInfo().equals(ctfLocationData)) {
+ if (fCurLocation.getLocationInfo().equals(ctfLocationData)) {
return super.hasMoreEvents();
}
@@ -173,143 +178,90 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
}
/* Seek the current location accordingly */
if (ret) {
- curLocation = new CtfLocation(new CtfLocationInfo(getCurrentEvent().getTimestamp().getValue(), index));
+ fCurLocation = new CtfLocation(new CtfLocationInfo(getCurrentEvent().getTimestamp().getValue(), index));
} else {
- curLocation = NULL_LOCATION;
+ fCurLocation = NULL_LOCATION;
}
return ret;
}
- /**
- * Method getRank.
- *
- * @return long
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
- */
- @Override
- public long getRank() {
- return curRank;
- }
+ // ------------------------------------------------------------------------
+ // CTFTraceReader
+ // ------------------------------------------------------------------------
- /**
- * Method setRank.
- *
- * @param rank
- * long
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
- */
@Override
- public void setRank(final long rank) {
- curRank = rank;
+ public boolean seek(long timestamp) {
+ return seek(new CtfLocationInfo(timestamp, 0));
}
@Override
- public CtfIterator clone() {
- CtfIterator clone = null;
+ public synchronized boolean advance() {
+ long index = fCurLocation.getLocationInfo().getIndex();
+ long timestamp = fCurLocation.getLocationInfo().getTimestamp();
+ boolean ret = false;
try {
- clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocationInfo(), curRank);
+ ret = super.advance();
} catch (CTFReaderException e) {
Activator.logError(e.getMessage(), e);
}
- return clone;
- }
- /**
- * Method dispose.
- *
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
- */
- @Override
- public void dispose() {
- super.dispose();
+ if (ret) {
+ final long timestampValue = getCurrentEvent().getTimestamp().getValue();
+ if (timestamp == timestampValue) {
+ fCurLocation = new CtfLocation(timestampValue, index + 1);
+ } else {
+ fCurLocation = new CtfLocation(timestampValue, 0L);
+ }
+ } else {
+ fCurLocation = NULL_LOCATION;
+ }
+ return ret;
}
- /**
- * Method setLocation.
- *
- * @param location
- * ITmfLocation<?>
- * @since 3.0
- */
+ // ------------------------------------------------------------------------
+ // ITmfContext
+ // ------------------------------------------------------------------------
+
@Override
- public void setLocation(final ITmfLocation location) {
- // FIXME alex: isn't there a cleaner way than a cast here?
- this.curLocation = (CtfLocation) location;
- seek(((CtfLocation) location).getLocationInfo());
+ public long getRank() {
+ return fCurRank;
}
- /**
- * Method getLocation.
- *
- * @return CtfLocation
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
- */
@Override
- public CtfLocation getLocation() {
- return curLocation;
+ public void setRank(long rank) {
+ fCurRank = rank;
}
- /**
- * Method increaseRank.
- *
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
- */
@Override
public void increaseRank() {
/* Only increase the rank if it's valid */
if (hasValidRank()) {
- curRank++;
+ fCurRank++;
}
}
- /**
- * Method hasValidRank, if the iterator is valid
- *
- * @return boolean
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
- */
@Override
public boolean hasValidRank() {
return (getRank() >= 0);
}
- /**
- * Method advance go to the next event
- *
- * @return boolean successful or not
- */
@Override
- public synchronized boolean advance() {
- long index = curLocation.getLocationInfo().getIndex();
- long timestamp = curLocation.getLocationInfo().getTimestamp();
- boolean ret = false;
- try {
- ret = super.advance();
- } catch (CTFReaderException e) {
- Activator.logError(e.getMessage(), e);
- }
+ public void setLocation(ITmfLocation location) {
+ // FIXME alex: isn't there a cleaner way than a cast here?
+ fCurLocation = (CtfLocation) location;
+ seek(((CtfLocation) location).getLocationInfo());
+ }
- if (ret) {
- final long timestampValue = getCurrentEvent().getTimestamp().getValue();
- if (timestamp == timestampValue) {
- curLocation = new CtfLocation(timestampValue, index + 1);
- } else {
- curLocation = new CtfLocation(timestampValue, 0L);
- }
- } else {
- curLocation = NULL_LOCATION;
- }
- return ret;
+ @Override
+ public CtfLocation getLocation() {
+ return fCurLocation;
}
- /**
- * Method compareTo.
- *
- * @param o
- * CtfIterator
- * @return int -1, 0, 1
- */
+ // ------------------------------------------------------------------------
+ // Comparable
+ // ------------------------------------------------------------------------
+
@Override
public int compareTo(final CtfIterator o) {
if (this.getRank() < o.getRank()) {
@@ -320,15 +272,19 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
return 0;
}
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = (prime * result)
- + ((ctfTmfTrace == null) ? 0 : ctfTmfTrace.hashCode());
+ + ((fTrace == null) ? 0 : fTrace.hashCode());
result = (prime * result)
- + ((curLocation == null) ? 0 : curLocation.hashCode());
- result = (prime * result) + (int) (curRank ^ (curRank >>> 32));
+ + ((fCurLocation == null) ? 0 : fCurLocation.hashCode());
+ result = (prime * result) + (int) (fCurRank ^ (fCurRank >>> 32));
return result;
}
@@ -344,21 +300,21 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
return false;
}
CtfIterator other = (CtfIterator) obj;
- if (ctfTmfTrace == null) {
- if (other.ctfTmfTrace != null) {
+ if (fTrace == null) {
+ if (other.fTrace != null) {
return false;
}
- } else if (!ctfTmfTrace.equals(other.ctfTmfTrace)) {
+ } else if (!fTrace.equals(other.fTrace)) {
return false;
}
- if (curLocation == null) {
- if (other.curLocation != null) {
+ if (fCurLocation == null) {
+ if (other.fCurLocation != null) {
return false;
}
- } else if (!curLocation.equals(other.curLocation)) {
+ } else if (!fCurLocation.equals(other.fCurLocation)) {
return false;
}
- if (curRank != other.curRank) {
+ if (fCurRank != other.fCurRank) {
return false;
}
return true;

Back to the top