1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 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 * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation
11 * Patrick Tasse - Refactoring
12 * Vincent Perot - Add subfield filtering
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Arrays
;
19 import java
.util
.List
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
24 * The base class for the Filter tree nodes
27 * @author Yuriy Vashchuk
28 * @author Patrick Tasse
30 public abstract class TmfFilterTreeNode
implements ITmfFilterTreeNode
, Cloneable
{
32 private static final String
[] VALID_CHILDREN
= {
33 TmfFilterTraceTypeNode
.NODE_NAME
,
34 TmfFilterAndNode
.NODE_NAME
,
35 TmfFilterOrNode
.NODE_NAME
,
36 TmfFilterContainsNode
.NODE_NAME
,
37 TmfFilterEqualsNode
.NODE_NAME
,
38 TmfFilterMatchesNode
.NODE_NAME
,
39 TmfFilterCompareNode
.NODE_NAME
42 private ITmfFilterTreeNode parent
= null;
43 private ArrayList
<ITmfFilterTreeNode
> children
= new ArrayList
<>();
49 public TmfFilterTreeNode(final ITmfFilterTreeNode parent
) {
51 parent
.addChild(this);
56 public ITmfFilterTreeNode
getParent() {
61 public abstract String
getNodeName();
64 public boolean hasChildren() {
65 return (children
.size() > 0);
69 public int getChildrenCount() {
70 return children
.size();
74 public ITmfFilterTreeNode
[] getChildren() {
75 return children
.toArray(new ITmfFilterTreeNode
[0]);
79 public ITmfFilterTreeNode
getChild(final int index
) throws IndexOutOfBoundsException
{
80 return children
.get(index
);
84 public ITmfFilterTreeNode
remove() {
85 if (getParent() != null) {
86 getParent().removeChild(this);
92 public ITmfFilterTreeNode
removeChild(ITmfFilterTreeNode node
) {
93 children
.remove(node
);
99 public int addChild(final ITmfFilterTreeNode node
) {
100 node
.setParent(this);
101 if (children
.add(node
)) {
102 return (children
.size() - 1);
108 public ITmfFilterTreeNode
replaceChild(final int index
, final ITmfFilterTreeNode node
) throws IndexOutOfBoundsException
{
109 node
.setParent(this);
110 return children
.set(index
, node
);
114 public void setParent(final ITmfFilterTreeNode parent
) {
115 this.parent
= parent
;
119 public abstract boolean matches(ITmfEvent event
);
122 public List
<String
> getValidChildren() {
123 return Arrays
.asList(VALID_CHILDREN
);
127 public ITmfFilterTreeNode
clone() {
129 TmfFilterTreeNode clone
= (TmfFilterTreeNode
) super.clone();
131 clone
.children
= new ArrayList
<>(children
.size());
132 for (ITmfFilterTreeNode child
: getChildren()) {
133 clone
.addChild(child
.clone());
136 } catch (CloneNotSupportedException e
) {
142 public String
toString() {
143 return toString(false);