Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterEventTypeNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
19
20
21 public class TmfFilterEventTypeNode extends TmfFilterTreeNode {
22
23 public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
24 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
25 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
26
27 private String fType;
28 private String fName;
29
30 public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {
31 super(parent);
32 }
33
34 @Override
35 public String getNodeName() {
36 return NODE_NAME;
37 }
38
39 public String getEventType() {
40 return fType;
41 }
42
43 public void setEventType(String type) {
44 this.fType = type;
45 }
46
47 public String getName() {
48 return fName;
49 }
50
51 public void setName(String name) {
52 this.fName = name;
53 }
54
55 @Override
56 public boolean matches(TmfEvent event) {
57 boolean match = false;
58 if (fType.contains(":")) { //$NON-NLS-1$
59 // special case for custom parsers
60 if (fType.startsWith(event.getClass().getCanonicalName())) {
61 if (fType.endsWith(event.getType().getTypeId())) {
62 match = true;
63 }
64 }
65 } else {
66 if (event.getClass().getCanonicalName().equals(fType)) {
67 match = true;
68 }
69 }
70 if (match) {
71 // There should be at most one child
72 for (ITmfFilterTreeNode node : getChildren()) {
73 if (! node.matches(event)) {
74 return false;
75 }
76 }
77 return true;
78 }
79 return false;
80 }
81
82 @Override
83 public List<String> getValidChildren() {
84 if (getChildrenCount() == 0) {
85 return super.getValidChildren();
86 } else {
87 return new ArrayList<String>(0); // only one child allowed
88 }
89 }
90
91 @Override
92 public String toString() {
93 StringBuffer buf = new StringBuffer();
94 buf.append("EventType is " + fName); //$NON-NLS-1$
95 if (getChildrenCount() > 0) {
96 buf.append(" and "); //$NON-NLS-1$
97 }
98 if (getChildrenCount() > 1) {
99 buf.append("( "); //$NON-NLS-1$
100 }
101 for (int i = 0; i < getChildrenCount(); i++) {
102 ITmfFilterTreeNode node = getChildren()[i];
103 buf.append(node.toString());
104 if (i < getChildrenCount() - 1) {
105 buf.append(" and "); //$NON-NLS-1$
106 }
107 }
108 if (getChildrenCount() > 1) {
109 buf.append(" )"); //$NON-NLS-1$
110 }
111 return buf.toString();
112 }
113 }
This page took 0.044947 seconds and 5 git commands to generate.