analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / filter / model / TmfFilterOrNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 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.tracecompass.tmf.core.filter.model;
14
15 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
16
17 /**
18 * Filter node for the 'or' operation
19 *
20 * @version 1.0
21 * @author Patrick Tasse
22 */
23 public class TmfFilterOrNode extends TmfFilterTreeNode {
24
25 /** or node name */
26 public static final String NODE_NAME = "OR"; //$NON-NLS-1$
27 /** not attribute name */
28 public static final String NOT_ATTR = "not"; //$NON-NLS-1$
29
30 private boolean fNot = false;
31
32 /**
33 * @param parent the parent node
34 */
35 public TmfFilterOrNode(ITmfFilterTreeNode parent) {
36 super(parent);
37 }
38
39 @Override
40 public String getNodeName() {
41 return NODE_NAME;
42 }
43
44 /**
45 * @return the NOT state
46 */
47 public boolean isNot() {
48 return fNot;
49 }
50
51 /**
52 * @param not the NOT state
53 */
54 public void setNot(boolean not) {
55 this.fNot = not;
56 }
57
58 @Override
59 public boolean matches(ITmfEvent event) {
60 for (ITmfFilterTreeNode node : getChildren()) {
61 if (node.matches(event)) {
62 return true ^ fNot;
63 }
64 }
65 return false & fNot;
66 }
67
68 @Override
69 public String toString(boolean explicit) {
70 StringBuffer buf = new StringBuffer();
71 if (fNot) {
72 buf.append("not "); //$NON-NLS-1$
73 }
74 if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {
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(explicit));
80 if (i < getChildrenCount() - 1) {
81 buf.append(" or "); //$NON-NLS-1$
82 }
83 }
84 if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {
85 buf.append(" )"); //$NON-NLS-1$
86 }
87 return buf.toString();
88 }
89 }
This page took 0.032358 seconds and 5 git commands to generate.