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