tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterAndNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 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 @SuppressWarnings("javadoc")
25 public class TmfFilterAndNode extends TmfFilterTreeNode {
26
27 public static final String NODE_NAME = "AND"; //$NON-NLS-1$
28 public static final String NOT_ATTR = "not"; //$NON-NLS-1$
29
30 private boolean fNot = false;
31
32 /**
33 * @param parent the parent node
34 */
35 public TmfFilterAndNode(ITmfFilterTreeNode parent) {
36 super(parent);
37 }
38
39 /**
40 * @return the NOT state
41 */
42 public boolean isNot() {
43 return fNot;
44 }
45
46 /**
47 * @param not the NOT state
48 */
49 public void setNot(boolean not) {
50 this.fNot = not;
51 }
52
53 @Override
54 public String getNodeName() {
55 return NODE_NAME;
56 }
57
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 }
67
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 }
89
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
116 }
This page took 0.032525 seconds and 5 git commands to generate.