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