1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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
.linuxtools
.tmf
.core
.filter
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
21 * Filter node for an event
24 * @author Patrick Tasse
26 @SuppressWarnings("javadoc")
27 public class TmfFilterEventTypeNode
extends TmfFilterTreeNode
{
30 public int hashCode() {
32 int result
= super.hashCode();
33 result
= prime
* result
+ ((fName
== null) ?
0 : fName
.hashCode());
34 result
= prime
* result
+ ((fType
== null) ?
0 : fType
.hashCode());
39 public boolean equals(Object obj
) {
43 if (!super.equals(obj
)) {
46 if (getClass() != obj
.getClass()) {
49 TmfFilterEventTypeNode other
= (TmfFilterEventTypeNode
) obj
;
51 if (other
.fName
!= null) {
54 } else if (!fName
.equals(other
.fName
)) {
58 if (other
.fType
!= null) {
61 } else if (!fType
.equals(other
.fType
)) {
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$
75 * @param parent the parent node
77 public TmfFilterEventTypeNode(ITmfFilterTreeNode parent
) {
82 public String
getNodeName() {
87 * @return the event type
89 public String
getEventType() {
94 * @param type the event type
96 public void setEventType(String type
) {
101 * @return the category and trace type name
103 public String
getName() {
108 * @param name the category and trace type name
110 public void setName(String name
) {
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())) {
125 if (event
.getClass().getCanonicalName().equals(fType
)) {
130 // There should be at most one child
131 for (ITmfFilterTreeNode node
: getChildren()) {
132 if (! node
.matches(event
)) {
142 public List
<String
> getValidChildren() {
143 if (getChildrenCount() == 0) {
144 return super.getValidChildren();
146 return new ArrayList
<>(0); // only one child allowed
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$
156 if (getChildrenCount() > 1) {
157 buf
.append("( "); //$NON-NLS-1$
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$
166 if (getChildrenCount() > 1) {
167 buf
.append(" )"); //$NON-NLS-1$
169 return buf
.toString();