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/TmfEventContentStub.java (-19 / +25 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>TmfEventFormatStub</u></b>
19
 * <b><u>TmfEventFormatStub</u></b>
17
 * <p>
20
 * <p>
Lines 17-23 Link Here
17
 * <p>
20
 * <p>
18
 * TODO: Implement me. Please.
21
 * TODO: Implement me. Please.
19
 */
22
 */
20
public class TmfEventFormatStub extends TmfEventFormat {
23
public class TmfEventContentStub extends TmfEventContent {
21
24
22
    // ========================================================================
25
    // ========================================================================
23
    // Attributes
26
    // Attributes
Lines 23-39 Link Here
23
    // Attributes
26
    // Attributes
24
    // ========================================================================
27
    // ========================================================================
25
28
26
    // ========================================================================
29
	private static final String   fTypeId = "typeId";
30
	private static final String[] fLabels = new String[] { "label1", "label2", "label3", "label4", "label5"  };
31
	private static final TmfEventType fType = new TmfEventType(fTypeId, fLabels);
32
33
	private static final String[] fFields = new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" };
34
35
	// ========================================================================
27
    // Constructors
36
    // Constructors
28
    // ========================================================================
37
    // ========================================================================
29
38
30
   public TmfEventFormatStub() {
39
   public TmfEventContentStub() {
31
        super(new String[] { "Field1", "Field2", "Field3", "Field4", "Field5" });
40
        super(fType, fFields);
32
    }
41
    }
33
42
34
   // ========================================================================
43
   public TmfEventContentStub(TmfEventType type, Object content) {
35
   // Accessors
44
       super(type, content);
36
   // ========================================================================
45
   }
37
46
38
   // ========================================================================
47
   // ========================================================================
39
   // Operators
48
   // Operators
Lines 39-55 Link Here
39
   // Operators
48
   // Operators
40
   // ========================================================================
49
   // ========================================================================
41
50
42
    /* (non-Javadoc)
51
   @Override
43
     * @see org.eclipse.linuxtools.tmf.event.TmfEventFormat#parse(java.lang.Object)
52
   public Map<String, TmfEventField> parseContent() {
44
     */
53
	   Map<String, TmfEventField> fields = new HashMap<String, TmfEventField>();
45
    @Override
54
    	for (int i = 0; i < fLabels.length; i++) {
46
    public TmfEventField[] parse(Object content) {
55
    		TmfEventField field = new TmfEventField(this, fLabels[i], fFields[i]);
47
        TmfEventField field1 = new TmfEventField(1);
56
    		fields.put(fLabels[i], field);
48
        TmfEventField field2 = new TmfEventField(-10);
57
    	}
49
        TmfEventField field3 = new TmfEventField(true);
58
    	return fields;
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
    }
59
    }
54
60
55
    // ========================================================================
61
    // ========================================================================
Lines 56-59 Link Here
56
    // Helper functions
62
    // Helper functions
57
    // ========================================================================
63
    // ========================================================================
58
64
59
}
65
}
(-)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 (-13 / +12 lines)
Lines 15-25 Link Here
15
import java.io.EOFException;
15
import java.io.EOFException;
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.io.RandomAccessFile;
17
import java.io.RandomAccessFile;
18
import java.util.Vector;
19
18
20
import org.eclipse.linuxtools.tmf.event.TmfEvent;
19
import org.eclipse.linuxtools.tmf.event.TmfEvent;
21
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
20
import org.eclipse.linuxtools.tmf.event.TmfEventContentStub;
22
import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
23
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
21
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
24
import org.eclipse.linuxtools.tmf.event.TmfEventSource;
22
import org.eclipse.linuxtools.tmf.event.TmfEventSource;
25
import org.eclipse.linuxtools.tmf.event.TmfEventType;
23
import org.eclipse.linuxtools.tmf.event.TmfEventType;
Lines 36-43 Link Here
36
    // Attributes
34
    // Attributes
