Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2010, 2012 Ericsson |
be222f56 PT |
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 the event match operation | |
22 | * | |
23 | * @version 1.0 | |
24 | * @author Patrick Tasse | |
25 | */ | |
26 | @SuppressWarnings("javadoc") | |
27 | public class TmfFilterNode extends TmfFilterTreeNode { | |
28 | ||
29 | public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$ | |
30 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$ | |
31 | ||
32 | String fFilterName; | |
33 | ||
34 | /** | |
35 | * @param filterName the filter name | |
36 | */ | |
37 | public TmfFilterNode(String filterName) { | |
38 | super(null); | |
39 | fFilterName = filterName; | |
40 | } | |
41 | ||
42 | /** | |
43 | * @param parent the parent node | |
44 | * @param filterName the filter name | |
45 | */ | |
46 | public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) { | |
47 | super(parent); | |
48 | fFilterName = filterName; | |
49 | } | |
50 | ||
51 | /** | |
52 | * @return the filer name | |
53 | */ | |
54 | public String getFilterName() { | |
55 | return fFilterName; | |
56 | } | |
57 | ||
58 | /** | |
59 | * @param filterName the filer name | |
60 | */ | |
61 | public void setFilterName(String filterName) { | |
62 | fFilterName = filterName; | |
63 | } | |
64 | ||
65 | @Override | |
66 | public String getNodeName() { | |
67 | return NODE_NAME; | |
68 | } | |
69 | ||
70 | @Override | |
71 | public boolean matches(ITmfEvent event) { | |
72 | // There should be at most one child | |
73 | for (ITmfFilterTreeNode node : getChildren()) { | |
74 | if (node.matches(event)) { | |
75 | return true; | |
76 | } | |
77 | } | |
78 | return false; | |
79 | } | |
80 | ||
81 | @Override | |
82 | public List<String> getValidChildren() { | |
83 | if (getChildrenCount() == 0) { | |
84 | return super.getValidChildren(); | |
85 | } | |
a4524c1b | 86 | return new ArrayList<>(0); // only one child allowed |
be222f56 PT |
87 | } |
88 | ||
89 | @Override | |
90 | public String toString() { | |
91 | StringBuffer buf = new StringBuffer(); | |
92 | if (getChildrenCount() > 1) { | |
93 | buf.append("( "); //$NON-NLS-1$ | |
94 | } | |
95 | for (int i = 0; i < getChildrenCount(); i++) { | |
96 | ITmfFilterTreeNode node = getChildren()[i]; | |
97 | buf.append(node.toString()); | |
98 | if (i < (getChildrenCount() - 1)) { | |
99 | buf.append(" and "); //$NON-NLS-1$ | |
100 | } | |
101 | } | |
102 | if (getChildrenCount() > 1) { | |
103 | buf.append(" )"); //$NON-NLS-1$ | |
104 | } | |
105 | return buf.toString(); | |
106 | } | |
107 | } |