Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 287562 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/linuxtools/tmf/ui/views/TmfEventsView.java (-2 / +2 lines)
Lines 215-221 Link Here
215
				event.getSource().getSourceId().toString(),
215
				event.getSource().getSourceId().toString(),
216
				event.getType().getTypeId().toString(),
216
				event.getType().getTypeId().toString(),
217
				event.getReference().getValue().toString(),
217
				event.getReference().getValue().toString(),
218
				event.getContent().getContent()
218
				event.getContent().toString()
219
            };
219
            };
220
		}
220
		}
221
		return fields;
221
		return fields;
Lines 292-295 Link Here
292
    	}
292
    	}
293
    }
293
    }
294
294
295
}
295
}
(-)stubs/org/eclipse/linuxtools/tmf/event/TmfEventTypeStub.java (-33 / +20 lines)
Lines 13-59 Link Here
13
package org.eclipse.linuxtools.tmf.event;
13
package org.eclipse.linuxtools.tmf.event;
14
14
15
/**
15
/**
16
 * <b><u>TmfEventFormatStub</u></b>
16
 * <b><u>TmfEventTypeStub</u></b>
17
 * <p>
17
 * <p>
18
 * TODO: Implement me. Please.
18
 * TODO: Implement me. Please.
19
 */
19
 */