37
    // ========================================================================
35
    // ========================================================================
38
36
39
	private final int NB_FORMATS = 10;
37
	private final int NB_TYPES = 10;
40
    private final TmfEventFormat[] fFormats;
38
    private final String[][] fFormats;
41
39
42
    // ========================================================================
40
    // ========================================================================
43
    // Constructors
41
    // Constructors
Lines 44-57 Link Here
44
    // ========================================================================
42
    // ========================================================================
45
43
46
    public TmfEventParserStub() {
44
    public TmfEventParserStub() {
47
    	fFormats = new TmfEventFormat[NB_FORMATS];
45
    	fFormats = new String[NB_TYPES][];
48
    	for (int i = 0; i < NB_FORMATS; i++) {
46
    	for (int i = 0; i < NB_TYPES; i++) {
49
    		Vector<String> format = new Vector<String>();
47
    		fFormats[i] = new String[i];
50
    		for (int j = 1; j <= i; j++) {
48
    		for (int j = 1; j <= i; j++) {
51
    			format.add(new String("Fmt-" + i + "-Fld-" + j));
49
    			fFormats[i][j] = "Fmt-" + i + "-Fld-" + j;
52
    		}
50
    		}
53
    		String[] fields = new String[i];
54
    		fFormats[i] = new TmfEventFormat(format.toArray(fields));
55
    	}
51
    	}
56
    }
52
    }
57
53
Lines 105-115 Link Here
105
        		}
101
        		}
106
        		content += "]";
102
        		content += "]";
107
103
104
        		String[] labels = fFormats[typeIndex];
105
        		TmfEventType eventType = new TmfEventType(type, labels);
106
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
        				eventType,
112
        				new TmfEventContent(content, fFormats[typeIndex]),
111
        				new TmfEventContentStub(eventType, labels),
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 (-4 / +3 lines)
Lines 31-37 Link Here
31
    public void testEmptyConstructor() {
31
    public void testEmptyConstructor() {
32
        TmfEventType type = new TmfEventType("", null);
32
        TmfEventType type = new TmfEventType("", null);
33
        assertEquals("getValue", "", type.getTypeId());
33
        assertEquals("getValue", "", type.getTypeId());
34
        assertEquals("getFormat", null, type.getFormat());
35
   }
34
   }
36
35
37
    @Test
36
    @Test
Lines 36-45 Link Here
36
35
37
    @Test
36
    @Test
38
    public void testNormalConstructor() {
37
    public void testNormalConstructor() {
39
        TmfEventType type = new TmfEventType("Type", new TmfEventFormat(new String[] { "field1", "field2" }));
38
        TmfEventType type = new TmfEventType("Type", new String[] { "field1", "field2" });
40
        assertEquals("getValue", "Type", type.getTypeId());
39
        assertEquals("getValue", "Type", type.getTypeId());
41
        assertEquals("getFormat", "field1", type.getFormat().getLabels()[0]);
40
        assertEquals("getFormat", "field1", type.getLabels()[0]);
42
        assertEquals("getFormat", "field2", type.getFormat().getLabels()[1]);
41
        assertEquals("getFormat", "field2", type.getLabels()[1]);
43
   }
42
   }
44
43
45
}
44
}
(-)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 / +11 lines)
Lines 29-39 Link Here
29
29
30
    @Test
30
    @Test
