~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.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
public class TmfFilterNode extends TmfFilterTreeNode {
 
27
 
 
28
        public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$
 
29
        public static final String NAME_ATTR = "name"; //$NON-NLS-1$
 
30
 
 
31
        String fFilterName;
 
32
 
 
33
        public TmfFilterNode(String filterName) {
 
34
                super(null);
 
35
                fFilterName = filterName;
 
36
        }
 
37
 
 
38
        public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) {
 
39
                super(parent);
 
40
                fFilterName = filterName;
 
41
        }
 
42
 
 
43
        public String getFilterName() {
 
44
                return fFilterName;
 
45
        }
 
46
 
 
47
        public void setFilterName(String filterName) {
 
48
                fFilterName = filterName;
 
49
        }
 
50
 
 
51
        @Override
 
52
        public String getNodeName() {
 
53
                return NODE_NAME;
 
54
        }
 
55
 
 
56
        @Override
 
57
        public boolean matches(ITmfEvent event) {
 
58
                // There should be at most one child
 
59
                for (ITmfFilterTreeNode node : getChildren()) {
 
60
                        if (node.matches(event)) {
 
61
                                return true;
 
62
                        }
 
63
                }
 
64
                return false;
 
65
        }
 
66
 
 
67
        @Override
 
68
        public List<String> getValidChildren() {
 
69
                if (getChildrenCount() == 0) {
 
70
                        return super.getValidChildren();
 
71
                }
 
72
        return new ArrayList<String>(0); // only one child allowed
 
73
        }
 
74
 
 
75
        @Override
 
76
        public String toString() {
 
77
                StringBuffer buf = new StringBuffer();
 
78
                if (getChildrenCount() > 1) {
 
79
                        buf.append("( "); //$NON-NLS-1$
 
80
                }
 
81
                for (int i = 0; i < getChildrenCount(); i++) {
 
82
                        ITmfFilterTreeNode node = getChildren()[i];
 
83
                        buf.append(node.toString());
 
84
                        if (i < (getChildrenCount() - 1)) {
 
85
                                buf.append(" and "); //$NON-NLS-1$
 
86
                        }
 
87
                }
 
88
                if (getChildrenCount() > 1) {
 
89
                        buf.append(" )"); //$NON-NLS-1$
 
90
                }
 
91
                return buf.toString();
 
92
        }
 
93
}