20
public class TmfEventFormatStub extends TmfEventFormat {
20
public class TmfEventTypeStub extends TmfEventType {
21
21
22
    // ========================================================================
22
	// ========================================================================
23
    // Attributes
23
	// Attributes
24
    // ========================================================================
24
	// ========================================================================
25
25
26
    // ========================================================================
26
	// ========================================================================
27
    // Constructors
27
	// Constructors
28
    // ========================================================================
28
	// ========================================================================
29
29
30
   public TmfEventFormatStub() {
30
	public TmfEventTypeStub() {
31
        super(new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" });
31
		super("TmfEventTypeStub", new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" });
32
    }
32
	}
33
33
34
   // ========================================================================
34
	// ========================================================================
35
   // Accessors
35
	// Accessors
36
   // ========================================================================
36
	// ========================================================================
37
37
38
   // ========================================================================
38
	// ========================================================================
39
   // Operators
39
	// Operators
40
   // ========================================================================
40
	// ========================================================================
41
41
42
    /* (non-Javadoc)
42
	// ========================================================================
43
     * @see org.eclipse.linuxtools.tmf.event.TmfEventFormat#parse(java.lang.Object)
43
	// Helper functions
44
     */
44
	// ========================================================================
45
    @Override
46
    public TmfEventField[] parse(Object content) {
47
        TmfEventField field1 = new TmfEventField(1);
48
        TmfEventField field2 = new TmfEventField(-10);
49
        TmfEventField field3 = new TmfEventField(true);
50
        TmfEventField field4 = new TmfEventField("some string");
51
        TmfEventField field5 = new TmfEventField(new TmfTimestamp(1, (byte) 2, 3));
52
        return new TmfEventField[] { field1, field2, field3, field4, field5 };
53
    }
54
55
    // ========================================================================
56
    // Helper functions
57
    // ========================================================================
58
45
59
}
46
}
(-)stubs/org/eclipse/linuxtools/tmf/event/TmfEventContentStub.java (+52 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Francois Chouinard - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.tmf.event;
14
15
import java.util.HashMap;
16
import java.util.Map;
17
18
/**
19
 * <b><u>TmfEventContentStub</u></b>
20
 * <p>
21
 * TODO: Implement me. Please.
22
 */
23
public class TmfEventContentStub extends TmfEventContent {
24
25
	public TmfEventContentStub() {
26
		super(new TmfEventTypeStub(), "DummyContent");
27
	}
28
29
	@Override
30
	protected Map<String, Object> parseContent() {
31
		Map<String, Object> result = new HashMap<String, Object>();
32
		String[] keys = fEventType.getLabels();
33
34
		TmfEventField field = new TmfEventField(this, keys[0], 1);
35
		result.put(keys[0], field);
36
		
37
		field = new TmfEventField(this, keys[1], -10);
38
		result.put(keys[1], field);
39
		
40
		field = new TmfEventField(this, keys[2], true);
41
		result.put(keys[2], field);
42
		
43
		field = new TmfEventField(this, keys[3], "some string");
44
		result.put(keys[3], field);
45
		
46
		field = new TmfEventField(this, keys[4], new TmfTimestamp(1, (byte) 2, 3));
47
		result.put(keys[4], field);
48
		
49
		return result;
50
	}
51
52
}
(-)stubs/org/eclipse/linuxtools/tmf/event/TmfEventFormatStub.java (-59 lines)
Lines 1-59 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Francois Chouinard - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.tmf.event;
14
15
/**
16
 * <b><u>TmfEventFormatStub</u></b>
17
 * <p>
18
 * TODO: Implement me. Please.
19
 */
20
public class TmfEventFormatStub extends TmfEventFormat {
21
22
    // ========================================================================
23
    // Attributes
24
    // ========================================================================
25
26
    // ========================================================================
27
    // Constructors
28
    // ========================================================================
29
30
   public TmfEventFormatStub() {
31
        super(new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" });
32
    }
33
34
   // ========================================================================
35
   // Accessors
36
   // ========================================================================
37
38
   // ========================================================================
39
   // Operators
40
   // ========================================================================
41
42
    /* (non-Javadoc)
43
     * @see org.eclipse.linuxtools.tmf.event.TmfEventFormat#parse(java.lang.Object)
44
     */
45
    @Override
46
    public TmfEventField[] parse(Object content) {
47
        TmfEventField field1 = new TmfEventField(1);
48
        TmfEventField field2 = new TmfEventField(-10);
49
        TmfEventField field3 = new TmfEventField(true);
50
        TmfEventField field4 = new TmfEventField("some string");
51
        TmfEventField field5 = new TmfEventField(new TmfTimestamp(1, (byte) 2, 3));
52
        return new TmfEventField[] { field1, field2, field3, field4, field5 };
53
    }
54
55
    // ========================================================================
56
    // Helper functions
57
    // ========================================================================
58
59
}
(-)stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java (-8 / +7 lines)
Lines 19-25 Link Here
19
19
20
import org.eclipse.linuxtools.tmf.event.TmfEvent;
20
import org.eclipse.linuxtools.tmf.event.TmfEvent;
21
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
21
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
22
import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
23
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
22
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
24
import org.eclipse.linuxtools.tmf.event.TmfEventSource;
23
import org.eclipse.linuxtools.tmf.event.TmfEventSource;
25
import org.eclipse.linuxtools.tmf.event.TmfEventType;
24
import org.eclipse.linuxtools.tmf.event.TmfEventType;
Lines 36-43 Link Here
36
    // Attributes
35
    // Attributes
37
    // ========================================================================
36
    // ========================================================================
38
37
39
	private final int NB_FORMATS = 10;
38
	private final int NB_TYPES = 10;
40
    private final TmfEventFormat[] fFormats;
39
    private final TmfEventType[] fEventTypes;
41
40
42
    // ========================================================================
41
    // ========================================================================
43
    // Constructors
42
    // Constructors
Lines 44-51 Link Here
44
    // ========================================================================
43
    // ========================================================================
45
44
46
    public TmfEventParserStub() {
45
    public TmfEventParserStub() {
47
    	fFormats = new TmfEventFormat[NB_FORMATS];
46
    	fEventTypes = new TmfEventType[NB_TYPES];
48
    	for (int i = 0; i < NB_FORMATS; i++) {
47
    	for (int i = 0; i < NB_TYPES; i++) {
49
    		Vector<String> format = new Vector<String>();
48
    		Vector<String> format = new Vector<String>();
50
    		for (int j = 1; j <= i; j++) {
49
    		for (int j = 1; j <= i; j++) {
51
    			format.add(new String("Fmt-" + i + "-Fld-" + j));
50
    			format.add(new String("Fmt-" + i + "-Fld-" + j));
Lines 51-57 Link Here
51
    			format.add(new String("Fmt-" + i + "-Fld-" + j));
50
    			format.add(new String("Fmt-" + i + "-Fld-" + j));
52
    		}
51
    		}
53
    		String[] fields = new String[i];
52
    		String[] fields = new String[i];
54
    		fFormats[i] = new TmfEventFormat(format.toArray(fields));
53
    		fEventTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields));
55
    	}
54
    	}
56
    }
55
    }
57
56
Lines 108-115 Link Here
108
        		TmfEvent event = new TmfEvent(
107
        		TmfEvent event = new TmfEvent(
109
        				new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
108
        				new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
110
        				new TmfEventSource(source),
109
        				new TmfEventSource(source),
111
        				new TmfEventType(type, fFormats[typeIndex]),
110
        				fEventTypes[typeIndex],
112
        				new TmfEventContent(content, fFormats[typeIndex]),
111
        				new TmfEventContent(fEventTypes[typeIndex], content),
113
        				new TmfEventReference(name));
112
        				new TmfEventReference(name));
114
        		return event;
113
        		return event;
115
        	} catch (EOFException e) {
114
        	} catch (EOFException e) {
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventTypeTest.java (-8 / +21 lines)
Lines 28-37 Link Here
28
    // ========================================================================
28
    // ========================================================================
29
29
30
    @Test
30
    @Test
31
    public void testEmptyConstructor() {
31
    public void testDefaultConstructor() {
32
        TmfEventType type = new TmfEventType("", null);
32
        TmfEventType type = new TmfEventType();
33
        assertEquals("getValue", "", type.getTypeId());
33
        assertEquals("getTypeId",  "Generic type", type.getTypeId());
34
        assertEquals("getFormat", null, type.getFormat());
34
        assertEquals("getNbFields", 1,             type.getNbFields());
35
        assertEquals("getLabel",   "Content",      type.getLabel(0));
35
   }
36
   }
36
37
37
    @Test
38
    @Test
Lines 36-45 Link Here
36
37
37
    @Test
38
    @Test
38
    public void testNormalConstructor() {
39
    public void testNormalConstructor() {
39
        TmfEventType type = new TmfEventType("Type", new TmfEventFormat(new String[] { "field1", "field2" }));
40
        TmfEventType type = new TmfEventType("MyType", new String[] { "Field1", "Field2" });
40
        assertEquals("getValue", "Type", type.getTypeId());
41
        assertEquals("getTypeId",  "MyType", type.getTypeId());
41
        assertEquals("getFormat", "field1", type.getFormat().getLabels()[0]);
42
        assertEquals("getNbFields", 2,       type.getNbFields());
42
        assertEquals("getFormat", "field2", type.getFormat().getLabels()[1]);
43
        assertEquals("getLabel",   "Field1", type.getLabel(0));
44
        assertEquals("getLabel",   "Field2", type.getLabel(1));
45
   }
46
47
    @Test
48
    public void testCopyConstructor() {
49
        TmfEventType other = new TmfEventType("MyType", new String[] { "Field1", "Field2" });
50
        TmfEventType type  = new TmfEventType(other);
51
52
        assertEquals("getTypeId",  "MyType", type.getTypeId());
53
        assertEquals("getNbFields", 2,       type.getNbFields());
54
        assertEquals("getLabel",   "Field1", type.getLabel(0));
55
        assertEquals("getLabel",   "Field2", type.getLabel(1));
43
   }
56
   }
44
57
45
}
58
}
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventFormatTest.java (-87 lines)
Lines 1-87 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Francois Chouinard - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.tmf.event;
14
15
import static org.junit.Assert.assertEquals;
16
17
import org.junit.Test;
18
19
/**
20
 * <b><u>TmfEventFormatTest</u></b>
21
 * <p>
22
 * JUnit test suite for the TmfEventFormat class.
23
 */
