Commit | Line | Data |
---|---|---|
46ab8ce3 FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
9b749023 | 3 | *\r |
46ab8ce3 FC |
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 | |
9b749023 | 8 | *\r |
46ab8ce3 FC |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.filter.model;\r |
46ab8ce3 FC |
14 | \r |
15 | import java.util.ArrayList;\r | |
16 | import java.util.List;\r | |
17 | \r | |
a96d4804 | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r |
46ab8ce3 | 19 | \r |
d37aaa7f FC |
20 | /**\r |
21 | * Filter node for the 'contains' operation\r | |
9b749023 | 22 | *\r |
d37aaa7f FC |
23 | * @version 1.0\r |
24 | * @author Patrick Tasse\r | |
25 | */\r | |
0283f7ff | 26 | @SuppressWarnings("javadoc")\r |
46ab8ce3 FC |
27 | public class TmfFilterContainsNode extends TmfFilterTreeNode {\r |
28 | \r | |
29 | public static final String NODE_NAME = "CONTAINS"; //$NON-NLS-1$\r | |
0283f7ff | 30 | public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r |
46ab8ce3 FC |
31 | public static final String FIELD_ATTR = "field"; //$NON-NLS-1$\r |
32 | public static final String VALUE_ATTR = "value"; //$NON-NLS-1$\r | |
33 | public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$\r | |
9b749023 | 34 | \r |
46ab8ce3 FC |
35 | private boolean fNot = false;\r |
36 | private String fField;\r | |
37 | private String fValue;\r | |
38 | private String fValueUpperCase;\r | |
39 | private boolean fIgnoreCase = false;\r | |
9b749023 | 40 | \r |
0283f7ff FC |
41 | /**\r |
42 | * @param parent the parent node\r | |
43 | */\r | |
46ab8ce3 FC |
44 | public TmfFilterContainsNode(ITmfFilterTreeNode parent) {\r |
45 | super(parent);\r | |
46 | }\r | |
47 | \r | |
0283f7ff FC |
48 | /**\r |
49 | * @return the NOT state\r | |
50 | */\r | |
46ab8ce3 FC |
51 | public boolean isNot() {\r |
52 | return fNot;\r | |
53 | }\r | |
9b749023 | 54 | \r |
0283f7ff FC |
55 | /**\r |
56 | * @param not the NOT state\r | |
57 | */\r | |
46ab8ce3 FC |
58 | public void setNot(boolean not) {\r |
59 | this.fNot = not;\r | |
60 | }\r | |
9b749023 | 61 | \r |
0283f7ff FC |
62 | /**\r |
63 | * @return the field name\r | |
64 | */\r | |
46ab8ce3 FC |
65 | public String getField() {\r |
66 | return fField;\r | |
67 | }\r | |
68 | \r | |
0283f7ff FC |
69 | /**\r |
70 | * @param field the field name\r | |
71 | */\r | |
46ab8ce3 FC |
72 | public void setField(String field) {\r |
73 | this.fField = field;\r | |
74 | }\r | |
75 | \r | |
0283f7ff FC |
76 | /**\r |
77 | * @return the contains value\r | |
78 | */\r | |
46ab8ce3 FC |
79 | public String getValue() {\r |
80 | return fValue;\r | |
81 | }\r | |
82 | \r | |
0283f7ff FC |
83 | /**\r |
84 | * @param value the contains value\r | |
85 | */\r | |
46ab8ce3 FC |
86 | public void setValue(String value) {\r |
87 | this.fValue = value;\r | |
88 | fValueUpperCase = value.toUpperCase();\r | |
89 | }\r | |
90 | \r | |
0283f7ff FC |
91 | /**\r |
92 | * @return the ignoreCase state\r | |
93 | */\r | |
46ab8ce3 FC |
94 | public boolean isIgnoreCase() {\r |
95 | return fIgnoreCase;\r | |
96 | }\r | |
9b749023 | 97 | \r |
0283f7ff FC |
98 | /**\r |
99 | * @param ignoreCase the ignoreCase state\r | |
100 | */\r | |
46ab8ce3 FC |
101 | public void setIgnoreCase(boolean ignoreCase) {\r |
102 | this.fIgnoreCase = ignoreCase;\r | |
103 | }\r | |
9b749023 | 104 | \r |
46ab8ce3 FC |
105 | @Override\r |
106 | public String getNodeName() {\r | |
107 | return NODE_NAME;\r | |
108 | }\r | |
109 | \r | |
110 | @Override\r | |
a96d4804 FC |
111 | public boolean matches(ITmfEvent event) {\r |
112 | Object value = getFieldValue(event, fField);\r | |
4c564a2d FC |
113 | if (value == null) {\r |
114 | return false ^ fNot;\r | |
115 | }\r | |
116 | String valueString = value.toString();\r | |
117 | if (fIgnoreCase) {\r | |
118 | return valueString.toUpperCase().contains(fValueUpperCase) ^ fNot;\r | |
4c564a2d | 119 | }\r |
9b749023 | 120 | return valueString.contains(fValue) ^ fNot;\r |
46ab8ce3 FC |
121 | }\r |
122 | \r | |
123 | @Override\r | |
124 | public List<String> getValidChildren() {\r | |
125 | return new ArrayList<String>(0);\r | |
126 | }\r | |
127 | \r | |
128 | @Override\r | |
129 | public String toString() {\r | |
130 | return fField + (fNot ? " not" : "") + " contains \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$\r | |
131 | }\r | |
132 | \r | |
133 | @Override\r | |
134 | public ITmfFilterTreeNode clone() {\r | |
135 | TmfFilterContainsNode clone = (TmfFilterContainsNode) super.clone();\r | |
6e85c58d FC |
136 | clone.fField = fField;\r |
137 | clone.setValue(fValue);\r | |
46ab8ce3 FC |
138 | return clone;\r |
139 | }\r | |
140 | }\r |