Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 158999f43749a430755d6ff287f1370f71e5c70c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*******************************************************************************
 * Copyright (c) 2010 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Patrick Tasse - Initial API and implementation
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.core.filter.model;

import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;


/**
 * Filter node for the 'and' operation
 *
 * @version 1.0
 * @author Patrick Tasse
 */
@SuppressWarnings("javadoc")
public class TmfFilterAndNode extends TmfFilterTreeNode {

	public static final String NODE_NAME = "AND"; //$NON-NLS-1$
	public static final String NOT_ATTR = "not"; //$NON-NLS-1$

	private boolean fNot = false;

	/**
	 * @param parent the parent node
	 */
	public TmfFilterAndNode(ITmfFilterTreeNode parent) {
		super(parent);
	}

	/**
	 * @return the NOT state
	 */
	public boolean isNot() {
		return fNot;
	}

	/**
	 * @param not the NOT state
	 */
	public void setNot(boolean not) {
		this.fNot = not;
	}

	@Override
	public String getNodeName() {
		return NODE_NAME;
	}

	@Override
	public boolean matches(ITmfEvent event) {
		for (ITmfFilterTreeNode node : getChildren()) {
			if (! node.matches(event)) {
				return false ^ fNot;
			}
		}
		return true ^ fNot;
	}

	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		if (fNot) {
			buf.append("not "); //$NON-NLS-1$
		}
		if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {
			buf.append("( "); //$NON-NLS-1$
		}
		for (int i = 0; i < getChildrenCount(); i++) {
			ITmfFilterTreeNode node = getChildren()[i];
			buf.append(node.toString());
			if (i < getChildrenCount() - 1) {
				buf.append(" and "); //$NON-NLS-1$
			}
		}
		if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {
			buf.append(" )"); //$NON-NLS-1$
		}
		return buf.toString();
	}

}

Back to the top