24
public class TmfEventFormatTest {
25
26
    // ========================================================================
27
    // Constructors
28
    // ========================================================================
29
30
    @Test
31
    public void testBasicTmfEventFormat() {
32
        TmfEventFormat format = new TmfEventFormat();
33
        assertEquals("getLabels", 1, format.getLabels().length);
34
        assertEquals("getValue", "Content", format.getLabels()[0]);
35
    }
36
37
    @Test
38
    public void testEmptyConstructor() {
39
        TmfEventFormat format = new TmfEventFormat(new String[] {});
40
        assertEquals("getLabels", 0, format.getLabels().length);
41
    }
42
43
    @Test
44
    public void testNormalConstructor() {
45
        TmfEventFormat format = new TmfEventFormat(new String[] { "field1", "field2", "field3" });
46
        assertEquals("getLabels", 3, format.getLabels().length);
47
        assertEquals("getLabels", "field1", format.getLabels()[0]);
48
        assertEquals("getLabels", "field2", format.getLabels()[1]);
49
        assertEquals("getLabels", "field3", format.getLabels()[2]);
50
    }
51
52
    @Test
53
    public void testExtendedConstructor() {
54
        TmfEventFormatStub format = new TmfEventFormatStub();
55
        assertEquals("getLabels", 5, format.getLabels().length);
56
        assertEquals("getLabels", "Field1", format.getLabels()[0]);
57
        assertEquals("getLabels", "Field2", format.getLabels()[1]);
58
        assertEquals("getLabels", "Field3", format.getLabels()[2]);
59
        assertEquals("getLabels", "Field4", format.getLabels()[3]);
60
        assertEquals("getLabels", "Field5", format.getLabels()[4]);
61
    }
62
63
    // ========================================================================
64
    // parse
65
    // ========================================================================
66
67
    @Test
68
    public void testBasicParse() {
69
        TmfEventFormat format = new TmfEventFormat();
70
        TmfEventField[] content = format.parse(new TmfTimestamp());
71
        assertEquals("length", 1, content.length);
72
        assertEquals("getValue", "[TmfTimestamp:0,0,0]", content[0].toString());
73
    }
74
75
    @Test
76
    public void testExtendedParse() {
77
        TmfEventFormatStub format = new TmfEventFormatStub();
78
        TmfEventField[] content = format.parse(new TmfTimestamp());
79
        assertEquals("length", 5, content.length);
80
        assertEquals("getValue", "1",                    content[0].toString());
81
        assertEquals("getValue", "-10",                  content[1].toString());
82
        assertEquals("getValue", "true",                 content[2].toString());
83
        assertEquals("getValue", "some string",          content[3].toString());
84
        assertEquals("getValue", "[TmfTimestamp:1,2,3]", content[4].toString());
85
    }
86
87
}
(-)src/org/eclipse/linuxtools/tmf/event/TmfTraceEventTest.java (-8 / +7 lines)
Lines 31-39 Link Here
31
    public void testTmfTraceEvent() throws Exception {
31
    public void testTmfTraceEvent() throws Exception {
32
        TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
32
        TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
33
        TmfEventSource    source    = new TmfEventSource("Source");
33
        TmfEventSource    source    = new TmfEventSource("Source");
34
        TmfEventFormat    format    = new TmfEventFormat(new String[] { "field1", "field2" });
34
        TmfEventType      type      = new TmfEventTypeStub();
35
        TmfEventType      type      = new TmfEventType("Type", format);
35
        TmfEventContent   content   = new TmfEventContentStub();
36
        TmfEventContent   content   = new TmfEventContent("Some content", format);
37
        TmfEventReference reference = new TmfEventReference("Reference");
36
        TmfEventReference reference = new TmfEventReference("Reference");
38
37
39
        // Create the trace event
38
        // Create the trace event
Lines 52-65 Link Here
52
51
53
        // Check the event type
52
        // Check the event type
54
        TmfEventType evType = event.getType();
53
        TmfEventType evType = event.getType();
55
        assertEquals("getValue", "Type", evType.getTypeId());
54
        assertEquals("getValue",  "TmfEventTypeStub", evType.getTypeId());
56
        assertEquals("getFormat", "field1", evType.getFormat().getLabels()[0]);
55
        assertEquals("getFormat", "Field1", evType.getLabels()[0]);
57
        assertEquals("getFormat", "field2", evType.getFormat().getLabels()[1]);
56
        assertEquals("getFormat", "Field2", evType.getLabels()[1]);
58
57
59
        // Check the event content
58
        // Check the event content
60
        TmfEventContent evContent = event.getContent();
59
        TmfEventContent evContent = event.getContent();
61
        assertEquals("getField", 1, evContent.getFields().length);
60
        assertEquals("getField", 5, content.getFields().length);
62
        assertEquals("getField", "Some content", evContent.getField(0).toString());
61
        assertEquals("getField", "some string", ((TmfEventField) evContent.getField(3)).getValue());
63
62
64
        // Check the event reference
63
        // Check the event reference
65
        TmfEventReference evRef = event.getReference();
64
        TmfEventReference evRef = event.getReference();
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java (-11 / +10 lines)
Lines 29-37 Link Here
29
29
30
	@Test
30
	@Test
31
	public void testTmfEventContent() {
31
	public void testTmfEventContent() {
32
		TmfEventContent content = new TmfEventContent("Some content", new TmfEventFormat());
32
		TmfEventContent content = new TmfEventContent(new TmfEventType(), "Some content");
33
		assertEquals("getFormat", 1, content.getFormat().getLabels().length);
33
		assertEquals("Nb labels", 1, content.getType().getLabels().length);
34
		assertEquals("getLabels", "Content", content.getFormat().getLabels()[0]);
35
		assertEquals("getContent", "Some content", content.getContent());
34
		assertEquals("getContent", "Some content", content.getContent());
36
	}
35
	}
37
36
Lines 41-49 Link Here
41
40
42
	@Test
41
	@Test
43
	public void testBasicGetField() {
42
	public void testBasicGetField() {
44
		TmfEventContent content = new TmfEventContent("Some content", new TmfEventFormat());
43
		TmfEventContent content = new TmfEventContent(new TmfEventType(), "Some content");
45
		assertEquals("getField", 1, content.getFields().length);
44
		assertEquals("getField", 1, content.getFields().length);
46
		assertEquals("getField", "Some content", content.getField(0).toString());
45
		assertEquals("getField", "Some content", content.getField(0));
47
	}
46
	}
48
47
49
	@Test
48
	@Test
Lines 48-60 Link Here
48
47
49
	@Test
48
	@Test
50
	public void testExtendedGetField() {
49
	public void testExtendedGetField() {
51
		TmfEventContent content = new TmfEventContent("", new TmfEventFormatStub());
50
		TmfEventContent content = new TmfEventContentStub();
52
		assertEquals("getField", 5, content.getFields().length);
51
		assertEquals("getField", 5, content.getFields().length);
53
		assertEquals("getField", "1", content.getField(0).toString());
52
		assertEquals("getField", 1,                      ((TmfEventField) content.getField(0)).getValue());
54
		assertEquals("getField", "-10", content.getField(1).toString());
53
		assertEquals("getField", -10,                    ((TmfEventField) content.getField(1)).getValue());
55
		assertEquals("getField", "true", content.getField(2).toString());
54
		assertEquals("getField", true,                   ((TmfEventField) content.getField(2)).getValue());
56
		assertEquals("getField", "some string", content.getField(3).toString());
55
		assertEquals("getField", "some string",          ((TmfEventField) content.getField(3)).getValue());
57
		assertEquals("getField", "[TmfTimestamp:1,2,3]", content.getField(4).toString());
56
		assertEquals("getField", "[TmfTimestamp:1,2,3]", ((TmfEventField) content.getField(4)).getValue().toString());
58
	}
57
	}
59
58
60
}
59
}
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java (-53 / +51 lines)
Lines 12-18 Link Here
12
12
13
package org.eclipse.linuxtools.tmf.event;
13
package org.eclipse.linuxtools.tmf.event;
14
14
15
import static org.junit.Assert.*;
15
import static org.junit.Assert.assertEquals;
16
16
17
import org.junit.Test;
17
import org.junit.Test;
18
18
Lines 31-39 Link Here
31
    public void testTmfEvent() {
31
    public void testTmfEvent() {
32
        TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
32
        TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
33
        TmfEventSource    source    = new TmfEventSource("Source");
33
        TmfEventSource    source    = new TmfEventSource("Source");
34
        TmfEventFormat    format    = new TmfEventFormat(new String[] { "field1", "field2" });
34
        TmfEventType      type      = new TmfEventTypeStub();
35
        TmfEventType      type      = new TmfEventType("Type", format);
35
        TmfEventContent   content   = new TmfEventContentStub();
36
        TmfEventContent   content   = new TmfEventContent("Some content", format);
37
        TmfEventReference reference = new TmfEventReference("Reference");
36
        TmfEventReference reference = new TmfEventReference("Reference");
38
37
39
        // Create the event
38
        // Create the event
Lines 57-70 Link Here
57
56
58
        // Check the event type
57
        // Check the event type
59
        TmfEventType tp = event.getType();
58
        TmfEventType tp = event.getType();
60
        assertEquals("getValue", "Type", tp.getTypeId());
59
        assertEquals("getValue",  "TmfEventTypeStub", tp.getTypeId());
61
        assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]);
