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