tmf: Replace TmfFilterEventTypeNode with TmfFilterTraceTypeNode
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / filter / model / TmfFilterTraceTypeNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 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.tracecompass.tmf.core.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
20
21 /**
22 * Filter node for an trace type
23 *
24 * @version 1.0
25 * @author Patrick Tasse
26 */
27 @SuppressWarnings("javadoc")
28 public class TmfFilterTraceTypeNode extends TmfFilterTreeNode {
29
30 public static final String NODE_NAME = "TRACETYPE"; //$NON-NLS-1$
31 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
32 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
33
34 private String fTraceTypeId;
35 private Class<? extends ITmfTrace> fTraceClass;
36 private String fName;
37
38 /**
39 * @param parent the parent node
40 */
41 public TmfFilterTraceTypeNode(ITmfFilterTreeNode parent) {
42 super(parent);
43 }
44
45 @Override
46 public String getNodeName() {
47 return NODE_NAME;
48 }
49
50 /**
51 * @return the trace type id
52 */
53 public String getTraceTypeId() {
54 return fTraceTypeId;
55 }
56
57 /**
58 * @param traceTypeId the trace type id
59 */
60 public void setTraceTypeId(String traceTypeId) {
61 this.fTraceTypeId = traceTypeId;
62 }
63
64 /**
65 * @return the trace class
66 */
67 public Class<? extends ITmfTrace> getTraceClass() {
68 return fTraceClass;
69 }
70
71 /**
72 * @param traceClass the trace class
73 */
74 public void setTraceClass(Class<? extends ITmfTrace> traceClass) {
75 this.fTraceClass = traceClass;
76 }
77
78 /**
79 * @return the category and trace type name
80 */
81 public String getName() {
82 return fName;
83 }
84
85 /**
86 * @param name the category and trace type name
87 */
88 public void setName(String name) {
89 this.fName = name;
90 }
91
92 @Override
93 public boolean matches(ITmfEvent event) {
94 boolean match = false;
95 ITmfTrace trace = event.getTrace();
96 if (trace.getClass().equals(fTraceClass)) {
97 if (fTraceTypeId != null) {
98 if (fTraceTypeId.equals(trace.getTraceTypeId())) {
99 match = true;
100 }
101 } else {
102 match = true;
103 }
104 }
105 if (match) {
106 // There should be at most one child
107 for (ITmfFilterTreeNode node : getChildren()) {
108 if (! node.matches(event)) {
109 return false;
110 }
111 }
112 return true;
113 }
114 return false;
115 }
116
117 @Override
118 public List<String> getValidChildren() {
119 if (getChildrenCount() == 0) {
120 return super.getValidChildren();
121 }
122 return new ArrayList<>(0); // only one child allowed
123 }
124
125 @Override
126 public String toString() {
127 StringBuffer buf = new StringBuffer();
128 buf.append("TraceType is " + fName); //$NON-NLS-1$
129 if (getChildrenCount() > 0) {
130 buf.append(" and "); //$NON-NLS-1$
131 }
132 if (getChildrenCount() > 1) {
133 buf.append("( "); //$NON-NLS-1$
134 }
135 for (int i = 0; i < getChildrenCount(); i++) {
136 ITmfFilterTreeNode node = getChildren()[i];
137 buf.append(node.toString());
138 if (i < getChildrenCount() - 1) {
139 buf.append(" and "); //$NON-NLS-1$
140 }
141 }
142 if (getChildrenCount() > 1) {
143 buf.append(" )"); //$NON-NLS-1$
144 }
145 return buf.toString();
146 }
147
148 @Override
149 public int hashCode() {
150 final int prime = 31;
151 int result = super.hashCode();
152 result = prime * result + ((fName == null) ? 0 : fName.hashCode());
153 result = prime * result + ((fTraceTypeId == null) ? 0 : fTraceTypeId.hashCode());
154 return result;
155 }
156
157 @Override
158 public boolean equals(Object obj) {
159 if (this == obj) {
160 return true;
161 }
162 if (!super.equals(obj)) {
163 return false;
164 }
165 if (getClass() != obj.getClass()) {
166 return false;
167 }
168 TmfFilterTraceTypeNode other = (TmfFilterTraceTypeNode) obj;
169 if (fName == null) {
170 if (other.fName != null) {
171 return false;
172 }
173 } else if (!fName.equals(other.fName)) {
174 return false;
175 }
176 if (fTraceTypeId == null) {
177 if (other.fTraceTypeId != null) {
178 return false;
179 }
180 } else if (!fTraceTypeId.equals(other.fTraceTypeId)) {
181 return false;
182 }
183 return true;
184 }
185 }
This page took 0.035443 seconds and 5 git commands to generate.