Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2010, 2014 Ericsson |
be222f56 PT |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.filter.model; |
be222f56 | 14 | |
2bdf0193 | 15 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
be222f56 PT |
16 | |
17 | ||
18 | /** | |
19 | * Filter node for the 'and' operation | |
20 | * | |
21 | * @version 1.0 | |
22 | * @author Patrick Tasse | |
23 | */ | |
24 | @SuppressWarnings("javadoc") | |
25 | public class TmfFilterAndNode extends TmfFilterTreeNode { | |
26 | ||
d5efe032 AF |
27 | public static final String NODE_NAME = "AND"; //$NON-NLS-1$ |
28 | public static final String NOT_ATTR = "not"; //$NON-NLS-1$ | |
be222f56 | 29 | |
d5efe032 | 30 | private boolean fNot = false; |
be222f56 | 31 | |
d5efe032 AF |
32 | /** |
33 | * @param parent the parent node | |
34 | */ | |
35 | public TmfFilterAndNode(ITmfFilterTreeNode parent) { | |
36 | super(parent); | |
37 | } | |
be222f56 | 38 | |
d5efe032 AF |
39 | /** |
40 | * @return the NOT state | |
41 | */ | |
42 | public boolean isNot() { | |
43 | return fNot; | |
44 | } | |
be222f56 | 45 | |
d5efe032 AF |
46 | /** |
47 | * @param not the NOT state | |
48 | */ | |
49 | public void setNot(boolean not) { | |
50 | this.fNot = not; | |
51 | } | |
be222f56 | 52 | |
d5efe032 AF |
53 | @Override |
54 | public String getNodeName() { | |
55 | return NODE_NAME; | |
56 | } | |
be222f56 | 57 | |
d5efe032 AF |
58 | @Override |
59 | public boolean matches(ITmfEvent event) { | |
60 | for (ITmfFilterTreeNode node : getChildren()) { | |
61 | if (! node.matches(event)) { | |
62 | return false ^ fNot; | |
63 | } | |
64 | } | |
65 | return true ^ fNot; | |
66 | } | |
be222f56 | 67 | |
d5efe032 AF |
68 | @Override |
69 | public String toString() { | |
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()); | |
80 | if (i < getChildrenCount() - 1) { | |
81 | buf.append(" and "); //$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 | } | |
be222f56 | 89 | |
b64984c4 VP |
90 | @Override |
91 | public int hashCode() { | |
92 | final int prime = 31; | |
93 | int result = super.hashCode(); | |
94 | result = prime * result + (fNot ? 1231 : 1237); | |
95 | return result; | |
96 | } | |
97 | ||
98 | @Override | |
99 | public boolean equals(Object obj) { | |
100 | if (this == obj) { | |
101 | return true; | |
102 | } | |
103 | if (!super.equals(obj)) { | |
104 | return false; | |
105 | } | |
106 | if (getClass() != obj.getClass()) { | |
107 | return false; | |
108 | } | |
109 | TmfFilterAndNode other = (TmfFilterAndNode) obj; | |
110 | if (fNot != other.fNot) { | |
111 | return false; | |
112 | } | |
113 | return true; | |
114 | } | |
115 | ||
be222f56 | 116 | } |