31
    public void testTmfTraceEvent() throws Exception {
31
    public void testTmfTraceEvent() throws Exception {
32
        TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
32
33
    	String[] labels = new String[] { "label1", "label2" };
34
        String[] fields = new String[] { "field1", "field2" };
35
36
    	TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
33
        TmfEventSource    source    = new TmfEventSource("Source");
37
        TmfEventSource    source    = new TmfEventSource("Source");
34
        TmfEventFormat    format    = new TmfEventFormat(new String[] { "field1", "field2" });
38
        TmfEventType      type      = new TmfEventType("Type", labels);
35
        TmfEventType      type      = new TmfEventType("Type", format);
39
        TmfEventContent   content   = new TmfEventContentStub(type, fields);
36
        TmfEventContent   content   = new TmfEventContent("Some content", format);
37
        TmfEventReference reference = new TmfEventReference("Reference");
40
        TmfEventReference reference = new TmfEventReference("Reference");
38
41
39
        // Create the trace event
42
        // Create the trace event
Lines 53-65 Link Here
53
        // Check the event type
56
        // Check the event type
54
        TmfEventType evType = event.getType();
57
        TmfEventType evType = event.getType();
55
        assertEquals("getValue", "Type", evType.getTypeId());
58
        assertEquals("getValue", "Type", evType.getTypeId());
56
        assertEquals("getFormat", "field1", evType.getFormat().getLabels()[0]);
59
        assertEquals("getFormat", "label1", evType.getLabels()[0]);
57
        assertEquals("getFormat", "field2", evType.getFormat().getLabels()[1]);
60
        assertEquals("getFormat", "label2", evType.getLabels()[1]);
58
61
59
        // Check the event content
62
        // Check the event content
60
        TmfEventContent evContent = event.getContent();
63
        TmfEventContent evContent = event.getContent();
61
        assertEquals("getField", 1, evContent.getFields().length);
64
        assertEquals("getField", 2, evContent.getFields().length);
62
        assertEquals("getField", "Some content", evContent.getField(0).toString());
65
        assertEquals("getField", "[field:label1,value:Field1]", evContent.getField(evType.getLabels()[0]).toString());
63
66
64
        // Check the event reference
67
        // Check the event reference
65
        TmfEventReference evRef = event.getReference();
68
        TmfEventReference evRef = event.getReference();
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventContentTest.java (-19 / +14 lines)
Lines 29-38 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 TmfEventContentStub();
33
		assertEquals("getFormat", 1, content.getFormat().getLabels().length);
33
		assertEquals("getType", "typeId", content.getType().getTypeId());
34
		assertEquals("getLabels", "Content", content.getFormat().getLabels()[0]);
34
		if (content.getContent() instanceof String) {
35
		assertEquals("getContent", "Some content", content.getContent());
35
			String value = (String) content.getContent();
36
			assertEquals("getContent", "Some content", value);
37
		}
36
	}
38
	}
37
39
38
	// ========================================================================
40
	// ========================================================================
Lines 40-60 Link Here
40
	// ========================================================================
42
	// ========================================================================
41
43
42
	@Test
44
	@Test
43
	public void testBasicGetField() {
45
	public void testGetField() {
44
		TmfEventContent content = new TmfEventContent("Some content", new TmfEventFormat());
46
		TmfEventContent content = new TmfEventContentStub();
45
		assertEquals("getField", 1, content.getFields().length);
46
		assertEquals("getField", "Some content", content.getField(0).toString());
47
	}
48
49
	@Test
50
	public void testExtendedGetField() {
51
		TmfEventContent content = new TmfEventContent("", new TmfEventFormatStub());
52
		assertEquals("getField", 5, content.getFields().length);
47
		assertEquals("getField", 5, content.getFields().length);
53
		assertEquals("getField", "1", content.getField(0).toString());
48
		assertEquals("getField", "[field:label1,value:Field1]", content.getField("label1").toString());
54
		assertEquals("getField", "-10", content.getField(1).toString());
49
		assertEquals("getField", "[field:label2,value:Field2]", content.getField("label2").toString());
55
		assertEquals("getField", "true", content.getField(2).toString());
50
		assertEquals("getField", "[field:label3,value:Field3]", content.getField("label3").toString());
56
		assertEquals("getField", "some string", content.getField(3).toString());
51
		assertEquals("getField", "[field:label4,value:Field4]", content.getField("label4").toString());
57
		assertEquals("getField", "[TmfTimestamp:1,2,3]", content.getField(4).toString());
52
		assertEquals("getField", "[field:label5,value:Field5]", content.getField("label5").toString());
58
	}
53
	}
