ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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 java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
19
20 /**
21 * Filter node for the event match operation
22 *
23 * @version 1.0
24 * @author Patrick Tasse
25 */
26 @SuppressWarnings("javadoc")
27 public class TmfFilterNode extends TmfFilterTreeNode {
28
29 public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$
30 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
31
32 String fFilterName;
33
34 /**
35 * @param filterName the filter name
36 */
37 public TmfFilterNode(String filterName) {
38 super(null);
39 fFilterName = filterName;
40 }
41
42 /**
43 * @param parent the parent node
44 * @param filterName the filter name
45 */
46 public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) {
47 super(parent);
48 fFilterName = filterName;
49 }
50
51 /**
52 * @return the filer name
53 */
54 public String getFilterName() {
55 return fFilterName;
56 }
57
58 /**
59 * @param filterName the filer name
60 */
61 public void setFilterName(String filterName) {
62 fFilterName = filterName;
63 }
64
65 @Override
66 public String getNodeName() {
67 return NODE_NAME;
68 }
69
70 @Override
71 public boolean matches(ITmfEvent event) {
72 // There should be at most one child
73 for (ITmfFilterTreeNode node : getChildren()) {
74 if (node.matches(event)) {
75 return true;
76 }
77 }
78 return false;
79 }
80
81 @Override
82 public List<String> getValidChildren() {
83 if (getChildrenCount() == 0) {
84 return super.getValidChildren();
85 }
86 return new ArrayList<>(0); // only one child allowed
87 }
88
89 @Override
90 public String toString() {
91 StringBuffer buf = new StringBuffer();
92 if (getChildrenCount() > 1) {
93 buf.append("( "); //$NON-NLS-1$
94 }
95 for (int i = 0; i < getChildrenCount(); i++) {
96 ITmfFilterTreeNode node = getChildren()[i];
97 buf.append(node.toString());
98 if (i < (getChildrenCount() - 1)) {
99 buf.append(" and "); //$NON-NLS-1$
100 }
101 }
102 if (getChildrenCount() > 1) {
103 buf.append(" )"); //$NON-NLS-1$
104 }
105 return buf.toString();
106 }
107
108 @Override
109 public int hashCode() {
110 final int prime = 31;
111 int result = super.hashCode();
112 result = prime * result + ((fFilterName == null) ? 0 : fFilterName.hashCode());
113 return result;
114 }
115
116 @Override
117 public boolean equals(Object obj) {
118 if (this == obj) {
119 return true;
120 }
121 if (!super.equals(obj)) {
122 return false;
123 }
124 if (getClass() != obj.getClass()) {
125 return false;
126 }
127 TmfFilterNode other = (TmfFilterNode) obj;
128 if (fFilterName == null) {
129 if (other.fFilterName != null) {
130 return false;
131 }
132 } else if (!fFilterName.equals(other.fFilterName)) {
133 return false;
134 }
135 return true;
136 }
137 }
This page took 0.037111 seconds and 5 git commands to generate.