Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterOrNode.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.core.filter.model;
14
15 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
16
17
18 public class TmfFilterOrNode extends TmfFilterTreeNode {
19
20 public static final String NODE_NAME = "OR"; //$NON-NLS-1$
21 public static final String NOT_ATTR = "not"; //$NON-NLS-1$
22
23 private boolean fNot = false;
24
25 public TmfFilterOrNode(ITmfFilterTreeNode parent) {
26 super(parent);
27 }
28
29 @Override
30 public String getNodeName() {
31 return NODE_NAME;
32 }
33
34 public boolean isNot() {
35 return fNot;
36 }
37
38 public void setNot(boolean not) {
39 this.fNot = not;
40 }
41
42 @Override
43 public boolean matches(ITmfEvent event) {
44 for (ITmfFilterTreeNode node : getChildren()) {
45 if (node.matches(event)) {
46 return true ^ fNot;
47 }
48 }
49 return false & fNot;
50 }
51
52 @Override
53 public String toString() {
54 StringBuffer buf = new StringBuffer();
55 if (fNot) {
56 buf.append("not "); //$NON-NLS-1$
57 }
58 if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {
59 buf.append("( "); //$NON-NLS-1$
60 }
61 for (int i = 0; i < getChildrenCount(); i++) {
62 ITmfFilterTreeNode node = getChildren()[i];
63 buf.append(node.toString());
64 if (i < getChildrenCount() - 1) {
65 buf.append(" or "); //$NON-NLS-1$
66 }
67 }
68 if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {
69 buf.append(" )"); //$NON-NLS-1$
70 }
71 return buf.toString();
72 }
73 }
This page took 0.043893 seconds and 6 git commands to generate.