blob: e2db82df88730d80a1e76110de5dc2e4491e16d8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*******************************************************************************
* Copyright (c) 2010 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Patrick Tasse - Initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.tmf.filter.model;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfNoSuchFieldException;
public class TmfFilterContainsNode extends TmfFilterTreeNode {
public static final String NODE_NAME = "CONTAINS"; //$NON-NLS-1$
public static final String NOT_ATTR = "not"; //$NON-NLS-1$
public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
public static final String VALUE_ATTR = "value"; //$NON-NLS-1$
public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$
private boolean fNot = false;
private String fField;
private String fValue;
private String fValueUpperCase;
private boolean fIgnoreCase = false;
public TmfFilterContainsNode(ITmfFilterTreeNode parent) {
super(parent);
}
public boolean isNot() {
return fNot;
}
public void setNot(boolean not) {
this.fNot = not;
}
public String getField() {
return fField;
}
public void setField(String field) {
this.fField = field;
}
public String getValue() {
return fValue;
}
public void setValue(String value) {
this.fValue = value;
fValueUpperCase = value.toUpperCase();
}
public boolean isIgnoreCase() {
return fIgnoreCase;
}
public void setIgnoreCase(boolean ignoreCase) {
this.fIgnoreCase = ignoreCase;
}
@Override
public String getNodeName() {
return NODE_NAME;
}
@Override
public boolean matches(TmfEvent event) {
try {
Object value = event.getContent().getField(fField);
if (value == null) {
return false ^ fNot;
}
String valueString = value.toString();
if (fIgnoreCase) {
return valueString.toUpperCase().contains(fValueUpperCase) ^ fNot;
} else {
return valueString.contains(fValue) ^ fNot;
}
} catch (TmfNoSuchFieldException e) {
return false ^ fNot;
}
}
@Override
public List<String> getValidChildren() {
return new ArrayList<String>(0);
}
@Override
public String toString() {
return fField + (fNot ? " not" : "") + " contains \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
@Override
public ITmfFilterTreeNode clone() {
TmfFilterContainsNode clone = (TmfFilterContainsNode) super.clone();
clone.fField = new String(fField);
clone.setValue(new String(fValue));
return clone;
}
}
|