60
        assertEquals("getLabels", "Field1", tp.getLabels()[0]);
62
        assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]);
61
        assertEquals("getLabels", "Field2", tp.getLabels()[1]);
63
62
64
        // Check the event content
63
        // Check the event content
65
        TmfEventContent cnt = event.getContent();
64
        TmfEventContent cnt = event.getContent();
66
        assertEquals("getField", 1, cnt.getFields().length);
65
        assertEquals("getField", 5, cnt.getFields().length);
67
        assertEquals("getField", "Some content", cnt.getField(0).toString());
66
        assertEquals("getField", "some string", ((TmfEventField) cnt.getField(3)).getValue());
68
67
69
        // Check the event reference
68
        // Check the event reference
70
        TmfEventReference ref = event.getReference();
69
        TmfEventReference ref = event.getReference();
Lines 71-119 Link Here
71
        assertEquals("getValue", "Reference", ref.getValue());
70
        assertEquals("getValue", "Reference", ref.getValue());
72
    }
71
    }
73
72
74
    @Test
73
//    @Test
75
    public void testTmfEvent2() {
74
//    public void testTmfEvent2() {
76
        TmfTimestamp      original  = new TmfTimestamp(12345, (byte) 2, 5);
75
//        TmfTimestamp      original  = new TmfTimestamp(12345, (byte) 2, 5);
77
        TmfTimestamp      effective = new TmfTimestamp(12350, (byte) 2, 5);
76
//        TmfTimestamp      effective = new TmfTimestamp(12350, (byte) 2, 5);
78
        TmfEventSource    source    = new TmfEventSource("Source");
77
//        TmfEventSource    source    = new TmfEventSource("Source");
79
        TmfEventFormat    format    = new TmfEventFormat(new String[] { "field1", "field2" });
78
//        TmfEventType      type      = new TmfEventTypeStub();
80
        TmfEventType      type      = new TmfEventType("Type", format);
79
//        TmfEventContent   content   = new TmfEventContentStub();
81
        TmfEventContent   content   = new TmfEventContent("Some content", format);
80
//        TmfEventReference reference = new TmfEventReference("Reference");
82
        TmfEventReference reference = new TmfEventReference("Reference");
81
//
83
82
//        // Create the event
84
        // Create the event
83
//        TmfEvent event = new TmfEvent(original, effective, source, type, content, reference);
85
        TmfEvent event = new TmfEvent(original, effective, source, type, content, reference);
84
//
86
85
//        // Check the event timestamp
87
        // Check the event timestamp
86
//        TmfTimestamp ts = event.getTimestamp();
88
        TmfTimestamp ts = event.getTimestamp();
87
//        assertEquals("getValue", 12350, ts.getValue());
89
        assertEquals("getValue", 12350, ts.getValue());
88
//        assertEquals("getscale",     2, ts.getScale());
90
        assertEquals("getscale",     2, ts.getScale());
89
//        assertEquals("getPrecision", 5, ts.getPrecision());
91
        assertEquals("getPrecision", 5, ts.getPrecision());
90
//
92
91
//        // Check the original event timestamp
93
        // Check the original event timestamp
92
//        ts = event.getOriginalTimestamp();
94
        ts = event.getOriginalTimestamp();
93
//        assertEquals("getValue", 12345, ts.getValue());
95
        assertEquals("getValue", 12345, ts.getValue());
94
//        assertEquals("getscale",     2, ts.getScale());
96
        assertEquals("getscale",     2, ts.getScale());
95
//        assertEquals("getPrecision", 5, ts.getPrecision());
97
        assertEquals("getPrecision", 5, ts.getPrecision());
96
//
98
97
//        // Check the event source
99
        // Check the event source
98
//        TmfEventSource src = event.getSource();
100
        TmfEventSource src = event.getSource();
99
//        assertEquals("getValue", "Source", src.getSourceId());
101
        assertEquals("getValue", "Source", src.getSourceId());
100
//
102
101
//        // Check the event type
103
        // Check the event type
102
//        TmfEventType tp = event.getType();
104
        TmfEventType tp = event.getType();
103
//        assertEquals("getValue",  "TmfEventTypeStub", tp.getTypeId());
105
        assertEquals("getValue", "Type", tp.getTypeId());
104
//        assertEquals("getLabels", "field1", tp.getLabels()[0]);
106
        assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]);
