ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterEqualsNode.java
CommitLineData
be222f56 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2010, 2013 Ericsson
be222f56
PT
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.core.filter.model;
14
15import java.util.ArrayList;
16import java.util.List;
17
18import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
19
20
21/**
22 * Filter node for the '==' operation
23 *
24 * @version 1.0
25 * @author Patrick Tasse
26 */
27@SuppressWarnings("javadoc")
28public class TmfFilterEqualsNode extends TmfFilterTreeNode {
29
30 public static final String NODE_NAME = "EQUALS"; //$NON-NLS-1$
d5efe032
AF
31 public static final String NOT_ATTR = "not"; //$NON-NLS-1$
32 public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
33 public static final String VALUE_ATTR = "value"; //$NON-NLS-1$
34 public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$
35
36 private boolean fNot = false;
37 private String fField;
38 private String fValue;
39 private boolean fIgnoreCase = false;
40
41 /**
42 * @param parent the aprent node
43 */
44 public TmfFilterEqualsNode(ITmfFilterTreeNode parent) {
45 super(parent);
46 }
47
48 /**
49 * @return the NOT state
50 */
51 public boolean isNot() {
52 return fNot;
53 }
54
55 /**
56 * @param not the NOT state
57 */
58 public void setNot(boolean not) {
59 this.fNot = not;
60 }
be222f56
PT
61
62 /**
63 * @return the field name
64 */
d5efe032
AF
65 public String getField() {
66 return fField;
67 }
68
69 /**
70 * @param field the field name
71 */
72 public void setField(String field) {
73 this.fField = field;
74 }
75
76 /**
77 * @return the equals value
78 */
79 public String getValue() {
80 return fValue;
81 }
82
83 /**
84 * @param value the equals value
85 */
86 public void setValue(String value) {
87 this.fValue = value;
88 }
89
90 /**
91 * @return the ignoreCase state
92 */
93 public boolean isIgnoreCase() {
94 return fIgnoreCase;
95 }
96
97 /**
98 * @param ignoreCase the ignoreCase state
99 */
100 public void setIgnoreCase(boolean ignoreCase) {
101 this.fIgnoreCase = ignoreCase;
102 }
103
104 @Override
105 public String getNodeName() {
106 return NODE_NAME;
107 }
108
109 @Override
110 public boolean matches(ITmfEvent event) {
be222f56
PT
111 Object value = getFieldValue(event, fField);
112 if (value == null) {
113 return false ^ fNot;
114 }
115 String valueString = value.toString();
116 if (valueString == null) {
117 return false ^ fNot;
118 }
119 if (fIgnoreCase) {
120 return valueString.equalsIgnoreCase(fValue) ^ fNot;
121 }
122 return valueString.equals(fValue) ^ fNot;
d5efe032
AF
123 }
124
125 @Override
126 public List<String> getValidChildren() {
127 return new ArrayList<>(0);
128 }
129
130 @Override
131 public String toString() {
132 return fField + (fNot ? " not" : "") + " equals \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
133 }
134
135 @Override
136 public ITmfFilterTreeNode clone() {
137 TmfFilterEqualsNode clone = (TmfFilterEqualsNode) super.clone();
138 clone.fField = fField;
139 clone.fValue = fValue;
140 return clone;
141 }
b64984c4
VP
142
143 @Override
144 public int hashCode() {
145 final int prime = 31;
146 int result = super.hashCode();
147 result = prime * result + ((fField == null) ? 0 : fField.hashCode());
148 result = prime * result + (fIgnoreCase ? 1231 : 1237);
149 result = prime * result + (fNot ? 1231 : 1237);
150 result = prime * result + ((fValue == null) ? 0 : fValue.hashCode());
151 return result;
152 }
153
154 @Override
155 public boolean equals(Object obj) {
156 if (this == obj) {
157 return true;
158 }
159 if (!super.equals(obj)) {
160 return false;
161 }
162 if (getClass() != obj.getClass()) {
163 return false;
164 }
165 TmfFilterEqualsNode other = (TmfFilterEqualsNode) obj;
166 if (fField == null) {
167 if (other.fField != null) {
168 return false;
169 }
170 } else if (!fField.equals(other.fField)) {
171 return false;
172 }
173 if (fIgnoreCase != other.fIgnoreCase) {
174 return false;
175 }
176 if (fNot != other.fNot) {
177 return false;
178 }
179 if (fValue == null) {
180 if (other.fValue != null) {
181 return false;
182 }
183 } else if (!fValue.equals(other.fValue)) {
184 return false;
185 }
186 return true;
187 }
be222f56 188}
This page took 0.074852 seconds and 5 git commands to generate.