59
54
60
}
55
}
(-)src/org/eclipse/linuxtools/tmf/event/TmfEventTest.java (-15 / +21 lines)
Lines 29-39 Link Here
29
    
29
    
30
    @Test
30
    @Test
31
    public void testTmfEvent() {
31
    public void testTmfEvent() {
32
33
    	String[] labels = new String[] { "label1", "label2" };
34
        String[] fields = new String[] { "field1", "field2" };
35
32
        TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
36
        TmfTimestamp      timestamp = new TmfTimestamp(12345, (byte) 2, 5);
33
        TmfEventSource    source    = new TmfEventSource("Source");
37
        TmfEventSource    source    = new TmfEventSource("Source");
34
        TmfEventFormat    format    = new TmfEventFormat(new String[] { "field1", "field2" });
38
        TmfEventType      type      = new TmfEventType("Type", labels);
35
        TmfEventType      type      = new TmfEventType("Type", format);
39
        TmfEventContent   content   = new TmfEventContentStub(type, fields);
36
        TmfEventContent   content   = new TmfEventContent("Some content", format);
37
        TmfEventReference reference = new TmfEventReference("Reference");
40
        TmfEventReference reference = new TmfEventReference("Reference");
38
41
39
        // Create the event
42
        // Create the event
Lines 58-70 Link Here
58
        // Check the event type
61
        // Check the event type
59
        TmfEventType tp = event.getType();
62
        TmfEventType tp = event.getType();
60
        assertEquals("getValue", "Type", tp.getTypeId());
63
        assertEquals("getValue", "Type", tp.getTypeId());
61
        assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]);
64
        assertEquals("getFormat", "label1", tp.getLabels()[0]);
62
        assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]);
65
        assertEquals("getFormat", "label2", tp.getLabels()[1]);
63
66
64
        // Check the event content
67
        // Check the event content
65
        TmfEventContent cnt = event.getContent();
68
        TmfEventContent cnt = event.getContent();
66
        assertEquals("getField", 1, cnt.getFields().length);
69
        assertEquals("getField", 2, cnt.getFields().length);
67
        assertEquals("getField", "Some content", cnt.getField(0).toString());
70
        assertEquals("getField", "[field:label1,value:Field1]", cnt.getField(tp.getLabels()[0]).toString());
68
71
69
        // Check the event reference
72
        // Check the event reference
70
        TmfEventReference ref = event.getReference();
73
        TmfEventReference ref = event.getReference();
Lines 73-84 Link Here
73
76
74
    @Test
77
    @Test