105
//        assertEquals("getLabels", "field2", tp.getLabels()[1]);
107
        assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]);
106
//
108
107
//        // Check the event content
109
        // Check the event content
108
//        TmfEventContent cnt = event.getContent();
110
        TmfEventContent cnt = event.getContent();
109
//        assertEquals("getField", 1, cnt.getFields().length);
111
        assertEquals("getField", 1, cnt.getFields().length);
110
//        assertEquals("getField", "Some content", cnt.getField(0).toString());
112
        assertEquals("getField", "Some content", cnt.getField(0).toString());
111
//
113
112
//        // Check the event reference
114
        // Check the event reference
113
//        TmfEventReference ref = event.getReference();
115
        TmfEventReference ref = event.getReference();
114
//        assertEquals("getValue", "Reference", ref.getValue());
116
        assertEquals("getValue", "Reference", ref.getValue());
115
//    }
117
    }
118
116
119
}
117
}
(-)src/org/eclipse/linuxtools/tmf/event/AllEventTests.java (-1 lines)
Lines 20-26 Link Here
20
    TmfTimestampTest.class,
20
    TmfTimestampTest.class,
21
    TmfTimeRangeTest.class,
21
    TmfTimeRangeTest.class,
22
    TmfEventTypeTest.class,
22
    TmfEventTypeTest.class,
