Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 151666 Details for
Bug 287562
[TMF] Update the Event Model code
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
TmfEvent update (2)
org.eclipse.linuxtools.tmf.patch (text/plain), 39.52 KB, created by
Francois Chouinard
on 2009-11-08 23:34:32 EST
(
hide
)
Description:
TmfEvent update (2)
Filename:
MIME Type:
Creator:
Francois Chouinard
Created:
2009-11-08 23:34:32 EST
Size:
39.52 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.linuxtools.tmf.ui >Index: src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java (working copy) >@@ -215,7 +215,7 @@ > event.getSource().getSourceId().toString(), > event.getType().getTypeId().toString(), > event.getReference().getValue().toString(), >- event.getContent().getContent() >+ event.getContent().toString() > }; > } > return fields; >@@ -292,4 +292,4 @@ > } > } > >-} >\ No newline at end of file >+} >#P org.eclipse.linuxtools.tmf.tests >Index: stubs/org/eclipse/linuxtools/tmf/event/TmfEventTypeStub.java >=================================================================== >--- stubs/org/eclipse/linuxtools/tmf/event/TmfEventTypeStub.java (revision 23661) >+++ stubs/org/eclipse/linuxtools/tmf/event/TmfEventTypeStub.java (working copy) >@@ -13,47 +13,34 @@ > package org.eclipse.linuxtools.tmf.event; > > /** >- * <b><u>TmfEventFormatStub</u></b> >+ * <b><u>TmfEventTypeStub</u></b> > * <p> > * TODO: Implement me. Please. > */ >-public class TmfEventFormatStub extends TmfEventFormat { >+public class TmfEventTypeStub extends TmfEventType { > >- // ======================================================================== >- // Attributes >- // ======================================================================== >+ // ======================================================================== >+ // Attributes >+ // ======================================================================== > >- // ======================================================================== >- // Constructors >- // ======================================================================== >+ // ======================================================================== >+ // Constructors >+ // ======================================================================== > >- public TmfEventFormatStub() { >- super(new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" }); >- } >+ public TmfEventTypeStub() { >+ super("TmfEventTypeStub", new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" }); >+ } > >- // ======================================================================== >- // Accessors >- // ======================================================================== >+ // ======================================================================== >+ // Accessors >+ // ======================================================================== > >- // ======================================================================== >- // Operators >- // ======================================================================== >+ // ======================================================================== >+ // Operators >+ // ======================================================================== > >- /* (non-Javadoc) >- * @see org.eclipse.linuxtools.tmf.event.TmfEventFormat#parse(java.lang.Object) >- */ >- @Override >- public TmfEventField[] parse(Object content) { >- TmfEventField field1 = new TmfEventField(1); >- TmfEventField field2 = new TmfEventField(-10); >- TmfEventField field3 = new TmfEventField(true); >- TmfEventField field4 = new TmfEventField("some string"); >- TmfEventField field5 = new TmfEventField(new TmfTimestamp(1, (byte) 2, 3)); >- return new TmfEventField[] { field1, field2, field3, field4, field5 }; >- } >- >- // ======================================================================== >- // Helper functions >- // ======================================================================== >+ // ======================================================================== >+ // Helper functions >+ // ======================================================================== > > } >Index: stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java >=================================================================== >--- stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java (revision 0) >+++ stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java (revision 0) >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 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 >+ *******************************************************************************/ >+ >+package org.eclipse.linuxtools.tmf.event; >+ >+import java.util.HashMap; >+import java.util.Map; >+ >+/** >+ * <b><u>TmfEventContentStub</u></b> >+ * <p> >+ * TODO: Implement me. Please. >+ */ >+public class TmfEventContentStub extends TmfEventContent { >+ >+ public TmfEventContentStub() { >+ super(new TmfEventTypeStub(), "DummyContent"); >+ } >+ >+ @Override >+ protected Map<String, Object> parseContent() { >+ Map<String, Object> result = new HashMap<String, Object>(); >+ String[] keys = fEventType.getLabels(); >+ >+ TmfEventField field = new TmfEventField(this, keys[0], 1); >+ result.put(keys[0], field); >+ >+ field = new TmfEventField(this, keys[1], -10); >+ result.put(keys[1], field); >+ >+ field = new TmfEventField(this, keys[2], true); >+ result.put(keys[2], field); >+ >+ field = new TmfEventField(this, keys[3], "some string"); >+ result.put(keys[3], field); >+ >+ field = new TmfEventField(this, keys[4], new TmfTimestamp(1, (byte) 2, 3)); >+ result.put(keys[4], field); >+ >+ return result; >+ } >+ >+} >Index: stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java >=================================================================== >--- stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java (revision 23661) >+++ stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java (working copy) >@@ -1,59 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2009 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 >- *******************************************************************************/ >- >-package org.eclipse.linuxtools.tmf.event; >- >-/** >- * <b><u>TmfEventFormatStub</u></b> >- * <p> >- * TODO: Implement me. Please. >- */ >-public class TmfEventFormatStub extends TmfEventFormat { >- >- // ======================================================================== >- // Attributes >- // ======================================================================== >- >- // ======================================================================== >- // Constructors >- // ======================================================================== >- >- public TmfEventFormatStub() { >- super(new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" }); >- } >- >- // ======================================================================== >- // Accessors >- // ======================================================================== >- >- // ======================================================================== >- // Operators >- // ======================================================================== >- >- /* (non-Javadoc) >- * @see org.eclipse.linuxtools.tmf.event.TmfEventFormat#parse(java.lang.Object) >- */ >- @Override >- public TmfEventField[] parse(Object content) { >- TmfEventField field1 = new TmfEventField(1); >- TmfEventField field2 = new TmfEventField(-10); >- TmfEventField field3 = new TmfEventField(true); >- TmfEventField field4 = new TmfEventField("some string"); >- TmfEventField field5 = new TmfEventField(new TmfTimestamp(1, (byte) 2, 3)); >- return new TmfEventField[] { field1, field2, field3, field4, field5 }; >- } >- >- // ======================================================================== >- // Helper functions >- // ======================================================================== >- >-} >Index: stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java >=================================================================== >--- stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java (revision 23661) >+++ stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java (working copy) >@@ -19,7 +19,6 @@ > > import org.eclipse.linuxtools.tmf.event.TmfEvent; > import org.eclipse.linuxtools.tmf.event.TmfEventContent; >-import org.eclipse.linuxtools.tmf.event.TmfEventFormat; > import org.eclipse.linuxtools.tmf.event.TmfEventReference; > import org.eclipse.linuxtools.tmf.event.TmfEventSource; > import org.eclipse.linuxtools.tmf.event.TmfEventType; >@@ -36,8 +35,8 @@ > // Attributes > // ======================================================================== > >- private final int NB_FORMATS = 10; >- private final TmfEventFormat[] fFormats; >+ private final int NB_TYPES = 10; >+ private final TmfEventType[] fEventTypes; > > // ======================================================================== > // Constructors >@@ -44,8 +43,8 @@ > // ======================================================================== > > public TmfEventParserStub() { >- fFormats = new TmfEventFormat[NB_FORMATS]; >- for (int i = 0; i < NB_FORMATS; i++) { >+ fEventTypes = new TmfEventType[NB_TYPES]; >+ for (int i = 0; i < NB_TYPES; i++) { > Vector<String> format = new Vector<String>(); > for (int j = 1; j <= i; j++) { > format.add(new String("Fmt-" + i + "-Fld-" + j)); >@@ -51,7 +50,7 @@ > format.add(new String("Fmt-" + i + "-Fld-" + j)); > } > String[] fields = new String[i]; >- fFormats[i] = new TmfEventFormat(format.toArray(fields)); >+ fEventTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields)); > } > } > >@@ -108,8 +107,8 @@ > TmfEvent event = new TmfEvent( > new TmfTimestamp(ts, (byte) -3, 0), // millisecs > new TmfEventSource(source), >- new TmfEventType(type, fFormats[typeIndex]), >- new TmfEventContent(content, fFormats[typeIndex]), >+ fEventTypes[typeIndex], >+ new TmfEventContent(fEventTypes[typeIndex], content), > new TmfEventReference(name)); > return event; > } catch (EOFException e) { >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java (working copy) >@@ -28,10 +28,11 @@ > // ======================================================================== > > @Test >- public void testEmptyConstructor() { >- TmfEventType type = new TmfEventType("", null); >- assertEquals("getValue", "", type.getTypeId()); >- assertEquals("getFormat", null, type.getFormat()); >+ public void testDefaultConstructor() { >+ TmfEventType type = new TmfEventType(); >+ assertEquals("getTypeId", "Generic type", type.getTypeId()); >+ assertEquals("getNbFields", 1, type.getNbFields()); >+ assertEquals("getLabel", "Content", type.getLabel(0)); > } > > @Test >@@ -36,10 +37,22 @@ > > @Test > public void testNormalConstructor() { >- TmfEventType type = new TmfEventType("Type", new TmfEventFormat(new String[] { "field1", "field2" })); >- assertEquals("getValue", "Type", type.getTypeId()); >- assertEquals("getFormat", "field1", type.getFormat().getLabels()[0]); >- assertEquals("getFormat", "field2", type.getFormat().getLabels()[1]); >+ TmfEventType type = new TmfEventType("MyType", new String[] { "Field1", "Field2" }); >+ assertEquals("getTypeId", "MyType", type.getTypeId()); >+ assertEquals("getNbFields", 2, type.getNbFields()); >+ assertEquals("getLabel", "Field1", type.getLabel(0)); >+ assertEquals("getLabel", "Field2", type.getLabel(1)); >+ } >+ >+ @Test >+ public void testCopyConstructor() { >+ TmfEventType other = new TmfEventType("MyType", new String[] { "Field1", "Field2" }); >+ TmfEventType type = new TmfEventType(other); >+ >+ assertEquals("getTypeId", "MyType", type.getTypeId()); >+ assertEquals("getNbFields", 2, type.getNbFields()); >+ assertEquals("getLabel", "Field1", type.getLabel(0)); >+ assertEquals("getLabel", "Field2", type.getLabel(1)); > } > > } >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java (working copy) >@@ -1,87 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2009 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 >- *******************************************************************************/ >- >-package org.eclipse.linuxtools.tmf.event; >- >-import static org.junit.Assert.assertEquals; >- >-import org.junit.Test; >- >-/** >- * <b><u>TmfEventFormatTest</u></b> >- * <p> >- * JUnit test suite for the TmfEventFormat class. >- */ >-public class TmfEventFormatTest { >- >- // ======================================================================== >- // Constructors >- // ======================================================================== >- >- @Test >- public void testBasicTmfEventFormat() { >- TmfEventFormat format = new TmfEventFormat(); >- assertEquals("getLabels", 1, format.getLabels().length); >- assertEquals("getValue", "Content", format.getLabels()[0]); >- } >- >- @Test >- public void testEmptyConstructor() { >- TmfEventFormat format = new TmfEventFormat(new String[] {}); >- assertEquals("getLabels", 0, format.getLabels().length); >- } >- >- @Test >- public void testNormalConstructor() { >- TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2", "field3" }); >- assertEquals("getLabels", 3, format.getLabels().length); >- assertEquals("getLabels", "field1", format.getLabels()[0]); >- assertEquals("getLabels", "field2", format.getLabels()[1]); >- assertEquals("getLabels", "field3", format.getLabels()[2]); >- } >- >- @Test >- public void testExtendedConstructor() { >- TmfEventFormatStub format = new TmfEventFormatStub(); >- assertEquals("getLabels", 5, format.getLabels().length); >- assertEquals("getLabels", "Field1", format.getLabels()[0]); >- assertEquals("getLabels", "Field2", format.getLabels()[1]); >- assertEquals("getLabels", "Field3", format.getLabels()[2]); >- assertEquals("getLabels", "Field4", format.getLabels()[3]); >- assertEquals("getLabels", "Field5", format.getLabels()[4]); >- } >- >- // ======================================================================== >- // parse >- // ======================================================================== >- >- @Test >- public void testBasicParse() { >- TmfEventFormat format = new TmfEventFormat(); >- TmfEventField[] content = format.parse(new TmfTimestamp()); >- assertEquals("length", 1, content.length); >- assertEquals("getValue", "[TmfTimestamp:0,0,0]", content[0].toString()); >- } >- >- @Test >- public void testExtendedParse() { >- TmfEventFormatStub format = new TmfEventFormatStub(); >- TmfEventField[] content = format.parse(new TmfTimestamp()); >- assertEquals("length", 5, content.length); >- assertEquals("getValue", "1", content[0].toString()); >- assertEquals("getValue", "-10", content[1].toString()); >- assertEquals("getValue", "true", content[2].toString()); >- assertEquals("getValue", "some string", content[3].toString()); >- assertEquals("getValue", "[TmfTimestamp:1,2,3]", content[4].toString()); >- } >- >-} >Index: src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java (working copy) >@@ -31,9 +31,8 @@ > public void testTmfTraceEvent() throws Exception { > TmfTimestamp timestamp = new TmfTimestamp(12345, (byte) 2, 5); > TmfEventSource source = new TmfEventSource("Source"); >- TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2" }); >- TmfEventType type = new TmfEventType("Type", format); >- TmfEventContent content = new TmfEventContent("Some content", format); >+ TmfEventType type = new TmfEventTypeStub(); >+ TmfEventContent content = new TmfEventContentStub(); > TmfEventReference reference = new TmfEventReference("Reference"); > > // Create the trace event >@@ -52,14 +51,14 @@ > > // Check the event type > TmfEventType evType = event.getType(); >- assertEquals("getValue", "Type", evType.getTypeId()); >- assertEquals("getFormat", "field1", evType.getFormat().getLabels()[0]); >- assertEquals("getFormat", "field2", evType.getFormat().getLabels()[1]); >+ assertEquals("getValue", "TmfEventTypeStub", evType.getTypeId()); >+ assertEquals("getFormat", "Field1", evType.getLabels()[0]); >+ assertEquals("getFormat", "Field2", evType.getLabels()[1]); > > // Check the event content > TmfEventContent evContent = event.getContent(); >- assertEquals("getField", 1, evContent.getFields().length); >- assertEquals("getField", "Some content", evContent.getField(0).toString()); >+ assertEquals("getField", 5, content.getFields().length); >+ assertEquals("getField", "some string", ((TmfEventField) evContent.getField(3)).getValue()); > > // Check the event reference > TmfEventReference evRef = event.getReference(); >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java (working copy) >@@ -29,9 +29,8 @@ > > @Test > public void testTmfEventContent() { >- TmfEventContent content = new TmfEventContent("Some content", new TmfEventFormat()); >- assertEquals("getFormat", 1, content.getFormat().getLabels().length); >- assertEquals("getLabels", "Content", content.getFormat().getLabels()[0]); >+ TmfEventContent content = new TmfEventContent(new TmfEventType(), "Some content"); >+ assertEquals("Nb labels", 1, content.getType().getLabels().length); > assertEquals("getContent", "Some content", content.getContent()); > } > >@@ -41,9 +40,9 @@ > > @Test > public void testBasicGetField() { >- TmfEventContent content = new TmfEventContent("Some content", new TmfEventFormat()); >+ TmfEventContent content = new TmfEventContent(new TmfEventType(), "Some content"); > assertEquals("getField", 1, content.getFields().length); >- assertEquals("getField", "Some content", content.getField(0).toString()); >+ assertEquals("getField", "Some content", content.getField(0)); > } > > @Test >@@ -48,13 +47,13 @@ > > @Test > public void testExtendedGetField() { >- TmfEventContent content = new TmfEventContent("", new TmfEventFormatStub()); >+ TmfEventContent content = new TmfEventContentStub(); > assertEquals("getField", 5, content.getFields().length); >- assertEquals("getField", "1", content.getField(0).toString()); >- assertEquals("getField", "-10", content.getField(1).toString()); >- assertEquals("getField", "true", content.getField(2).toString()); >- assertEquals("getField", "some string", content.getField(3).toString()); >- assertEquals("getField", "[TmfTimestamp:1,2,3]", content.getField(4).toString()); >+ assertEquals("getField", 1, ((TmfEventField) content.getField(0)).getValue()); >+ assertEquals("getField", -10, ((TmfEventField) content.getField(1)).getValue()); >+ assertEquals("getField", true, ((TmfEventField) content.getField(2)).getValue()); >+ assertEquals("getField", "some string", ((TmfEventField) content.getField(3)).getValue()); >+ assertEquals("getField", "[TmfTimestamp:1,2,3]", ((TmfEventField) content.getField(4)).getValue().toString()); > } > > } >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java (working copy) >@@ -12,7 +12,7 @@ > > package org.eclipse.linuxtools.tmf.event; > >-import static org.junit.Assert.*; >+import static org.junit.Assert.assertEquals; > > import org.junit.Test; > >@@ -31,9 +31,8 @@ > public void testTmfEvent() { > TmfTimestamp timestamp = new TmfTimestamp(12345, (byte) 2, 5); > TmfEventSource source = new TmfEventSource("Source"); >- TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2" }); >- TmfEventType type = new TmfEventType("Type", format); >- TmfEventContent content = new TmfEventContent("Some content", format); >+ TmfEventType type = new TmfEventTypeStub(); >+ TmfEventContent content = new TmfEventContentStub(); > TmfEventReference reference = new TmfEventReference("Reference"); > > // Create the event >@@ -57,14 +56,14 @@ > > // Check the event type > TmfEventType tp = event.getType(); >- assertEquals("getValue", "Type", tp.getTypeId()); >- assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]); >- assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]); >+ assertEquals("getValue", "TmfEventTypeStub", tp.getTypeId()); >+ assertEquals("getLabels", "Field1", tp.getLabels()[0]); >+ assertEquals("getLabels", "Field2", tp.getLabels()[1]); > > // Check the event content > TmfEventContent cnt = event.getContent(); >- assertEquals("getField", 1, cnt.getFields().length); >- assertEquals("getField", "Some content", cnt.getField(0).toString()); >+ assertEquals("getField", 5, cnt.getFields().length); >+ assertEquals("getField", "some string", ((TmfEventField) cnt.getField(3)).getValue()); > > // Check the event reference > TmfEventReference ref = event.getReference(); >@@ -71,49 +70,48 @@ > assertEquals("getValue", "Reference", ref.getValue()); > } > >- @Test >- public void testTmfEvent2() { >- TmfTimestamp original = new TmfTimestamp(12345, (byte) 2, 5); >- TmfTimestamp effective = new TmfTimestamp(12350, (byte) 2, 5); >- TmfEventSource source = new TmfEventSource("Source"); >- TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2" }); >- TmfEventType type = new TmfEventType("Type", format); >- TmfEventContent content = new TmfEventContent("Some content", format); >- TmfEventReference reference = new TmfEventReference("Reference"); >- >- // Create the event >- TmfEvent event = new TmfEvent(original, effective, source, type, content, reference); >- >- // Check the event timestamp >- TmfTimestamp ts = event.getTimestamp(); >- assertEquals("getValue", 12350, ts.getValue()); >- assertEquals("getscale", 2, ts.getScale()); >- assertEquals("getPrecision", 5, ts.getPrecision()); >- >- // Check the original event timestamp >- ts = event.getOriginalTimestamp(); >- assertEquals("getValue", 12345, ts.getValue()); >- assertEquals("getscale", 2, ts.getScale()); >- assertEquals("getPrecision", 5, ts.getPrecision()); >- >- // Check the event source >- TmfEventSource src = event.getSource(); >- assertEquals("getValue", "Source", src.getSourceId()); >- >- // Check the event type >- TmfEventType tp = event.getType(); >- assertEquals("getValue", "Type", tp.getTypeId()); >- assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]); >- assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]); >- >- // Check the event content >- TmfEventContent cnt = event.getContent(); >- assertEquals("getField", 1, cnt.getFields().length); >- assertEquals("getField", "Some content", cnt.getField(0).toString()); >- >- // Check the event reference >- TmfEventReference ref = event.getReference(); >- assertEquals("getValue", "Reference", ref.getValue()); >- } >+// @Test >+// public void testTmfEvent2() { >+// TmfTimestamp original = new TmfTimestamp(12345, (byte) 2, 5); >+// TmfTimestamp effective = new TmfTimestamp(12350, (byte) 2, 5); >+// TmfEventSource source = new TmfEventSource("Source"); >+// TmfEventType type = new TmfEventTypeStub(); >+// TmfEventContent content = new TmfEventContentStub(); >+// TmfEventReference reference = new TmfEventReference("Reference"); >+// >+// // Create the event >+// TmfEvent event = new TmfEvent(original, effective, source, type, content, reference); >+// >+// // Check the event timestamp >+// TmfTimestamp ts = event.getTimestamp(); >+// assertEquals("getValue", 12350, ts.getValue()); >+// assertEquals("getscale", 2, ts.getScale()); >+// assertEquals("getPrecision", 5, ts.getPrecision()); >+// >+// // Check the original event timestamp >+// ts = event.getOriginalTimestamp(); >+// assertEquals("getValue", 12345, ts.getValue()); >+// assertEquals("getscale", 2, ts.getScale()); >+// assertEquals("getPrecision", 5, ts.getPrecision()); >+// >+// // Check the event source >+// TmfEventSource src = event.getSource(); >+// assertEquals("getValue", "Source", src.getSourceId()); >+// >+// // Check the event type >+// TmfEventType tp = event.getType(); >+// assertEquals("getValue", "TmfEventTypeStub", tp.getTypeId()); >+// assertEquals("getLabels", "field1", tp.getLabels()[0]); >+// assertEquals("getLabels", "field2", tp.getLabels()[1]); >+// >+// // Check the event content >+// TmfEventContent cnt = event.getContent(); >+// assertEquals("getField", 1, cnt.getFields().length); >+// assertEquals("getField", "Some content", cnt.getField(0).toString()); >+// >+// // Check the event reference >+// TmfEventReference ref = event.getReference(); >+// assertEquals("getValue", "Reference", ref.getValue()); >+// } > > } >Index: src/org/eclipse/linuxtools/tmf/event/AllEventTests.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/AllEventTests.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/AllEventTests.java (working copy) >@@ -20,7 +20,6 @@ > TmfTimestampTest.class, > TmfTimeRangeTest.class, > TmfEventTypeTest.class, >- TmfEventFormatTest.class, > TmfEventContentTest.class, > TmfEventTest.class, > TmfTraceEventTest.class >#P org.eclipse.linuxtools.tmf >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventType.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventType.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventType.java (working copy) >@@ -23,10 +23,11 @@ > // Attributes > // ======================================================================== > >- private final String fTypeId; >- private final TmfEventFormat fFormat; >+ private final String fTypeId; >+ private final String[] fFieldLabels; >+ private final int fNbFields; > >- // ======================================================================== >+ // ======================================================================== > // Constructors > // ======================================================================== > >@@ -31,12 +32,29 @@ > // ======================================================================== > > /** >+ * >+ */ >+ public TmfEventType() { >+ this("Generic type", new String[] { "Content" }); >+ } >+ >+ /** > * @param type > * @param format > */ >- public TmfEventType(String typeID, TmfEventFormat format) { >- fTypeId = typeID; >- fFormat = format; >+ public TmfEventType(String typeId, String[] labels) { >+ fTypeId = typeId; >+ fFieldLabels = labels; >+ fNbFields = fFieldLabels.length; >+ } >+ >+ /** >+ * @param other >+ */ >+ public TmfEventType(TmfEventType other) { >+ fTypeId = other.fTypeId; >+ fFieldLabels = other.fFieldLabels; >+ fNbFields = other.fNbFields; > } > > // ======================================================================== >@@ -50,12 +68,28 @@ > return fTypeId; > } > >- /** >- * @return >- */ >- public TmfEventFormat getFormat() { >- return fFormat; >- } >+ /** >+ * @return >+ */ >+ public int getNbFields() { >+ return fNbFields; >+ } >+ >+ /** >+ * @return >+ */ >+ public String[] getLabels() { >+ return fFieldLabels; >+ } >+ >+ /** >+ * @return >+ */ >+ public String getLabel(int i) { >+ if (i >= 0 && i < fNbFields) >+ return fFieldLabels[i]; >+ return null; >+ } > > // ======================================================================== > // Operators >@@ -63,7 +97,7 @@ > > @Override > public String toString() { >- return fTypeId.toString(); >+ return "[type:" + fTypeId + "]"; > } > >-} >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventField.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventField.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventField.java (working copy) >@@ -16,6 +16,8 @@ > * <b><u>TmfEventField</u></b> > * <p> > * A basic event field. >+ * >+ * TODO: Add support for field hierarchy. > */ > public class TmfEventField { > >@@ -23,7 +25,9 @@ > // Attributes > // ======================================================================== > >- private final Object fValue; >+ private final TmfEventContent fParent; >+ private final String fId; >+ private Object fValue; > > // ======================================================================== > // Constructors >@@ -30,12 +34,32 @@ > // ======================================================================== > > /** >+ * @param parent >+ * @param id > * @param value > */ >- public TmfEventField(Object value) { >+ public TmfEventField(TmfEventContent parent, String id, Object value) { >+ fParent = parent; >+ fId = id; > fValue = value; > } > >+ /** >+ * @param other >+ */ >+ public TmfEventField(TmfEventField other) { >+ fParent = other.fParent; >+ fId = other.fId; >+ fValue = other.fValue; >+ } >+ >+ @SuppressWarnings("unused") >+ private TmfEventField() { >+ fParent = null; >+ fId = null; >+ fValue = null; >+ } >+ > // ======================================================================== > // Accessors > // ======================================================================== >@@ -43,6 +67,20 @@ > /** > * @return > */ >+ public TmfEventContent getContent() { >+ return fParent; >+ } >+ >+ /** >+ * @return >+ */ >+ public String getId() { >+ return fId; >+ } >+ >+ /** >+ * @return >+ */ > public Object getValue() { > return fValue; > } >@@ -47,6 +85,13 @@ > return fValue; > } > >+ /** >+ * @return >+ */ >+ protected void setValue(Object value) { >+ fValue = value; >+ } >+ > // ======================================================================== > // Operators > // ======================================================================== >@@ -56,7 +101,7 @@ > */ > @Override > public String toString() { >- return fValue.toString(); >+ return "[field:" + fId + ",value:" + fValue.toString() + "]"; > } > >-} >+} >\ No newline at end of file >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java (working copy) >@@ -12,6 +12,9 @@ > > package org.eclipse.linuxtools.tmf.event; > >+import java.util.HashMap; >+import java.util.Map; >+ > /** > * <b><u>TmfEventContent</u></b> > * <p> >@@ -23,10 +26,12 @@ > // Attributes > // ======================================================================== > >- private final TmfEventFormat fFormat; >- private final String fContent; >- private final int fNbFields; >- private TmfEventField[] fFields = null; >+ protected TmfEvent fParentEvent = null; >+ protected TmfEventType fEventType = null; >+ protected Object fRawContent = null; >+ >+ // The content fields >+ protected Map<String, Object> fFields = null; > > // ======================================================================== > // Constructors >@@ -33,15 +38,28 @@ > // ======================================================================== > > /** >+ * @param parent >+ * @param type > * @param content >- * @param format > */ >- public TmfEventContent(Object content, TmfEventFormat format) { >- fFormat = format; >- fContent = content.toString(); >- fNbFields = fFormat.getLabels().length; >+ public TmfEventContent(TmfEventType type, Object content) { >+ fEventType = type; >+ fRawContent = content; > } > >+ /** >+ * @param other >+ */ >+ public TmfEventContent(TmfEventContent other) { >+ fParentEvent = other.fParentEvent; >+ fEventType = other.fEventType; >+ fRawContent = other.fRawContent; >+ } >+ >+ @SuppressWarnings("unused") >+ private TmfEventContent() { >+ } >+ > // ======================================================================== > // Accessors > // ======================================================================== >@@ -47,34 +65,49 @@ > // ======================================================================== > > /** >- * @return >+ * @param event > */ >- public String getContent() { >- return fContent; >+ public void setEvent(TmfEvent event) { >+ fParentEvent = event; > } > > /** >- * @return >+ * @return the parent (containing) event > */ >- public TmfEventFormat getFormat() { >- return fFormat; >+ public TmfEvent getEvent() { >+ return fParentEvent; > } > >- /** >- * @return >- */ >- public int getNbFields() { >- return fNbFields; >- } >+ /** >+ * @return the event type >+ */ >+ public TmfEventType getType() { >+ return fEventType; >+ } > > /** >- * @return >+ * @return the raw content >+ */ >+ public Object getContent() { >+ return fRawContent; >+ } >+ >+ /** >+ * Returns the list of fields in the same order as TmfEventType.getLabels() >+ * >+ * @return the ordered set of fields (optional fields might be null) > */ >- public TmfEventField[] getFields() { >- if (fFields == null) { >- fFields = fFormat.parse(fContent); >+ public Object[] getFields() { >+ if (fFields == null) { >+ fFields = parseContent(); >+ } >+ String[] labels = fEventType.getLabels(); >+ int nbFields = labels.length; >+ Object[] fields = new Object[nbFields]; >+ for (int i = 0; i < nbFields; i++) { >+ fields[i] = fFields.get(labels[i]); > } >- return fFields; >+ return fields; > } > > /** >@@ -81,19 +114,49 @@ > * @param id > * @return > */ >- public TmfEventField getField(int id) { >- assert id >= 0 && id < fNbFields; >- if (fFields == null) { >- fFields = fFormat.parse(fContent); >- } >- return fFields[id]; >+ public Object getField(String id) { >+ if (fFields == null) { >+ fFields = parseContent(); >+ } >+ return fFields.get(id); > } > > /** >+ * @param id > * @return > */ >- public void setFields(TmfEventField[] fields) { >- fFields = fields; >+ public Object getField(int n) { >+ return getField(fEventType.getLabels()[n]); >+ } >+ >+ // ======================================================================== >+ // Operators >+ // ======================================================================== >+ >+ /** >+ * By default, the content is a single field. >+ */ >+ protected Map<String, Object> parseContent() { >+ Map<String, Object> result = new HashMap<String, Object>(); >+ String key = fEventType.getLabel(0); >+ if (key == null) key = "Content"; >+ result.put(fEventType.getLabel(0), fRawContent); >+ return result; > } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#toString() >+ */ >+ @Override >+ public String toString() { >+ Object[] fields = getFields(); >+ String result = "[content:"; >+ for (int i = 0; i < fields.length; i++) { >+ result += fields[i].toString(); >+ } >+ result += "]"; >+ >+ return result; >+ } > > } >Index: src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java >=================================================================== >--- src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java (revision 23661) >+++ src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java (working copy) >@@ -1,72 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2009 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 >- *******************************************************************************/ >- >-package org.eclipse.linuxtools.tmf.event; >- >-/** >- * <b><u>TmfEventFormat</u></b> >- * <p> >- * The basic event content format. >- */ >-public class TmfEventFormat implements ITmfContentParser { >- >- // ======================================================================== >- // Attributes >- // ======================================================================== >- >- private final String[] fLabels; >- >- // ======================================================================== >- // Constructors >- // ======================================================================== >- >- /** >- * >- */ >- public TmfEventFormat() { >- this(new String[] { "Content" }); >- } >- >- /** >- * @param labels >- */ >- public TmfEventFormat(String[] labels) { >- fLabels = labels; >- } >- >- // ======================================================================== >- // Accessors >- // ======================================================================== >- >- /** >- * @return >- */ >- public String[] getLabels() { >- return fLabels; >- } >- >- // ======================================================================== >- // Operators >- // ======================================================================== >- >- /** >- * The default content parser: returns a single field containing the whole >- * content. >- * >- * @param content >- * @return >- */ >- public TmfEventField[] parse(Object content) { >- return new TmfEventField[] { new TmfEventField(content.toString()) }; >- } >- >-}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
fchouinard
:
iplog-
Actions:
View
|
Diff
Attachments on
bug 287562
:
145578
|
151266
|
151267
| 151666