Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / 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.core.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
19
20
21 public class TmfFilterContainsNode extends TmfFilterTreeNode {
22
23 public static final String NODE_NAME = "CONTAINS"; //$NON-NLS-1$
24 public static final String NOT_ATTR = "not"; //$NON-NLS-1$
25 public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
26 public static final String VALUE_ATTR = "value"; //$NON-NLS-1$
27 public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$
28
29 private boolean fNot = false;
30 private String fField;
31 private String fValue;
32 private String fValueUpperCase;
33 private boolean fIgnoreCase = false;
34
35 public TmfFilterContainsNode(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 fValueUpperCase = value.toUpperCase();
62 }
63
64 public boolean isIgnoreCase() {
65 return fIgnoreCase;
66 }
67
68 public void setIgnoreCase(boolean ignoreCase) {
69 this.fIgnoreCase = ignoreCase;
70 }
71
72 @Override
73 public String getNodeName() {
74 return NODE_NAME;
75 }
76
77 @Override
78 public boolean matches(ITmfEvent event) {
79 Object value = getFieldValue(event, fField);
80 if (value == null) {
81 return false ^ fNot;
82 }
83 String valueString = value.toString();
84 if (fIgnoreCase) {
85 return valueString.toUpperCase().contains(fValueUpperCase) ^ fNot;
86 } else {
87 return valueString.contains(fValue) ^ fNot;
88 }
89 }
90
91 @Override
92 public List<String> getValidChildren() {
93 return new ArrayList<String>(0);
94 }
95
96 @Override
97 public String toString() {
98 return fField + (fNot ? " not" : "") + " contains \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
99 }
100
101 @Override
102 public ITmfFilterTreeNode clone() {
103 TmfFilterContainsNode clone = (TmfFilterContainsNode) super.clone();
104 clone.fField = fField;
105 clone.setValue(fValue);
106 return clone;
107 }
108 }
This page took 0.03369 seconds and 6 git commands to generate.