sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/model/GenericSampledTrace.java
changeset 5 844b047e260d
parent 2 b9ab3b238396
child 12 ae255c9aa552
--- a/sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/model/GenericSampledTrace.java	Tue Apr 20 14:41:43 2010 +0300
+++ b/sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/model/GenericSampledTrace.java	Wed Apr 21 15:14:16 2010 +0300
@@ -22,21 +22,44 @@
 
 public abstract class GenericSampledTrace extends GenericTrace
 {
-	private static final long serialVersionUID = -5030416972125713453L;
+	private static final long serialVersionUID = 5248402326692863890L;
+	private long lastSampleTime;
 	
-	public Vector samples;
+	public Vector<GenericSample> samples;
 	
 	public GenericSampledTrace()
 	{
-	  this.samples = new Vector();
+	  this.samples = new Vector<GenericSample>();
 	}
 	
 	public void addSample(GenericSample sample)
 	{
 	  this.samples.add(sample);
+	  if (sample.sampleSynchTime > lastSampleTime){
+		  lastSampleTime = sample.sampleSynchTime;
+	  }
 	}
 	
-	public Enumeration getSamples()
+	/**
+	 * Returns the highest sampleSyncTime found in the set of samples.
+	 * 
+	 * @return last sample time
+	 */
+	public long getLastSampleTime(){
+		if (lastSampleTime == 0 && samples.size()>0){
+			//someone has added samples without going through the addSample() API in this class
+			//really, this.samples should be private
+			//let's try to recalculate lastSampleTime
+			for (GenericSample s : samples) {
+				  if (s.sampleSynchTime > lastSampleTime){
+					  lastSampleTime = s.sampleSynchTime;
+				  }
+			}
+		}
+		return lastSampleTime;
+	}
+	
+	public Enumeration<GenericSample> getSamples()
 	{
 	  return samples.elements();
 	}
@@ -48,7 +71,7 @@
 	
 	public Vector<GenericSample> getSamplesInsideTimePeriod(long start, long end)
 	{
-		Enumeration sEnum = samples.elements();
+		Enumeration<GenericSample> sEnum = samples.elements();
 		Vector<GenericSample> okSamples = new Vector<GenericSample>();
 		
 		while(sEnum.hasMoreElements())
@@ -195,18 +218,20 @@
 			return 0;
 	}
 	
+	/**
+	 * Returns the highest sample time in the trace. Note, on SMP systems,
+	 * this may not be the time of the last sample.
+	 * @return
+	 */
 	public int getLastSampleNumber()
 	{
-		if (this.samples.size() > 0)
-			return (int)((GenericSample)this.samples.lastElement()).sampleSynchTime;
-		else
-			return 0;
+		return (int)getLastSampleTime();
 	}
 	
 	public String toString()
 	{
-		Enumeration sEnum = this.getSamples();
-	  	Vector strings = new Vector();
+		Enumeration<GenericSample> sEnum = this.getSamples();
+	  	Vector<String> strings = new Vector<String>();
 	  	int totalLength = 0;
 	  	while(sEnum.hasMoreElements())
 	  	{	
@@ -218,11 +243,11 @@
 	  	
 	  	System.out.println(Messages.getString("GenericSampledTrace.totalLength") + totalLength); //$NON-NLS-1$
 	  	byte[] bytes = new byte[totalLength];
-	  	sEnum = strings.elements();
+	  	Enumeration<String> sEnumString = strings.elements();
 	  	int index = 0;
-	  	while(sEnum.hasMoreElements())
+	  	while(sEnumString.hasMoreElements())
 	  	{
-	  		String s = (String)sEnum.nextElement();
+	  		String s = (String)sEnumString.nextElement();
 	  		byte[] sB = s.getBytes();
 	  		for (int i = index; i < index + sB.length; i++)
 	  		{