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