23
    TmfEventFormatTest.class,
24
    TmfEventContentTest.class,
23
    TmfEventContentTest.class,
25
    TmfEventTest.class,
24
    TmfEventTest.class,
26
    TmfTraceEventTest.class
25
    TmfTraceEventTest.class
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventType.java (-14 / +48 lines)
Lines 23-32 Link Here
23
    // Attributes
23
    // Attributes
24
    // ========================================================================
24
    // ========================================================================
25
25
26
	private final String fTypeId;
26
	private final String   fTypeId;
27
    private final TmfEventFormat fFormat;
27
	private final String[] fFieldLabels;
28
	private final int      fNbFields;
28
29
29
    // ========================================================================
30
	// ========================================================================
30
    // Constructors
31
    // Constructors
31
    // ========================================================================
32
    // ========================================================================
32
33
Lines 31-42 Link Here
31
    // ========================================================================
32
    // ========================================================================
32
33
33
	/**
34
	/**
35
	 * 
36
	 */
37
	public TmfEventType() {
38
		this("Generic type", new String[] { "Content" });
39
	}
40
41
	/**
34
	 * @param type
42
	 * @param type
35
	 * @param format
43
	 * @param format
36
	 */
44
	 */
37
	public TmfEventType(String typeID, TmfEventFormat format) {
45
	public TmfEventType(String typeId, String[] labels) {
38
		fTypeId = typeID;
46
		fTypeId      = typeId;
39
		fFormat = format;
47
		fFieldLabels = labels;
48
		fNbFields    =  fFieldLabels.length;
49
	}
50
51
	/**
52
	 * @param other
53
	 */
54
	public TmfEventType(TmfEventType other) {
55
		fTypeId      = other.fTypeId;
56
		fFieldLabels = other.fFieldLabels;
57
		fNbFields    = other.fNbFields;
40
	}
58
	}
41
59
42
    // ========================================================================
60
    // ========================================================================
Lines 50-61 Link Here
50
		return fTypeId;
68
		return fTypeId;
51
	}
69
	}
52
70
53
    /**
71
	/**
54
     * @return
72
	 * @return
55
     */
73
	 */
56
    public TmfEventFormat getFormat() {
74
	public int getNbFields() {
57
        return fFormat;
75
		return fNbFields;
58
    }
76
	}
77
78
	/**
79
	 * @return
80
	 */
81
	public String[] getLabels() {
82
		return fFieldLabels;
83
	}
84
85
	/**
86
	 * @return
87
	 */
88
	public String getLabel(int i) {
89
		if (i >= 0 && i < fNbFields)
90
			return fFieldLabels[i];
91
		return null;
92
	}
59
93
60
    // ========================================================================
94
    // ========================================================================
61
    // Operators
95
    // Operators
Lines 63-69 Link Here
63
97
64
    @Override
98
    @Override
65
    public String toString() {
99
    public String toString() {
66
        return fTypeId.toString();
100
    	return "[type:" + fTypeId + "]";
67
    }
101
    }
68
102
69
}
103
}
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventField.java (-4 / +49 lines)
Lines 16-21 Link Here
16
 * <b><u>TmfEventField</u></b>
16
 * <b><u>TmfEventField</u></b>
17
 * <p>
17
 * <p>
18
 * A basic event field.
18
 * A basic event field.
19
 * 
20
 * TODO: Add support for field hierarchy.
