Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2010, 2014 Ericsson |
be222f56 PT |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.filter.model; |
be222f56 PT |
14 | |
15 | import java.util.ArrayList; | |
16 | import java.util.List; | |
17 | ||
2bdf0193 | 18 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
be222f56 PT |
19 | |
20 | /** | |
21 | * Filter node for an event | |
22 | * | |
23 | * @version 1.0 | |
24 | * @author Patrick Tasse | |
25 | */ | |
26 | @SuppressWarnings("javadoc") | |
27 | public class TmfFilterEventTypeNode extends TmfFilterTreeNode { | |
28 | ||
b64984c4 VP |
29 | @Override |
30 | public int hashCode() { | |
31 | final int prime = 31; | |
32 | int result = super.hashCode(); | |
33 | result = prime * result + ((fName == null) ? 0 : fName.hashCode()); | |
34 | result = prime * result + ((fType == null) ? 0 : fType.hashCode()); | |
35 | return result; | |
36 | } | |
37 | ||
38 | @Override | |
39 | public boolean equals(Object obj) { | |
40 | if (this == obj) { | |
41 | return true; | |
42 | } | |
43 | if (!super.equals(obj)) { | |
44 | return false; | |
45 | } | |
46 | if (getClass() != obj.getClass()) { | |
47 | return false; | |
48 | } | |
49 | TmfFilterEventTypeNode other = (TmfFilterEventTypeNode) obj; | |
50 | if (fName == null) { | |
51 | if (other.fName != null) { | |
52 | return false; | |
53 | } | |
54 | } else if (!fName.equals(other.fName)) { | |
55 | return false; | |
56 | } | |
57 | if (fType == null) { | |
58 | if (other.fType != null) { | |
59 | return false; | |
60 | } | |
61 | } else if (!fType.equals(other.fType)) { | |
62 | return false; | |
63 | } | |
64 | return true; | |
65 | } | |
66 | ||
be222f56 | 67 | public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$ |
d5efe032 AF |
68 | public static final String TYPE_ATTR = "type"; //$NON-NLS-1$ |
69 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$ | |
be222f56 | 70 | |
d5efe032 AF |
71 | private String fType; |
72 | private String fName; | |
be222f56 | 73 | |
d5efe032 AF |
74 | /** |
75 | * @param parent the parent node | |
76 | */ | |
77 | public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) { | |
78 | super(parent); | |
79 | } | |
be222f56 | 80 | |
d5efe032 AF |
81 | @Override |
82 | public String getNodeName() { | |
83 | return NODE_NAME; | |
84 | } | |
be222f56 | 85 | |
d5efe032 AF |
86 | /** |
87 | * @return the event type | |
88 | */ | |
89 | public String getEventType() { | |
90 | return fType; | |
91 | } | |
be222f56 | 92 | |
d5efe032 AF |
93 | /** |
94 | * @param type the event type | |
95 | */ | |
96 | public void setEventType(String type) { | |
97 | this.fType = type; | |
98 | } | |
be222f56 | 99 | |
d5efe032 | 100 | /** |
4b3b667b | 101 | * @return the category and trace type name |
d5efe032 AF |
102 | */ |
103 | public String getName() { | |
104 | return fName; | |
105 | } | |
be222f56 | 106 | |
d5efe032 | 107 | /** |
4b3b667b | 108 | * @param name the category and trace type name |
d5efe032 AF |
109 | */ |
110 | public void setName(String name) { | |
111 | this.fName = name; | |
112 | } | |
be222f56 PT |
113 | |
114 | @Override | |
115 | public boolean matches(ITmfEvent event) { | |
116 | boolean match = false; | |
117 | if (fType.contains(":")) { //$NON-NLS-1$ | |
118 | // special case for custom parsers | |
119 | if (fType.startsWith(event.getClass().getCanonicalName())) { | |
120 | if (fType.endsWith(event.getType().getName())) { | |
121 | match = true; | |
122 | } | |
123 | } | |
124 | } else { | |
125 | if (event.getClass().getCanonicalName().equals(fType)) { | |
126 | match = true; | |
127 | } | |
128 | } | |
129 | if (match) { | |
130 | // There should be at most one child | |
131 | for (ITmfFilterTreeNode node : getChildren()) { | |
132 | if (! node.matches(event)) { | |
133 | return false; | |
134 | } | |
135 | } | |
136 | return true; | |
137 | } | |
138 | return false; | |
139 | } | |
140 | ||
d5efe032 AF |
141 | @Override |
142 | public List<String> getValidChildren() { | |
143 | if (getChildrenCount() == 0) { | |
144 | return super.getValidChildren(); | |
145 | } | |
a4524c1b | 146 | return new ArrayList<>(0); // only one child allowed |
d5efe032 | 147 | } |
be222f56 | 148 | |
d5efe032 AF |
149 | @Override |
150 | public String toString() { | |
151 | StringBuffer buf = new StringBuffer(); | |
152 | buf.append("EventType is " + fName); //$NON-NLS-1$ | |
153 | if (getChildrenCount() > 0) { | |
154 | buf.append(" and "); //$NON-NLS-1$ | |
155 | } | |
156 | if (getChildrenCount() > 1) { | |
157 | buf.append("( "); //$NON-NLS-1$ | |
158 | } | |
159 | for (int i = 0; i < getChildrenCount(); i++) { | |
160 | ITmfFilterTreeNode node = getChildren()[i]; | |
161 | buf.append(node.toString()); | |
162 | if (i < getChildrenCount() - 1) { | |
163 | buf.append(" and "); //$NON-NLS-1$ | |
164 | } | |
165 | } | |
166 | if (getChildrenCount() > 1) { | |
167 | buf.append(" )"); //$NON-NLS-1$ | |
168 | } | |
169 | return buf.toString(); | |
170 | } | |
be222f56 | 171 | } |