1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
22 * Filter node for an trace type
25 * @author Patrick Tasse
27 @SuppressWarnings("javadoc")
28 public class TmfFilterTraceTypeNode
extends TmfFilterTreeNode
{
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$
34 private String fTraceTypeId
;
35 private Class
<?
extends ITmfTrace
> fTraceClass
;
39 * @param parent the parent node
41 public TmfFilterTraceTypeNode(ITmfFilterTreeNode parent
) {
46 public String
getNodeName() {
51 * @return the trace type id
53 public String
getTraceTypeId() {
58 * @param traceTypeId the trace type id
60 public void setTraceTypeId(String traceTypeId
) {
61 this.fTraceTypeId
= traceTypeId
;
65 * @return the trace class
67 public Class
<?
extends ITmfTrace
> getTraceClass() {
72 * @param traceClass the trace class
74 public void setTraceClass(Class
<?
extends ITmfTrace
> traceClass
) {
75 this.fTraceClass
= traceClass
;
79 * @return the category and trace type name
81 public String
getName() {
86 * @param name the category and trace type name
88 public void setName(String name
) {
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())) {
106 // There should be at most one child
107 for (ITmfFilterTreeNode node
: getChildren()) {
108 if (! node
.matches(event
)) {
118 public List
<String
> getValidChildren() {
119 if (getChildrenCount() == 0) {
120 return super.getValidChildren();
122 return new ArrayList
<>(0); // only one child allowed
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$
132 if (getChildrenCount() > 1) {
133 buf
.append("( "); //$NON-NLS-1$
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$
142 if (getChildrenCount() > 1) {
143 buf
.append(" )"); //$NON-NLS-1$
145 return buf
.toString();
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());
158 public boolean equals(Object obj
) {
162 if (!super.equals(obj
)) {
165 if (getClass() != obj
.getClass()) {
168 TmfFilterTraceTypeNode other
= (TmfFilterTraceTypeNode
) obj
;
170 if (other
.fName
!= null) {
173 } else if (!fName
.equals(other
.fName
)) {
176 if (fTraceTypeId
== null) {
177 if (other
.fTraceTypeId
!= null) {
180 } else if (!fTraceTypeId
.equals(other
.fTraceTypeId
)) {