Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterEqualsNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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.linuxtools.tmf.core.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
19 import org.eclipse.linuxtools.tmf.core.event.TmfNoSuchFieldException;
20
21
22 public class TmfFilterEqualsNode extends TmfFilterTreeNode {
23
24 public static final String NODE_NAME = "EQUALS"; //$NON-NLS-1$
25 public static final String NOT_ATTR = "not"; //$NON-NLS-1$
26 public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
27 public static final String VALUE_ATTR = "value"; //$NON-NLS-1$
28 public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$
29
30 private boolean fNot = false;
31 private String fField;
32 private String fValue;
33 private boolean fIgnoreCase = false;
34
35 public TmfFilterEqualsNode(ITmfFilterTreeNode parent) {
36 super(parent);
37 }
38
39 public boolean isNot() {
40 return fNot;
41 }
42
43 public void setNot(boolean not) {
44 this.fNot = not;
45 }
46
47 public String getField() {
48 return fField;
49 }
50
51 public void setField(String field) {
52 this.fField = field;
53 }
54
55 public String getValue() {
56 return fValue;
57 }
58
59 public void setValue(String value) {
60 this.fValue = value;
61 }
62
63 public boolean isIgnoreCase() {
64 return fIgnoreCase;
65 }
66
67 public void setIgnoreCase(boolean ignoreCase) {
68 this.fIgnoreCase = ignoreCase;
69 }
70
71 @Override
72 public String getNodeName() {
73 return NODE_NAME;
74 }
75
76 @Override
77 public boolean matches(TmfEvent event) {
78 try {
79 Object value = event.getContent().getField(fField);
80 if (value == null) {
81 return false ^ fNot;
82 }
83 String valueString = value.toString();
84 if (valueString == null) {
85 return false ^ fNot;
86 }
87 if (fIgnoreCase) {
88 return valueString.equalsIgnoreCase(fValue) ^ fNot;
89 } else {
90 return valueString.equals(fValue) ^ fNot;
91 }
92 } catch (TmfNoSuchFieldException e) {
93 return false ^ fNot;
94 }
95 }
96
97 @Override
98 public List<String> getValidChildren() {
99 return new ArrayList<String>(0);
100 }
101
102 @Override
103 public String toString() {
104 return fField + (fNot ? " not" : "") + " equals \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
105 }
106
107 @Override
108 public ITmfFilterTreeNode clone() {
109 TmfFilterEqualsNode clone = (TmfFilterEqualsNode) super.clone();
110 clone.fField = new String(fField);
111 clone.fValue = new String(fValue);
112 return clone;
113 }
114 }
This page took 0.046689 seconds and 5 git commands to generate.