Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2010, 2013 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 PT |
14 | |
15 | import java.util.ArrayList; | |
16 | import java.util.List; | |
17 | ||
2bdf0193 | 18 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
be222f56 PT |
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$ | |
d5efe032 | 30 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$ |
be222f56 | 31 | |
d5efe032 | 32 | String fFilterName; |
be222f56 | 33 | |
d5efe032 AF |
34 | /** |
35 | * @param filterName the filter name | |
36 | */ | |
37 | public TmfFilterNode(String filterName) { | |
38 | super(null); | |
39 | fFilterName = filterName; | |
40 | } | |
be222f56 | 41 | |
d5efe032 AF |
42 | /** |
43 | * @param parent the parent node | |
be222f56 | 44 | * @param filterName the filter name |
d5efe032 AF |
45 | */ |
46 | public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) { | |
47 | super(parent); | |
48 | fFilterName = filterName; | |
49 | } | |
be222f56 | 50 | |
d5efe032 AF |
51 | /** |
52 | * @return the filer name | |
53 | */ | |
54 | public String getFilterName() { | |
55 | return fFilterName; | |
56 | } | |
be222f56 | 57 | |
d5efe032 AF |
58 | /** |
59 | * @param filterName the filer name | |
60 | */ | |
61 | public void setFilterName(String filterName) { | |
62 | fFilterName = filterName; | |
63 | } | |
be222f56 | 64 | |
d5efe032 AF |
65 | @Override |
66 | public String getNodeName() { | |
67 | return NODE_NAME; | |
68 | } | |
be222f56 | 69 | |
d5efe032 AF |
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 | } | |
be222f56 | 80 | |
d5efe032 AF |
81 | @Override |
82 | public List<String> getValidChildren() { | |
83 | if (getChildrenCount() == 0) { | |
84 | return super.getValidChildren(); | |
85 | } | |
a4524c1b | 86 | return new ArrayList<>(0); // only one child allowed |
d5efe032 | 87 | } |
be222f56 | 88 | |
d5efe032 AF |
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 | } | |
b64984c4 VP |
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 | } | |
be222f56 | 137 | } |