Commit | Line | Data |
---|---|---|
46ab8ce3 FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
3 | * \r | |
4 | * All rights reserved. This program and the accompanying materials are\r | |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
8 | * \r | |
9 | * Contributors:\r | |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.filter.model;\r |
46ab8ce3 | 14 | \r |
a96d4804 | 15 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r |
46ab8ce3 | 16 | \r |
d37aaa7f FC |
17 | /**\r |
18 | * Filter node for the 'or' operation\r | |
19 | * \r | |
20 | * @version 1.0\r | |
21 | * @author Patrick Tasse\r | |
22 | */\r | |
46ab8ce3 FC |
23 | public class TmfFilterOrNode extends TmfFilterTreeNode {\r |
24 | \r | |
25 | public static final String NODE_NAME = "OR"; //$NON-NLS-1$\r | |
26 | public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r | |
27 | \r | |
28 | private boolean fNot = false;\r | |
29 | \r | |
30 | public TmfFilterOrNode(ITmfFilterTreeNode parent) {\r | |
31 | super(parent);\r | |
32 | }\r | |
33 | \r | |
34 | @Override\r | |
35 | public String getNodeName() {\r | |
36 | return NODE_NAME;\r | |
37 | }\r | |
38 | \r | |
39 | public boolean isNot() {\r | |
40 | return fNot;\r | |
41 | }\r | |
42 | \r | |
43 | public void setNot(boolean not) {\r | |
44 | this.fNot = not;\r | |
45 | }\r | |
46 | \r | |
47 | @Override\r | |
a96d4804 | 48 | public boolean matches(ITmfEvent event) {\r |
46ab8ce3 FC |
49 | for (ITmfFilterTreeNode node : getChildren()) {\r |
50 | if (node.matches(event)) {\r | |
51 | return true ^ fNot;\r | |
52 | }\r | |
53 | }\r | |
54 | return false & fNot;\r | |
55 | }\r | |
56 | \r | |
57 | @Override\r | |
58 | public String toString() {\r | |
59 | StringBuffer buf = new StringBuffer();\r | |
60 | if (fNot) {\r | |
61 | buf.append("not "); //$NON-NLS-1$\r | |
62 | }\r | |
63 | if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {\r | |
64 | buf.append("( "); //$NON-NLS-1$\r | |
65 | }\r | |
66 | for (int i = 0; i < getChildrenCount(); i++) {\r | |
67 | ITmfFilterTreeNode node = getChildren()[i];\r | |
68 | buf.append(node.toString());\r | |
69 | if (i < getChildrenCount() - 1) {\r | |
70 | buf.append(" or "); //$NON-NLS-1$\r | |
71 | }\r | |
72 | }\r | |
73 | if (getParent() != null && !(getParent() instanceof TmfFilterRootNode) && !(getParent() instanceof TmfFilterNode)) {\r | |
74 | buf.append(" )"); //$NON-NLS-1$\r | |
75 | }\r | |
76 | return buf.toString();\r | |
77 | }\r | |
78 | }\r |