From bd54d363b79ab554de3036a01c59c40aff78c1a9 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 1 Feb 2013 17:21:19 -0500 Subject: [PATCH] tmf: Make TmfEvent immutable The immediate benefit of immutable events is that we can avoid doing copies in many places in the framework (for indexing, checkpoints, et al.). It also alleviates many potential concurrency issues. For specific sub-classes that need to have mutable (non-final) fields, the recommended - hopefully transitional - approach is to re-define the fields in question and override the getters to make sure the extended class's versions are used. This was done for CustomEvent in this patch. Change-Id: I6a9ec635eaa68b03d1c5a6875f60ece7d47cb024 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/10123 Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse --- .../tmf/core/tests/event/TmfEventTest.java | 212 ++---------------- .../tmf/core/trace/TmfExperimentContext.java | 2 +- .../tmf/core/ctfadaptor/CtfTmfEvent.java | 3 +- .../linuxtools/tmf/core/event/ITmfEvent.java | 8 +- .../linuxtools/tmf/core/event/TmfEvent.java | 142 ++---------- .../tmf/core/event/TmfLostEvent.java | 49 +--- .../tmf/core/trace/TmfCheckpointIndexer.java | 4 +- .../tmf/ui/parsers/custom/CustomEvent.java | 112 ++++++++- .../tmf/ui/viewers/events/TmfEventsCache.java | 4 +- .../tmf/ui/viewers/events/TmfEventsTable.java | 2 +- 10 files changed, 155 insertions(+), 383 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java index d541d20668..e8737e3a2d 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java @@ -31,7 +31,6 @@ import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; -import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventType; @@ -84,8 +83,6 @@ public class TmfEventTest { private final String fReference2 = "Some other reference"; private final ITmfEvent fEvent2 = new TmfEvent(null, 1, fTimestamp2, fSource, fType, fContent2, fReference2); - private final String fTracePath = "testfiles" + File.separator + "A-Test-10K"; - // ------------------------------------------------------------------------ // Helper functions // ------------------------------------------------------------------------ @@ -193,195 +190,6 @@ public class TmfEventTest { } } - // ------------------------------------------------------------------------ - // Setters - // ------------------------------------------------------------------------ - - private static class TestEvent extends TmfEvent { - - public TestEvent(final ITmfEvent event) { - super(event); - } - - @Override - public void setTrace(final ITmfTrace trace) { - super.setTrace(trace); - } - - @Override - public void setRank(final long rank) { - super.setRank(rank); - } - - @Override - public void setTimestamp(final ITmfTimestamp timestamp) { - super.setTimestamp(timestamp); - } - - @Override - public void setSource(final String source) { - super.setSource(source); - } - - @Override - public void setType(final ITmfEventType type) { - super.setType(type); - } - - @Override - public void setContent(final ITmfEventField content) { - super.setContent(content); - } - - @Override - public void setReference(final String reference) { - super.setReference(reference); - } - - } - - private ITmfTrace setupTrace() { - ITmfTrace trace = null; - try { - final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(fTracePath), null); - final File test = new File(FileLocator.toFileURL(location).toURI()); - trace = new TmfTraceStub(test.toURI().getPath(), 500, false); - } catch (final TmfTraceException e) { - e.printStackTrace(); - } catch (final URISyntaxException e) { - e.printStackTrace(); - } catch (final IOException e) { - e.printStackTrace(); - } - return trace; - } - - /** - * - */ - public void testSetTrace() { - final ITmfTrace trace = setupTrace(); - assertNotNull(trace); - - final TestEvent event = new TestEvent(fEvent1); - assertNull("setTrace", event.getTrace()); - - event.setTrace(trace); - assertEquals("setTrace", trace, event.getTrace()); - - event.setTrace(null); - assertNull("setTrace", event.getTrace()); - - trace.dispose(); - } - - /** - * - */ - public void testSetRank() { - final TestEvent event = new TestEvent(fEvent1); - assertEquals("setRank", 0, event.getRank()); - - event.setRank(1); - assertEquals("setRank", 1, event.getRank()); - - event.setRank(-1); - assertEquals("setRank", -1, event.getRank()); - - event.setRank(0); - assertEquals("setRank", 0, event.getRank()); - } - - /** - * - */ - public void testSetTimestamp() { - final TestEvent event = new TestEvent(fEvent1); - assertEquals("setTimestamp", fTimestamp1, event.getTimestamp()); - - event.setTimestamp(fTimestamp2); - assertEquals("setTimestamp", fTimestamp2, event.getTimestamp()); - - event.setTimestamp(null); - assertNull("setTimestamp", event.getTimestamp()); - - event.setTimestamp(fTimestamp1); - assertEquals("setTimestamp", fTimestamp1, event.getTimestamp()); - } - - /** - * - */ - public void testSetSource() { - final TestEvent event = new TestEvent(fEvent1); - assertEquals("setSource", fSource, event.getSource()); - - final String source2 = "another source"; - event.setSource(source2); - assertEquals("setContent", source2, event.getSource()); - - event.setSource(null); - assertNull("setContent", event.getSource()); - - event.setSource(fSource); - assertEquals("setContent", fSource, event.getSource()); - } - - /** - * - */ - public void testSetType() { - final TestEvent event = new TestEvent(fEvent1); - assertEquals("setType", fType, event.getType()); - - final String typeId = "OtherTestType"; - final String[] labels = new String[] { fLabel2, fLabel1 }; - final TmfEventType newType = new TmfEventType(fContext, typeId, TmfEventField.makeRoot(labels)); - - event.setType(newType); - assertEquals("setType", newType, event.getType()); - - event.setType(null); - assertNull("setType", event.getType()); - - event.setType(fType); - assertEquals("setType", fType, event.getType()); - } - - /** - * - */ - public void testSetContent() { - final TestEvent event = new TestEvent(fEvent1); - assertEquals("setContent", fContent1, event.getContent()); - - event.setContent(fContent2); - assertEquals("setContent", fContent2, event.getContent()); - - event.setContent(null); - assertNull("setContent", event.getContent()); - - event.setContent(fContent1); - assertEquals("setContent", fContent1, event.getContent()); - } - - /** - * - */ - public void testSetReference() { - final TestEvent event = new TestEvent(fEvent1); - assertEquals("setReference", fReference1, event.getReference()); - - event.setReference(fReference2); - assertEquals("setReference", fReference2, event.getReference()); - - event.setReference(null); - assertNull("setReference", event.getReference()); - - event.setReference(fReference1); - assertEquals("setReference", fReference1, event.getReference()); - } - // ------------------------------------------------------------------------ // hashCode // ------------------------------------------------------------------------ @@ -589,4 +397,24 @@ public class TmfEventTest { assertEquals("toString", expected2, fEvent2.toString()); } + /** + * Test the .toString() with extended classes. + * It should print the correct class name. + */ + @Test + public void testToStringExtended() { + class ExtendedEvent extends TmfEvent { + ExtendedEvent(ITmfEvent event) { + super(event); + } + } + ExtendedEvent event = new ExtendedEvent(fEvent1); + String expected = "ExtendedEvent [fTimestamp=" + fTimestamp1 + + ", fTrace=null, fRank=0, fSource=" + fSource + + ", fType=" + fType + ", fContent=" + fContent1 + + ", fReference=" + fReference1 + "]"; + + assertEquals(expected, event.toString()); + } + } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java index e000140c69..9109fd35bd 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentContext.java @@ -135,7 +135,7 @@ public class TmfExperimentContext extends TmfContext { private ITmfEvent[] cloneEvents() { final ITmfEvent[] events = new ITmfEvent[fEvents.length]; for (int i = 0; i < fEvents.length; i++) { - events[i] = (fEvents[i] != null) ? fEvents[i].clone() : null; + events[i] = fEvents[i]; } return events; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java index 3635ced6a5..c7a2129d74 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map.Entry; import java.util.Set; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.linuxtools.ctf.core.event.CTFCallsite; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; @@ -43,7 +42,7 @@ import org.eclipse.ui.views.properties.IPropertySource; * @author Alexandre Montplaisir * @since 2.0 */ -public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { +public final class CtfTmfEvent implements ITmfEvent, Cloneable { // ------------------------------------------------------------------------ // Constants diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java index 95e24f46a9..e8defc0a2b 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java @@ -12,6 +12,7 @@ package org.eclipse.linuxtools.tmf.core.event; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; /** @@ -36,7 +37,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; * @see ITmfEventField * @see TmfEvent */ -public interface ITmfEvent { +public interface ITmfEvent extends IAdaptable { // ------------------------------------------------------------------------ // Constants @@ -106,9 +107,4 @@ public interface ITmfEvent { */ public String getReference(); - /** - * @return a clone of the event - */ - public ITmfEvent clone(); - } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java index 61e2c1c52a..f48517446c 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which @@ -9,21 +9,17 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Updated as per TMF Event Model 1.0 + * Alexandre Montplaisir - Made immutable *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.event; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.ui.views.properties.IPropertySource; /** * A basic implementation of ITmfEvent. - *

