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 | |
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 | |
6c13869b FC |
18 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r |
19 | import org.eclipse.linuxtools.tmf.core.event.TmfNoSuchFieldException;\r | |
46ab8ce3 FC |
20 | \r |
21 | \r | |
22 | public class TmfFilterEqualsNode extends TmfFilterTreeNode {\r | |
23 | \r | |
24 | public static final String NODE_NAME = "EQUALS"; //$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 boolean fIgnoreCase = false;\r | |
34 | \r | |
35 | public TmfFilterEqualsNode(ITmfFilterTreeNode parent) {\r | |
36 | super(parent);\r | |
37 | }\r | |
38 | \r | |
39 | public boolean isNot() {\r | |
40 | return fNot;\r | |
41 | }\r | |
42 | \r | |
43 | public void setNot(boolean not) {\r | |
44 | this.fNot = not;\r | |
45 | }\r | |
46 | \r | |
47 | public String getField() {\r | |
48 | return fField;\r | |
49 | }\r | |
50 | \r | |
51 | public void setField(String field) {\r | |
52 | this.fField = field;\r | |
53 | }\r | |
54 | \r | |
55 | public String getValue() {\r | |
56 | return fValue;\r | |
57 | }\r | |
58 | \r | |
59 | public void setValue(String value) {\r | |
60 | this.fValue = value;\r | |
61 | }\r | |
62 | \r | |
63 | public boolean isIgnoreCase() {\r | |
64 | return fIgnoreCase;\r | |
65 | }\r | |
66 | \r | |
67 | public void setIgnoreCase(boolean ignoreCase) {\r | |
68 | this.fIgnoreCase = ignoreCase;\r | |
69 | }\r | |
70 | \r | |
71 | @Override\r | |
72 | public String getNodeName() {\r | |
73 | return NODE_NAME;\r | |
74 | }\r | |
75 | \r | |
76 | @Override\r | |
77 | public boolean matches(TmfEvent event) {\r | |
78 | try {\r | |
79 | Object value = event.getContent().getField(fField);\r | |
80 | if (value == null) {\r | |
81 | return false ^ fNot;\r | |
82 | }\r | |
83 | String valueString = value.toString();\r | |
84 | if (valueString == null) {\r | |
85 | return false ^ fNot;\r | |
86 | }\r | |
87 | if (fIgnoreCase) {\r | |
88 | return valueString.equalsIgnoreCase(fValue) ^ fNot;\r | |
89 | } else {\r | |
90 | return valueString.equals(fValue) ^ fNot;\r | |
91 | }\r | |
92 | } catch (TmfNoSuchFieldException e) {\r | |
93 | return false ^ fNot;\r | |
94 | }\r | |
95 | }\r | |
96 | \r | |
97 | @Override\r | |
98 | public List<String> getValidChildren() {\r | |
99 | return new ArrayList<String>(0);\r | |
100 | }\r | |
101 | \r | |
102 | @Override\r | |
103 | public String toString() {\r | |
104 | return fField + (fNot ? " not" : "") + " equals \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$\r | |
105 | }\r | |
106 | \r | |
107 | @Override\r | |
108 | public ITmfFilterTreeNode clone() {\r | |
109 | TmfFilterEqualsNode clone = (TmfFilterEqualsNode) super.clone();\r | |
110 | clone.fField = new String(fField);\r | |
111 | clone.fValue = new String(fValue);\r | |
112 | return clone;\r | |
113 | }\r | |
114 | }\r |