1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
21 * Filter node for the event match operation
24 * @author Patrick Tasse
26 @SuppressWarnings("javadoc")
27 public class TmfFilterNode
extends TmfFilterTreeNode
{
29 public static final String NODE_NAME
= "FILTER"; //$NON-NLS-1$
30 public static final String NAME_ATTR
= "name"; //$NON-NLS-1$
35 * @param filterName the filter name
37 public TmfFilterNode(String filterName
) {
39 fFilterName
= filterName
;
43 * @param parent the parent node
44 * @param filterName the filter name
46 public TmfFilterNode(ITmfFilterTreeNode parent
, String filterName
) {
48 fFilterName
= filterName
;
52 * @return the filer name
54 public String
getFilterName() {
59 * @param filterName the filer name
61 public void setFilterName(String filterName
) {
62 fFilterName
= filterName
;
66 public String
getNodeName() {
71 public boolean matches(ITmfEvent event
) {
72 // There should be at most one child
73 for (ITmfFilterTreeNode node
: getChildren()) {
74 if (node
.matches(event
)) {
82 public List
<String
> getValidChildren() {
83 if (getChildrenCount() == 0) {
84 return super.getValidChildren();
86 return new ArrayList
<>(0); // only one child allowed
90 public String
toString() {
91 StringBuffer buf
= new StringBuffer();
92 if (getChildrenCount() > 1) {
93 buf
.append("( "); //$NON-NLS-1$
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$
102 if (getChildrenCount() > 1) {
103 buf
.append(" )"); //$NON-NLS-1$
105 return buf
.toString();
109 public int hashCode() {
110 final int prime
= 31;
111 int result
= super.hashCode();
112 result
= prime
* result
+ ((fFilterName
== null) ?
0 : fFilterName
.hashCode());
117 public boolean equals(Object obj
) {
121 if (!super.equals(obj
)) {
124 if (getClass() != obj
.getClass()) {
127 TmfFilterNode other
= (TmfFilterNode
) obj
;
128 if (fFilterName
== null) {
129 if (other
.fFilterName
!= null) {
132 } else if (!fFilterName
.equals(other
.fFilterName
)) {