- * Note that for performance reasons TmfEvent is NOT immutable. If a shallow - * copy of the event is needed, use the copy constructor. Otherwise (deep copy) - * use clone(). * * @version 1.0 * @author Francois Chouinard @@ -33,19 +29,19 @@ import org.eclipse.ui.views.properties.IPropertySource; * @see ITmfEventField * @see ITmfTrace */ -public class TmfEvent implements ITmfEvent, IAdaptable, Cloneable { +public class TmfEvent implements ITmfEvent { // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ - private ITmfTrace fTrace; - private long fRank; - private ITmfTimestamp fTimestamp; - private String fSource; - private ITmfEventType fType; - private ITmfEventField fContent; - private String fReference; + private final ITmfTrace fTrace; + private final long fRank; + private final ITmfTimestamp fTimestamp; + private final String fSource; + private final ITmfEventType fType; + private final ITmfEventField fContent; + private final String fReference; // ------------------------------------------------------------------------ // Constructors @@ -121,146 +117,45 @@ public class TmfEvent implements ITmfEvent, IAdaptable, Cloneable { // ITmfEvent // ------------------------------------------------------------------------ - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace() - */ @Override public ITmfTrace getTrace() { return fTrace; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank() - */ @Override public long getRank() { return fRank; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp() - */ @Override public ITmfTimestamp getTimestamp() { return fTimestamp; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource() - */ @Override public String getSource() { return fSource; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType() - */ @Override public ITmfEventType getType() { return fType; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent() - */ @Override public ITmfEventField getContent() { return fContent; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference() - */ @Override public String getReference() { return fReference; } - // ------------------------------------------------------------------------ - // Convenience setters - // ------------------------------------------------------------------------ - - /** - * @param trace the new event trace - */ - protected void setTrace(final ITmfTrace trace) { - fTrace = trace; - } - - /** - * @param rank the new event rank - */ - protected void setRank(final long rank) { - fRank = rank; - } - - /** - * @param timestamp the new event timestamp - */ - protected void setTimestamp(final ITmfTimestamp timestamp) { - fTimestamp = timestamp; - } - - /** - * @param source the new event source - */ - protected void setSource(final String source) { - fSource = source; - } - - /** - * @param type the new event type - */ - protected void setType(final ITmfEventType type) { - fType = type; - } - - /** - * @param content the event new content - */ - protected void setContent(final ITmfEventField content) { - fContent = content; - } - - /** - * @param reference the new event reference - */ - protected void setReference(final String reference) { - fReference = reference; - } - - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - - /* (non-Javadoc) - * @see java.lang.Object#clone() - */ - @Override - public TmfEvent clone() { - TmfEvent clone = null; - try { - clone = (TmfEvent) super.clone(); - clone.fTrace = fTrace; - clone.fRank = fRank; - clone.fTimestamp = fTimestamp; - clone.fSource = fSource; - clone.fType = fType != null ? fType.clone() : null; - clone.fContent = fContent; - clone.fReference = fReference; - } catch (final CloneNotSupportedException e) { - } - return clone; - } - // ------------------------------------------------------------------------ // Object // ------------------------------------------------------------------------ - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -275,9 +170,6 @@ public class TmfEvent implements ITmfEvent, IAdaptable, Cloneable { return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -338,20 +230,16 @@ public class TmfEvent implements ITmfEvent, IAdaptable, Cloneable { return true; } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override @SuppressWarnings("nls") public String toString() { - return "TmfEvent [fTimestamp=" + fTimestamp + ", fTrace=" + fTrace + ", fRank=" + fRank - + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent - + ", fReference=" + fReference + "]"; + return getClass().getSimpleName() + " [fTimestamp=" + getTimestamp() + + ", fTrace=" + getTrace() + ", fRank=" + getRank() + + ", fSource=" + getSource() + ", fType=" + getType() + + ", fContent=" + getContent() + ", fReference=" + getReference() + + "]"; } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ /** * @since 2.0 */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfLostEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfLostEvent.java index b721f52a21..a4223affaf 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfLostEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfLostEvent.java @@ -69,17 +69,13 @@ public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { * @param event the original event */ public TmfLostEvent(final ITmfLostEvent event) { - if (event == null) { - throw new IllegalArgumentException(); - } - setTrace(event.getTrace()); - setRank(event.getRank()); - setTimestamp(event.getTimestamp()); - setSource(event.getSource()); - setType(event.getType()); - setContent(event.getContent()); - setReference(event.getReference()); - + super( event.getTrace(), + event.getRank(), + event.getTimestamp(), + event.getSource(), + event.getType(), + event.getContent(), + event.getReference()); fTimeRange = event.getTimeRange(); fNbLostEvents = event.getNbLostEvents(); } @@ -88,17 +84,11 @@ public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { // ITmfLostEvent // ------------------------------------------------------------------------ - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent#getTimeRange() - */ @Override public TmfTimeRange getTimeRange() { return fTimeRange; } - /* (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent#getNbLostEvents() - */ @Override public long getNbLostEvents() { return fNbLostEvents; @@ -122,29 +112,10 @@ public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { fNbLostEvents = nbLostEvents; } - // ------------------------------------------------------------------------ - // Cloneable - // ------------------------------------------------------------------------ - - /* (non-Javadoc) - * @see java.lang.Object#clone() - */ - @Override - public TmfLostEvent clone() { - TmfLostEvent clone = null; - clone = (TmfLostEvent) super.clone(); - clone.fTimeRange = fTimeRange; - clone.fNbLostEvents = fNbLostEvents; - return clone; - } - // ------------------------------------------------------------------------ // Object // ------------------------------------------------------------------------ - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -154,9 +125,6 @@ public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { if (this == obj) { @@ -182,9 +150,6 @@ public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { return true; } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override @SuppressWarnings("nls") public String toString() { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java index 7acd78af17..dd9920942e 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java @@ -353,7 +353,7 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer { ITmfEvent[] trcEvts = expCtx.getEvents(); for (int i = 0; i < size; i++) { ITmfEvent event = expContext.getEvents()[i]; - trcEvts[i] = (event != null) ? event.clone() : null; + trcEvts[i] = event; } return expCtx; } @@ -383,7 +383,7 @@ public class TmfCheckpointIndexer implements ITmfTraceIndexer { ITmfEvent[] trcEvts = expContext.getEvents(); for (int i = 0; i < size; i++) { ITmfEvent event = trcEvts[i]; - ctx.getEvents()[i] = (event != null) ? event.clone() : null; + ctx.getEvents()[i] = event; } return ctx; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEvent.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEvent.java index fed9735f1b..2db21759d7 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEvent.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEvent.java @@ -20,6 +20,8 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn; +import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; +import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; @@ -43,6 +45,15 @@ public class CustomEvent extends TmfEvent { /** Empty message */ protected static final String NO_MESSAGE = ""; //$NON-NLS-1$ + /** Replacement for the super-class' timestamp field */ + private ITmfTimestamp customEventTimestamp; + + /** Replacement for the super-class' content field */ + private ITmfEventField customEventContent; + + /** Replacement for the super-class' type field */ + private ITmfEventType customEventType; + /** The trace to which this event belongs */ protected CustomTraceDefinition fDefinition; @@ -74,6 +85,11 @@ public class CustomEvent extends TmfEvent { super(other); fDefinition = definition; fData = new HashMap(); + + /* Set our overridden fields */ + customEventTimestamp = other.getTimestamp(); + customEventContent = other.getContent(); + customEventType = other.getType(); } /** @@ -95,19 +111,77 @@ public class CustomEvent extends TmfEvent { public CustomEvent(CustomTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) { - super(parentTrace, timestamp, source, type, null, reference); + /* Do not use upstream's fields for stuff we override */ + super(parentTrace, null, source, null, null, reference); fDefinition = definition; fData = new HashMap(); + + /* Set our overridden fields */ + customEventTimestamp = timestamp; + customEventContent = null; + customEventType = type; } + // ------------------------------------------------------------------------ + // Overridden getters + // ------------------------------------------------------------------------ + @Override public ITmfTimestamp getTimestamp() { if (fData != null) { processData(); } - return super.getTimestamp(); + return customEventTimestamp; } + @Override + public ITmfEventField getContent() { + return customEventContent; + } + + @Override + public ITmfEventType getType() { + return customEventType; + } + + // ------------------------------------------------------------------------ + // Setters + // ------------------------------------------------------------------------ + + /** + * Set this event's timestamp + * + * @param timestamp + * The new timestamp + */ + protected void setTimestamp(ITmfTimestamp timestamp) { + customEventTimestamp = timestamp; + } + + /** + * Set this event's content + * + * @param content + * The new content + */ + protected void setContent(ITmfEventField content) { + customEventContent = content; + } + + /** + * Set this event's type + * + * @param type + * The new type + */ + protected void setType(ITmfEventType type) { + customEventType = type; + } + + // ------------------------------------------------------------------------ + // Other operations + // ------------------------------------------------------------------------ + /** * @return The event fields */ @@ -150,20 +224,17 @@ public class CustomEvent extends TmfEvent { fData = null; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((fDefinition == null) ? 0 : fDefinition.hashCode()); + result = prime * result + ((customEventTimestamp == null) ? 0 : customEventTimestamp.hashCode()); + result = prime * result + ((customEventContent == null) ? 0 : customEventContent.hashCode()); + result = prime * result + ((customEventType == null) ? 0 : customEventType.hashCode()); return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { if (this == obj) { @@ -183,6 +254,31 @@ public class CustomEvent extends TmfEvent { } else if (!fDefinition.equals(other.fDefinition)) { return false; } + + if (customEventTimestamp == null) { + if (other.customEventTimestamp != null) { + return false; + } + } else if (!customEventTimestamp.equals(other.customEventTimestamp)) { + return false; + } + + if (customEventContent == null) { + if (other.customEventContent != null) { + return false; + } + } else if (!customEventContent.equals(other.customEventContent)) { + return false; + } + + if (customEventType == null) { + if (other.customEventType != null) { + return false; + } + } else if (!customEventType.equals(other.customEventType)) { + return false; + } + return true; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java index c5996b8f9e..47ba0f2c9f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsCache.java @@ -178,7 +178,7 @@ public class TmfEventsCache { if (index == fCacheEndIndex) { int i = index - fCacheStartIndex; if (i < fCache.length) { - fCache[i] = new CachedEvent(event.clone(), rank); + fCache[i] = new CachedEvent(event, rank); fCacheEndIndex++; } } @@ -348,7 +348,7 @@ public class TmfEventsCache { if (monitor.isCanceled()) { return; } - fCache[count] = new CachedEvent(event.clone(), rank); + fCache[count] = new CachedEvent(event, rank); count++; fCacheEndIndex++; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java index aad9495b24..060cdcb3fe 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java @@ -1313,7 +1313,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS final long rank = fFilterCheckCount; final int index = (int) fFilterMatchCount; fFilterMatchCount++; - fCache.storeEvent(event.clone(), rank, index); + fCache.storeEvent(event, rank, index); refreshTable(); } else if ((fFilterCheckCount % 100) == 0) { refreshTable(); -- 2.34.1