19
 */
21
 */
20
public class TmfEventField {
22
public class TmfEventField {
21
23
Lines 23-29 Link Here
23
    // Attributes
25
    // Attributes
24
    // ========================================================================
26
    // ========================================================================
25
27
26
    private final Object fValue;
28
	private final TmfEventContent fParent;
29
    private final String fId;
30
    private       Object fValue;
27
31
28
    // ========================================================================
32
    // ========================================================================
29
    // Constructors
33
    // Constructors
Lines 30-41 Link Here
30
    // ========================================================================
34
    // ========================================================================
31
35
32
    /**
36
    /**
37
     * @param parent
38
     * @param id
33
     * @param value
39
     * @param value
34
     */
40
     */
35
    public TmfEventField(Object value) {
41
    public TmfEventField(TmfEventContent parent, String id, Object value) {
42
    	fParent = parent;
43
    	fId = id;
36
        fValue = value;
44
        fValue = value;
37
    }
45
    }
38
46
47
    /**
48
     * @param other
49
     */
50
    public TmfEventField(TmfEventField other) {
51
    	fParent = other.fParent;
52
    	fId = other.fId;
53
        fValue = other.fValue;
54
    }
55
56
    @SuppressWarnings("unused")
57
	private TmfEventField() {
58
    	fParent = null;
59
    	fId = null;
60
        fValue = null;
61
    }
62
39
    // ========================================================================
63
    // ========================================================================
40
    // Accessors
64
    // Accessors
41
    // ========================================================================
65
    // ========================================================================
Lines 43-48 Link Here
43
    /**
67
    /**
44
     * @return
68
     * @return
45
     */
69
     */
70
    public TmfEventContent getContent() {
71
        return fParent;
72
    }
73
74
    /**
75
     * @return
76
     */
77
    public String getId() {
78
        return fId;
79
    }
80
81
    /**
82
     * @return
83
     */
46
    public Object getValue() {
84
    public Object getValue() {
47
        return fValue;
85
        return fValue;
48
    }
86
    }
Lines 47-52 Link Here
47
        return fValue;
85
        return fValue;
48
    }
86
    }
49
87
88
    /**
89
     * @return
90
     */
91
    protected void setValue(Object value) {
92
        fValue = value;
93
    }
94
50
    // ========================================================================
95
    // ========================================================================
51
    // Operators
96
    // Operators
52
    // ========================================================================
97
    // ========================================================================
Lines 56-62 Link Here
56
     */
101
     */
57
    @Override
102
    @Override
58
	public String toString() {
103
	public String toString() {
59
        return fValue.toString();
104
        return "[field:" + fId + ",value:" + fValue.toString() + "]";
60
    }
105
    }
61
106
62
}
107
}
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventContent.java (-34 / +97 lines)
Lines 12-17 Link Here
12
12
13
package org.eclipse.linuxtools.tmf.event;
13
package org.eclipse.linuxtools.tmf.event;
14
14
15
import java.util.HashMap;
16
import java.util.Map;
17
15
/**
18
/**
16
 * <b><u>TmfEventContent</u></b>
19
 * <b><u>TmfEventContent</u></b>
17
 * <p>
20
 * <p>
Lines 23-32 Link Here
23
    // Attributes
26
    // Attributes
24
    // ========================================================================
27
    // ========================================================================
25
28
26
	private final TmfEventFormat fFormat;
29
	protected TmfEvent     fParentEvent = null;
27
	private final String fContent;
30
	protected TmfEventType fEventType   = null;
28
	private final int fNbFields;
31
	protected Object       fRawContent  = null;
29
	private       TmfEventField[] fFields = null;
32
33
	// The content fields
34
	protected Map<String, Object> fFields = null;
30
35
31
    // ========================================================================
36
    // ========================================================================
32
    // Constructors
37
    // Constructors
Lines 33-47 Link Here
33
    // ========================================================================
38
    // ========================================================================
34
39
35
	/**
40
	/**
41
	 * @param parent
42
	 * @param type
36
	 * @param content
43
	 * @param content
37
	 * @param format
38
	 */
44
	 */
39
	public TmfEventContent(Object content, TmfEventFormat format) {
45
	public TmfEventContent(TmfEventType type, Object content) {
40
		fFormat = format;
46
		fEventType   = type;
41
		fContent = content.toString();
47
		fRawContent  = content;
42
		fNbFields = fFormat.getLabels().length;
43
	}
48
	}
44
49
50
    /**
51
     * @param other
52
     */
53
    public TmfEventContent(TmfEventContent other) {
54
    	fParentEvent = other.fParentEvent;
55
		fEventType   = other.fEventType;
56
		fRawContent  = other.fRawContent;
57
    }
58
59
    @SuppressWarnings("unused")
60
	private TmfEventContent() {
61
    }
62
45
    // ========================================================================
63
    // ========================================================================
46
    // Accessors
64
    // Accessors
47
    // ========================================================================
65
    // ========================================================================
Lines 47-80 Link Here
47
    // ========================================================================
65
    // ========================================================================
