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