tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterEventTypeNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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.ITmfEvent;
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
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
67 public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
68 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
69 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
70
71 private String fType;
72 private String fName;
73
74 /**
75 * @param parent the parent node
76 */
77 public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {
78 super(parent);
79 }
80
81 @Override
82 public String getNodeName() {
83 return NODE_NAME;
84 }
85
86 /**
87 * @return the event type
88 */
89 public String getEventType() {
90 return fType;
91 }
92
93 /**
94 * @param type the event type
95 */
96 public void setEventType(String type) {
97 this.fType = type;
98 }
99
100 /**
101 * @return the category and trace type name
102 */
103 public String getName() {
104 return fName;
105 }
106
107 /**
108 * @param name the category and trace type name
109 */
110 public void setName(String name) {
111 this.fName = name;
112 }
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
141 @Override
142 public List<String> getValidChildren() {
143 if (getChildrenCount() == 0) {
144 return super.getValidChildren();
145 }
146 return new ArrayList<>(0); // only one child allowed
147 }
148
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 }
171 }
This page took 0.035054 seconds and 5 git commands to generate.