*
*/
public void testCopyBadTimestamp() {
- final ITmfTimestamp ts0a = new TmfTimestamp(0, 100, 0);
-
try {
new TmfSimpleTimestamp(null);
fail("TmfSimpleTimestamp: null argument");
- } catch (final IllegalArgumentException e) {
- }
-
- try {
- new TmfSimpleTimestamp(ts0a);
- fail("TmfSimpleTimestamp: bad scale");
- } catch (final ArithmeticException e) {
- }
- }
-
- // ------------------------------------------------------------------------
- // clone
- // ------------------------------------------------------------------------
-
- private static class MyTimestamp extends TmfSimpleTimestamp {
-
- @Override
- public boolean equals(final Object other) {
- return super.equals(other);
+ } catch (final NullPointerException e) {
}
-
- @Override
- public MyTimestamp clone() {
- return (MyTimestamp) super.clone();
- }
- }
-
- /**
- *
- */
- public void testClone() {
- final ITmfTimestamp clone = ts0.clone();
-
- assertTrue("clone", ts0.clone().equals(ts0));
- assertTrue("clone", clone.clone().equals(clone));
-
- assertEquals("clone", clone, ts0);
- assertEquals("clone", ts0, clone);
- }
-
- /**
- *
- */
- public void testClone2() {
- final MyTimestamp timestamp = new MyTimestamp();
- final MyTimestamp clone = timestamp.clone();
-
- assertTrue("clone", timestamp.clone().equals(timestamp));
- assertTrue("clone", clone.clone().equals(clone));
-
- assertEquals("clone", clone, timestamp);
- assertEquals("clone", timestamp, clone);
}
// ------------------------------------------------------------------------
}
}
- // ------------------------------------------------------------------------
- // clone
- // ------------------------------------------------------------------------
-
- /**
- * @throws CloneNotSupportedException cloning problem
- */
- public void testClone() throws CloneNotSupportedException {
- final ITmfTimestamp ts1 = new TmfTimestamp(12345);
- final ITmfTimestamp ts2 = new TmfTimestamp(12350);
-
- final TmfTimeRange range = new TmfTimeRange(ts1, ts2);
- final TmfTimeRange clone = range.clone();
-
- assertTrue("clone", range.clone().equals(range));
- assertTrue("clone", clone.clone().equals(clone));
-
- assertEquals("clone", range, clone);
- assertEquals("clone", ts1, clone.getStartTime());
- assertEquals("clone", ts2, clone.getEndTime());
- }
-
// ------------------------------------------------------------------------
// hashCode
// ------------------------------------------------------------------------
assertEquals("getPrecision", TmfTimestamp.ZERO.getPrecision(), ts.getPrecision());
}
- // ------------------------------------------------------------------------
- // clone
- // ------------------------------------------------------------------------
-
- private static class MyTimestamp extends TmfTimestamp {
-
- @Override
- public boolean equals(final Object other) {
- return super.equals(other);
- }
-
- @Override
- public MyTimestamp clone() {
- return (MyTimestamp) super.clone();
- }
- }
-
- /**
- *
- */
- public void testClone() {
- final ITmfTimestamp clone = ts0.clone();
-
- assertTrue("clone", ts0.clone().equals(ts0));
- assertTrue("clone", clone.clone().equals(clone));
-
- assertEquals("clone", clone, ts0);
- assertEquals("clone", ts0, clone);
- }
-
- /**
- *
- */
- public void testClone2() {
- final MyTimestamp timestamp = new MyTimestamp();
- final MyTimestamp clone = timestamp.clone();
-
- assertTrue("clone", timestamp.clone().equals(timestamp));
- assertTrue("clone", clone.clone().equals(clone));
-
- assertEquals("clone", clone, timestamp);
- assertEquals("clone", timestamp, clone);
- }
-
// ------------------------------------------------------------------------
// hashCode
// ------------------------------------------------------------------------
* @param timestamp long
*/
public CtfTmfTimestamp(long timestamp) {
- setValue(timestamp, ITmfTimestamp.NANOSECOND_SCALE, 0);
+ super(timestamp, ITmfTimestamp.NANOSECOND_SCALE, 0);
type = TimestampType.DAY;
}
*/
public ITmfTimestamp getDelta(ITmfTimestamp ts);
- /**
- * @return a clone of the timestamp
- */
- public ITmfTimestamp clone();
-
// ------------------------------------------------------------------------
// Comparable
// ------------------------------------------------------------------------
clone = (TmfEvent) super.clone();
clone.fTrace = fTrace;
clone.fRank = fRank;
- clone.fTimestamp = fTimestamp != null ? fTimestamp.clone() : null;
+ clone.fTimestamp = fTimestamp;
clone.fSource = fSource;
clone.fType = fType != null ? fType.clone() : null;
clone.fContent = fContent != null ? fContent.clone() : null;
@Override
public TmfLostEvent clone() {
TmfLostEvent clone = null;
- try {
- clone = (TmfLostEvent) super.clone();
- clone.fTimeRange = fTimeRange.clone();
- clone.fNbLostEvents = fNbLostEvents;
- } catch (CloneNotSupportedException e) {
- }
+ clone = (TmfLostEvent) super.clone();
+ clone.fTimeRange = fTimeRange;
+ clone.fNbLostEvents = fNbLostEvents;
return clone;
}
}
/**
- * Copy constructor
+ * Copy constructor.
*
- * @param timestamp the timestamp to copy or scale to 0
- * @throws IllegalArgumentException if timestamp is null
- * @throws ArithmeticException if timestamp can't be scaled to 0
+ * If the parameter is not a TmfSimpleTimestamp, the timestamp will be
+ * scaled to seconds, and the precision will be discarded.
+ *
+ * @param timestamp
+ * The timestamp to copy
*/
public TmfSimpleTimestamp(final ITmfTimestamp timestamp) {
- if (timestamp == null) {
- throw new IllegalArgumentException();
- }
- setValue(timestamp.normalize(0, 0).getValue(), 0, 0);
+ super(timestamp.normalize(0, ITmfTimestamp.SECOND_SCALE).getValue(), 0, 0);
}
// ------------------------------------------------------------------------
return super.getDelta(ts);
}
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#clone()
- */
- @Override
- public TmfSimpleTimestamp clone() {
- return (TmfSimpleTimestamp) super.clone();
- }
-
// ------------------------------------------------------------------------
// Object
// ------------------------------------------------------------------------
/*******************************************************************************
* Copyright (c) 2009, 2012 Ericsson
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Francois Chouinard - Initial API and implementation
* Francois Chouinard - Updated as per TMF Event Model 1.0
/**
* A utility class to define and manage time ranges.
- *
+ *
* @version 1.0
* @author Francois Chouinard
- *
+ *
* @see ITmfTimestamp
*/
-public final class TmfTimeRange implements Cloneable {
+public final class TmfTimeRange {
// ------------------------------------------------------------------------
// Constants
/**
* The null time range
*/
- public static final TmfTimeRange NULL_RANGE =
- new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_BANG);
+ public static final TmfTimeRange NULL_RANGE = new TmfTimeRange();
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private ITmfTimestamp fStartTime;
- private ITmfTimestamp fEndTime;
+ private final ITmfTimestamp fStartTime;
+ private final ITmfTimestamp fEndTime;
// ------------------------------------------------------------------------
// Constructors
/**
* Default constructor
*/
- @SuppressWarnings("unused")
private TmfTimeRange() {
+ fStartTime = TmfTimestamp.BIG_BANG;
+ fEndTime = TmfTimestamp.BIG_BANG;
}
/**
* Full constructor
- *
+ *
* @param startTime start of the time range
* @param endTime end of the time range
*/
/**
* Copy constructor
- *
+ *
* @param range the other time range
*/
public TmfTimeRange(final TmfTimeRange range) {
/**
* Check if the timestamp is within the time range
- *
+ *
* @param ts the timestamp to check
* @return true if [startTime] <= [ts] <= [endTime]
*/
/**
* Check if the time range is within the time range
- *
+ *
* @param range the other time range
* @return true if [range] is fully contained
*/
/**
* Get intersection of two time ranges
- *
+ *
* @param range the other time range
* @return the intersection time range, or null if no intersection exists
*/
return null; // no intersection
}
- return new TmfTimeRange(fStartTime.compareTo(range.fStartTime, true) < 0
- ? range.fStartTime
- : fStartTime, fEndTime.compareTo(range.fEndTime, true) > 0
- ? range.fEndTime
+ return new TmfTimeRange(fStartTime.compareTo(range.fStartTime, true) < 0
+ ? range.fStartTime
+ : fStartTime, fEndTime.compareTo(range.fEndTime, true) > 0
+ ? range.fEndTime
: fEndTime);
}
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @Override
- public TmfTimeRange clone() throws CloneNotSupportedException {
- TmfTimeRange clone = null;
- try {
- clone = (TmfTimeRange) super.clone();
- clone.fStartTime = fStartTime.clone();
- clone.fEndTime = fEndTime.clone();
- }
- catch (final CloneNotSupportedException e) {
- }
- return clone;
- }
-
// ------------------------------------------------------------------------
// Object
// ------------------------------------------------------------------------
* @version 1.1
* @author Francois Chouinard
*/
-public class TmfTimestamp implements ITmfTimestamp, Cloneable {
+public class TmfTimestamp implements ITmfTimestamp {
// ------------------------------------------------------------------------
// Constants
/**
* The timestamp raw value (mantissa)
*/
- private long fValue;
+ private final long fValue;
/**
* The timestamp scale (magnitude)
*/
- private int fScale;
+ private final int fScale;
/**
* The value precision (tolerance)
*/
- private int fPrecision;
+ private final int fPrecision;
// ------------------------------------------------------------------------
// Constructors
fPrecision = timestamp.getPrecision();
}
- // ------------------------------------------------------------------------
- // Setters
- // ------------------------------------------------------------------------
-
- protected void setValue(long value, int scale, int precision) {
- fValue = value;
- fScale = scale;
- fPrecision = precision;
- }
-
// ------------------------------------------------------------------------
// ITmfTimestamp
// ------------------------------------------------------------------------
// Handle the trivial case
if (fScale == scale && offset == 0) {
- return new TmfTimestamp(this);
+ return this;
}
// In case of big bang and big crunch just return this (no need to normalize)
return new TmfTimestamp(value, fScale, fPrecision + nts.getPrecision());
}
- // ------------------------------------------------------------------------
- // Cloneable
- // ------------------------------------------------------------------------
-
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @Override
- public TmfTimestamp clone() {
- TmfTimestamp clone = null;
- try {
- clone = (TmfTimestamp) super.clone();
- clone.fValue = fValue;
- clone.fScale = fScale;
- clone.fPrecision = fPrecision;
- } catch (final CloneNotSupportedException e) {
- }
- return clone;
- }
-
// ------------------------------------------------------------------------
// Comparable
// ------------------------------------------------------------------------
try {
clone = (TmfCheckpoint) super.clone();
clone.fContext = (fContext != null) ? fContext.clone() : null;
- clone.fTimestamp = (fTimestamp != null) ? fTimestamp.clone() : null;
+ clone.fTimestamp = fTimestamp;
} catch (final CloneNotSupportedException e) {
}
return clone;
final long position = rank / fCheckpointInterval;
// Add new entry at proper location (if empty)
if (fTraceIndex.size() == position) {
- fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), saveContext(context)));
+ fTraceIndex.add(new TmfCheckpoint(timestamp, saveContext(context)));
}
}
}
if (event == null) {
return;
}
- final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH);
+ final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp(), TmfTimestamp.BIG_CRUNCH);
final TmfExperimentRangeUpdatedSignal signal = new TmfExperimentRangeUpdatedSignal(this, this, timeRange);
// Broadcast in separate thread to prevent deadlock
*/
@Override
public ITmfTimestamp getStartTime() {
- return fStartTime.clone();
+ return fStartTime;
}
/* (non-Javadoc)
*/
@Override
public ITmfTimestamp getEndTime() {
- return fEndTime.clone();
+ return fEndTime;
}
// ------------------------------------------------------------------------
* @param range the new time range
*/
protected void setTimeRange(final TmfTimeRange range) {
- fStartTime = range.getStartTime().clone();
- fEndTime = range.getEndTime().clone();
+ fStartTime = range.getStartTime();
+ fEndTime = range.getEndTime();
}
/**
* @param startTime the new first event timestamp
*/
protected void setStartTime(final ITmfTimestamp startTime) {
- fStartTime = startTime.clone();
+ fStartTime = startTime;
}
/**
* @param endTime the new last event timestamp
*/
protected void setEndTime(final ITmfTimestamp endTime) {
- fEndTime = endTime.clone();
+ fEndTime = endTime;
}
/**
*/
protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
- fStartTime = timestamp.clone();
+ fStartTime = timestamp;
}
if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
- fEndTime = timestamp.clone();
+ fEndTime = timestamp;
}
if (context.hasValidRank()) {
long rank = context.getRank();
if (endEvent == null) {
throw new IllegalArgumentException("TmfAsyncSequenceDiagramEvent constructor: endEvent=null"); //$NON-NLS-1$
}
- fEndTime = endEvent.getTimestamp().clone();
+ fEndTime = endEvent.getTimestamp();
}
// ------------------------------------------------------------------------
(name == null ? ", name=null" : "")); //$NON-NLS-1$ //$NON-NLS-2$
}
- fStartTime = startEvent.getTimestamp().clone();
+ fStartTime = startEvent.getTimestamp();
fSender = sender;
fReceiver = receiver;
* @param max the scale max
*/
public void showToolTip(ITmfTimestamp value, ITmfTimestamp min, ITmfTimestamp max) {
- fMinMaxRange = new TmfTimeRange(min.clone(), max.clone());
- fCurrentValue = value.clone();
+ fMinMaxRange = new TmfTimeRange(min, max);
+ fCurrentValue = value;
int w = fToolTipShell.getBounds().width;
int h = fToolTipShell.getBounds().height;
* @param time the time when the message end
*/
public void setEndTime(ITmfTimestamp time) {
- fEndTime = time.clone();
+ fEndTime = time;
fHasTime = true;
if (getStartLifeline() != null && getStartLifeline().getFrame() != null) {
getStartLifeline().getFrame().setHasTimeInfo(true);
* @param time the time when the message start
*/
public void setStartTime(ITmfTimestamp time) {
- fStartTime = time.clone();
+ fStartTime = time;
fHasTime = true;
if (getStartLifeline() != null && getStartLifeline().getFrame() != null) {
getStartLifeline().getFrame().setHasTimeInfo(true);
protected void updateMinMax(SDTimeEvent m1, SDTimeEvent m2) {
ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime());
if (fComputeMinMax) {
- fMinTime = delta.clone();
+ fMinTime = delta;
if (fMinTime.compareTo(TmfTimestamp.ZERO, false) < 0) {
fMinTime = new TmfTimestamp(0, m1.getTime().getScale(), m1.getTime().getPrecision());
}
- fMaxTime = fMinTime.clone();
+ fMaxTime = fMinTime;
fComputeMinMax = false;
}
if ((delta.compareTo(fMinTime, true) < 0) && (delta.compareTo(TmfTimestamp.ZERO, false) > 0)) {
- fMinTime = delta.clone();
+ fMinTime = delta;
}
if ((delta.compareTo(fMaxTime, true) > 0) && (delta.compareTo(TmfTimestamp.ZERO, false) > 0)) {
- fMaxTime = delta.clone();
+ fMaxTime = delta;
}
}
* @param time the time when the execution occurrence starts
*/
public void setStartTime(ITmfTimestamp time) {
- fStartTime = time.clone();
+ fStartTime = time;
fHasTimeInfo = true;
if (fLifeline != null) {
fLifeline.setTimeInfo(true);
* @param time the time when the execution occurrence ends
*/
public void setEndTime(ITmfTimestamp time) {
- fEndTime = time.clone();
+ fEndTime = time;
fHasTimeInfo = true;
if (fLifeline != null) {
fLifeline.setTimeInfo(true);
/**********************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others.
* Copyright (c) 2011, 2012 Ericsson.
- *
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
+ *
+ * Contributors:
* IBM - Initial API and implementation
* Bernd Hufmann - Updated for TMF
**********************************************************************/
* <br>
* <br>
* Usage example:
- *
+ *
* <pre>
* Frame frame;
* Lifeline lifeLine1;
* Lifeline lifeLine2;
- *
+ *
* SyncMessage message = new SyncMessage();
* // Create a new event occurrence on each lifeline
* lifeline1.getNewOccurrenceIndex();
* // add the message to the frame
* frame.addMessage(message);
* </pre>
- *
+ *
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
* @version 1.0
* @author sveyrier
- *
+ *
*/
public class SyncMessage extends BaseMessage implements ITimeRange {
* SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
* event occurrence on each lifeline (the greater value will be used).<br>
* This synchronization is only done if the end lifeline has already been set.
- *
+ *
* @param lifeline the message sender
*/
public void autoSetStartLifeline(Lifeline lifeline) {
* SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
* event occurrence on each lifeline (the greater value will be used).<br>
* This synchronization is only done if the start lifeline has already been set.
- *
+ *
* @param lifeline the message receiver
*/
public void autoSetEndLifeline(Lifeline lifeline) {
* SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
* event occurrence on each lifeline (the greater value will be used).<br>
* This synchronization is only done if the start lifeline has already been set.
- *
+ *
* @param lifeline the message receiver
*/
@Override
* SyncMessage must occur at the same event occurrence on both lifelines, this method is responsible to synchronize the
* event occurrence on each lifeline (the greater value will be used).<br>
* This synchronization is only done if the start lifeline has already been set.
- *
+ *
* @param lifeline the message receiver
*/
@Override
/**
* Set the event occurrence when this message occurs.<br>
- *
+ *
* @param occurrence the event occurrence to assign to this message.<br>
* @see Lifeline Lifeline for more event occurence details
*/
/**
* Set the message return associated with this message.
- *
+ *
* @param message the message return to associate
*/
protected void setMessageReturn(SyncMessageReturn message) {
/**
* Returns the syncMessageReturn associated to this syncMessage
- *
+ *
* @return the message return
*/
public SyncMessageReturn getMessageReturn() {
/**
* Set the time when the message occurs
- *
+ *
* @param time the time when the message occurs
*/
public void setTime(ITmfTimestamp time) {
- fEventTime = time.clone();
+ fEventTime = time;
fHasTimeInfo = true;
if (getStartLifeline() != null && getStartLifeline().getFrame() != null) {
getStartLifeline().getFrame().setHasTimeInfo(true);
/*
* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#getStartTime()
- */
+ */
@Override
public ITmfTimestamp getStartTime() {
return fEventTime;
/*
* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#hasTimeInfo()
- */
+ */
@Override
public boolean hasTimeInfo() {
return fHasTimeInfo;
fLock.lock();
try {
if (fCurrentTime != null) {
- return fCurrentTime.clone();
+ return fCurrentTime;
}
return null;
} finally {
++fNbSeqEvents;
if (fFirstTime == null) {
- fFirstTime = event.getTimestamp().clone();
+ fFirstTime = event.getTimestamp();
}
- fLastTime = event.getTimestamp().clone();
+ fLastTime = event.getTimestamp();
if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
fLock.lock();
return false;
}
- TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime().clone(), fCheckPoints.get(fCheckPoints.size()-1).getEndTime().clone());
+ TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime(), fCheckPoints.get(fCheckPoints.size()-1).getEndTime());
fFindJob = new SearchJob(findCriteria, window);
fFindJob.schedule();
fView.toggleWaitCursorAsync(true);
if (fCriteria.isLifeLineSelected()) {
if (fCriteria.matches(sdEvent.getSender())) {
- fFoundTime = event.getTimestamp().clone();
+ fFoundTime = event.getTimestamp();
fIsFound = true;
super.cancel();
}
if (fCriteria.matches(sdEvent.getReceiver())) {
- fFoundTime = event.getTimestamp().clone();
+ fFoundTime = event.getTimestamp();
fIsFound = true;
super.cancel();
}
}
if (fCriteria.isSyncMessageSelected() && fCriteria.matches(sdEvent.getName())) {
- fFoundTime = event.getTimestamp().clone();
+ fFoundTime = event.getTimestamp();
fIsFound = true;
super.cancel();
}