48
66
49
	/**
67
	/**
50
	 * @return
68
	 * @param event
51
	 */
69
	 */
52
	public String getContent() {
70
	public void setEvent(TmfEvent event) {
53
		return fContent;
71
		fParentEvent = event;
54
	}
72
	}
55
73
56
	/**
74
	/**
57
	 * @return
75
	 * @return the parent (containing) event
58
	 */
76
	 */
59
	public TmfEventFormat getFormat() {
77
	public TmfEvent getEvent() {
60
		return fFormat;
78
		return fParentEvent;
61
	}
79
	}
62
80
63
    /**
81
	/**
64
     * @return
82
	 * @return the event type
65
     */
83
	 */
66
    public int getNbFields() {
84
	public TmfEventType getType() {
67
        return fNbFields;
85
		return fEventType;
68
    }
86
	}
69
87
70
	/**
88
	/**
71
	 * @return
89
	 * @return the raw content
90
	 */
91
	public Object getContent() {
92
		return fRawContent;
93
	}
94
95
	/**
96
	 * Returns the list of fields in the same order as TmfEventType.getLabels()
97
	 * 
98
	 * @return the ordered set of fields (optional fields might be null)
72
	 */
99
	 */
73
	public TmfEventField[] getFields() {
100
	public Object[] getFields() {
74
	    if (fFields == null) {
101
		if (fFields == null) {
75
	        fFields = fFormat.parse(fContent);
102
			fFields = parseContent();
103
		}
104
		String[] labels = fEventType.getLabels(); 
105
		int nbFields = labels.length;
106
		Object[] fields = new Object[nbFields];
107
	    for (int i = 0; i < nbFields; i++) {
108
	    	fields[i] = fFields.get(labels[i]);
76
	    }
109
	    }
77
		return fFields;
110
		return fields;
78
	}
111
	}
79
112
80
	/**
113
	/**
Lines 81-99 Link Here
81
	 * @param id
114
	 * @param id
82
	 * @return
115
	 * @return
83
	 */
116
	 */
84
	public TmfEventField getField(int id) {
117
	public Object getField(String id) {
85
        assert id >= 0 && id < fNbFields;
118
		if (fFields == null) {
86
        if (fFields == null) {
119
			fFields = parseContent();
87
            fFields = fFormat.parse(fContent);
120
		}
88
        }
121
		return fFields.get(id);
89
		return fFields[id];
90
	}
122
	}
91
123
92
	/**
124
	/**
125
	 * @param id
93
	 * @return
126
	 * @return
94
	 */
127
	 */
95
	public void setFields(TmfEventField[] fields) {
128
	public Object getField(int n) {
96
        fFields = fields;
129
		return getField(fEventType.getLabels()[n]);
130
	}
131
132
    // ========================================================================
133
    // Operators
134
    // ========================================================================
135
136
	/**
137
	 * By default, the content is a single field.
138
	 */
139
	protected Map<String, Object> parseContent() {
140
		Map<String, Object> result = new HashMap<String, Object>();
141
		String key = fEventType.getLabel(0);
142
		if (key == null) key = "Content";
143
		result.put(fEventType.getLabel(0), fRawContent);
144
		return result;
97
	}
145
	}
146
	
147
    /* (non-Javadoc)
148
     * @see java.lang.Object#toString()
149
     */
150
    @Override
151
	public String toString() {
152
    	Object[] fields = getFields();
153
    	String result = "[content:";
154
    	for (int i = 0; i < fields.length; i++) {
155
    		result += fields[i].toString();
156
    	}
157
    	result += "]";
158
159
    	return result;
160
    }
98
161
99
}
162
}
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventFormat.java (-72 lines)
Lines 1-72 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Francois Chouinard - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.linuxtools.tmf.event;
14
15
/**
16
 * <b><u>TmfEventFormat</u></b>
17
 * <p>
18
 * The basic event content format.
19
 */
20
public class TmfEventFormat implements ITmfContentParser {
21
22
    // ========================================================================
23
    // Attributes
24
    // ========================================================================
25
26
	private final String[] fLabels;
27
28
    // ========================================================================
29
    // Constructors
30
    // ========================================================================
31
32
	/**
33
	 * 
34
	 */
35
	public TmfEventFormat() {
36
	    this(new String[] { "Content" });
37
	}
38
39
    /**
40
     * @param labels
41
     */
42
    public TmfEventFormat(String[] labels) {
43
        fLabels = labels;
44
    }
45
46
    // ========================================================================
47
    // Accessors
48
    // ========================================================================
49
50
	/**
51
	 * @return
52
	 */
53
	public String[] getLabels() {
54
		return fLabels;
55
	}
56
57
    // ========================================================================
58
    // Operators
59
    // ========================================================================
60
61
	/**
62
	 * The default content parser: returns a single field containing the whole
63
	 * content.
64
	 * 
65
	 * @param content
66
	 * @return
67
	 */
68
	public TmfEventField[] parse(Object content) {
69
        return new TmfEventField[] { new TmfEventField(content.toString()) };
70
    }
71
72
}

Return to bug 287562