Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / filter / model / TmfFilterNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.event.TmfEvent;
19
20
21 public class TmfFilterNode extends TmfFilterTreeNode {
22
23 public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$
24 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
25
26 String fFilterName;
27
28 public TmfFilterNode(String filterName) {
29 super(null);
30 fFilterName = filterName;
31 }
32
33 public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) {
34 super(parent);
35 fFilterName = filterName;
36 }
37
38 public String getFilterName() {
39 return fFilterName;
40 }
41
42 public void setFilterName(String filterName) {
43 fFilterName = filterName;
44 }
45
46 @Override
47 public String getNodeName() {
48 return NODE_NAME;
49 }
50
51 @Override
52 public boolean matches(TmfEvent event) {
53 // There should be at most one child
54 for (ITmfFilterTreeNode node : getChildren()) {
55 if (node.matches(event)) {
56 return true;
57 }
58 }
59 return false;
60 }
61
62 @Override
63 public List<String> getValidChildren() {
64 if (getChildrenCount() == 0) {
65 return super.getValidChildren();
66 } else {
67 return new ArrayList<String>(0); // only one child allowed
68 }
69 }
70
71 @Override
72 public String toString() {
73 StringBuffer buf = new StringBuffer();
74 if (getChildrenCount() > 1) {
75 buf.append("( "); //$NON-NLS-1$
76 }
77 for (int i = 0; i < getChildrenCount(); i++) {
78 ITmfFilterTreeNode node = getChildren()[i];
79 buf.append(node.toString());
80 if (i < getChildrenCount() - 1) {
81 buf.append(" and "); //$NON-NLS-1$
82 }
83 }
84 if (getChildrenCount() > 1) {
85 buf.append(" )"); //$NON-NLS-1$
86 }
87 return buf.toString();
88 }
89 }
This page took 0.03429 seconds and 5 git commands to generate.