75
    public void testTmfEvent2() {
78
    public void testTmfEvent2() {
76
        TmfTimestamp      original  = new TmfTimestamp(12345, (byte) 2, 5);
79
80
    	String[] labels = new String[] { "label1", "label2" };
81
        String[] fields = new String[] { "field1", "field2" };
82
83
    	TmfTimestamp      original  = new TmfTimestamp(12345, (byte) 2, 5);
77
        TmfTimestamp      effective = new TmfTimestamp(12350, (byte) 2, 5);
84
        TmfTimestamp      effective = new TmfTimestamp(12350, (byte) 2, 5);
78
        TmfEventSource    source    = new TmfEventSource("Source");
85
        TmfEventSource    source    = new TmfEventSource("Source");
79
        TmfEventFormat    format    = new TmfEventFormat(new String[] { "field1", "field2" });
86
        TmfEventType      type      = new TmfEventType("Type", labels);
80
        TmfEventType      type      = new TmfEventType("Type", format);
87
        TmfEventContent   content   = new TmfEventContentStub(type, fields);
81
        TmfEventContent   content   = new TmfEventContent("Some content", format);
82
        TmfEventReference reference = new TmfEventReference("Reference");
88
        TmfEventReference reference = new TmfEventReference("Reference");
83
89
84
        // Create the event
90
        // Create the event
Lines 103-115 Link Here
103
        // Check the event type
109
        // Check the event type
104
        TmfEventType tp = event.getType();
110
        TmfEventType tp = event.getType();
105
        assertEquals("getValue", "Type", tp.getTypeId());
111
        assertEquals("getValue", "Type", tp.getTypeId());
106
        assertEquals("getFormat", "field1", tp.getFormat().getLabels()[0]);
112
        assertEquals("getFormat", "label1", tp.getLabels()[0]);
107
        assertEquals("getFormat", "field2", tp.getFormat().getLabels()[1]);
113
        assertEquals("getFormat", "label2", tp.getLabels()[1]);
108
114
109
        // Check the event content
115
        // Check the event content
110
        TmfEventContent cnt = event.getContent();
116
        TmfEventContent cnt = event.getContent();
111
        assertEquals("getField", 1, cnt.getFields().length);
117
        assertEquals("getField", 2, cnt.getFields().length);
112
        assertEquals("getField", "Some content", cnt.getField(0).toString());
118
        assertEquals("getField", "[field:label1,value:Field1]", cnt.getField(tp.getLabels()[0]).toString());
113
119
114
        // Check the event reference
120
        // Check the event reference
115
        TmfEventReference ref = event.getReference();
121
        TmfEventReference ref = event.getReference();
(-)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 (-12 / +12 lines)
Lines 23-30 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
28
29
    // ========================================================================
29
    // ========================================================================
30
    // Constructors
30
    // Constructors
Lines 34-42 Link Here
34
	 * @param type
34
	 * @param type
35
	 * @param format
35
	 * @param format
36
	 */
36
	 */
37
	public TmfEventType(String typeID, TmfEventFormat format) {
37
	public TmfEventType(String typeID, String[] labels) {
38
		fTypeId = typeID;
38
		fTypeId = typeID;
39
		fFormat = format;
39
		fFieldLabels = labels;
40
	}
40
	}
41
41
42
    // ========================================================================
42
    // ========================================================================
Lines 50-61 Link Here
50
		return fTypeId;
50
		return fTypeId;
51
	}
51
	}
52
52
53
    /**
53
	/**
54
     * @return
54
	 * @return
55
     */
55
	 */
56
    public TmfEventFormat getFormat() {
56
	public String[] getLabels() {
57
        return fFormat;
57
		return fFieldLabels;
58
    }
58
	}
59
59
60
    // ========================================================================
60
    // ========================================================================
61
    // Operators
61
    // Operators
Lines 63-69 Link Here
63
63
64
    @Override
64
    @Override
65
    public String toString() {
65
    public String toString() {
66
        return fTypeId.toString();
66
    	return "[type:" + fTypeId + "]";
67
    }
67
    }
68
68
69
}
69
}
(-)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 (-36 / +81 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.Map;
16
15
/**
17
/**
16
 * <b><u>TmfEventContent</u></b>
18
 * <b><u>TmfEventContent</u></b>
17
 * <p>
19
 * <p>
Lines 17-23 Link Here
17
 * <p>
19
 * <p>
18
 * The event content.
20
 * The event content.
19
 */
21
 */
20
public class TmfEventContent {
22
public abstract class TmfEventContent {
21
23
22
    // ========================================================================
24
    // ========================================================================
23
    // Attributes
25
    // Attributes
Lines 23-32 Link Here
23
    // Attributes
25
    // Attributes
24
    // ========================================================================
26
    // ========================================================================
25
27
26
	private final TmfEventFormat fFormat;
28
	protected TmfEvent     fParentEvent = null;
27
	private final String fContent;
29
	protected TmfEventType fEventType   = null;
28
	private final int fNbFields;
30
	protected Object       fRawContent  = null;
29
	private       TmfEventField[] fFields = null;
31
32
	// The ordered list of field labels
33
	protected String[] fFieldLabels = null;
34
	protected Map<String, TmfEventField> 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;
48
		fFieldLabels = (type != null) ? fEventType.getLabels() : null;
49
		fFields = parseContent();
43
	}
50
	}
44
51
52
    /**
53
     * @param other
54
     */
55
    public TmfEventContent(TmfEventContent other) {
56
    	fParentEvent = other.fParentEvent;
57
		fEventType   = other.fEventType;
58
		fRawContent  = other.fRawContent;
59
		fFieldLabels = other.fFieldLabels;
60
    }
61
62
    @SuppressWarnings("unused")
63
	private TmfEventContent() {
64
    }
65
45
    // ========================================================================
66
    // ========================================================================
46
    // Accessors
67
    // Accessors
47
    // ========================================================================
68
    // ========================================================================
Lines 47-80 Link Here
47
    // ========================================================================
68
    // ========================================================================
48
69
49
	/**
70
	/**
50
	 * @return
71
	 * @param event
72
	 */
73
	public void setEvent(TmfEvent event) {
74
		fParentEvent = event;
75
	}
76
77
	/**
78
	 * @return the parent (containing) event
51
	 */
79
	 */
52
	public String getContent() {
80
	public TmfEvent getEvent() {
53
		return fContent;
81
		return fParentEvent;
54
	}
82
	}
55
83
56
	/**
84
	/**
57
	 * @return
85
	 * @return the event type
58
	 */
86
	 */
59
	public TmfEventFormat getFormat() {
87
	public TmfEventType getType() {
60
		return fFormat;
88
		return fEventType;
61
	}
89
	}
62
90
63
    /**
91
	/**
64
     * @return
92
	 * @return the raw content
65
     */
93
	 */
66
    public int getNbFields() {
94
	public Object getContent() {
67
        return fNbFields;
95
		return fRawContent;
68
    }
96
	}
69
97
70
	/**
98
	/**
71
	 * @return
99
	 * Returns the list of fields in the same order as TmfEventType.getLabels()
100
	 * 
101
	 * @return the ordered set of fields (optional fields might be null)
72
	 */
102
	 */
73
	public TmfEventField[] getFields() {
103
	public TmfEventField[] getFields() {
74
	    if (fFields == null) {
104
		int nbFields = fFieldLabels.length;
75
	        fFields = fFormat.parse(fContent);
105
		TmfEventField[] fields = new TmfEventField[nbFields];
106
	    for (int i = 0; i < nbFields; i++) {
107
	    	fields[i] = fFields.get(fFieldLabels[i]);
76
	    }
108
	    }
77
		return fFields;
109
		return fields;
78
	}
110
	}
79
111
80
	/**
112
	/**
Lines 81-99 Link Here
81
	 * @param id
113
	 * @param id
82
	 * @return
114
	 * @return
83
	 */
115
	 */
84
	public TmfEventField getField(int id) {
116
	public TmfEventField getField(String id) {
85
        assert id >= 0 && id < fNbFields;
117
		return fFields.get(id);
86
        if (fFields == null) {
87
            fFields = fFormat.parse(fContent);
88
        }
89
		return fFields[id];
90
	}
118
	}
91
119
120
    // ========================================================================
121
    // Operators
122
    // ========================================================================
123
92
	/**
124
	/**
93
	 * @return
125
	 * 
94
	 */
126
	 */
95
	public void setFields(TmfEventField[] fields) {
127
	public abstract Map<String, TmfEventField> parseContent();
96
        fFields = fields;
128
	
97
	}
129
    /* (non-Javadoc)
130
     * @see java.lang.Object#toString()
131
     */
132
    @Override
133
	public String toString() {
134
    	TmfEventField[] fields = getFields();
135
    	String result = "[content:";
136
    	for (int i = 0; i < fields.length; i++) {
137
    		result += fields[i].toString();
138
    	}
139
    	result += "]";
140
141
    	return result;
142
    }
98
143
99
}
144
}
(-)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