tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterContainsNode.java
CommitLineData
be222f56
PT
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
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 * Filter node for the 'contains' operation
22 *
23 * @version 1.0
24 * @author Patrick Tasse
25 */
26@SuppressWarnings("javadoc")
27public class TmfFilterContainsNode extends TmfFilterTreeNode {
28
29 public static final String NODE_NAME = "CONTAINS"; //$NON-NLS-1$
30 public static final String NOT_ATTR = "not"; //$NON-NLS-1$
31 public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
32 public static final String VALUE_ATTR = "value"; //$NON-NLS-1$
33 public static final String IGNORECASE_ATTR = "ignorecase"; //$NON-NLS-1$
34
35 private boolean fNot = false;
36 private String fField;
37 private String fValue;
38 private String fValueUpperCase;
39 private boolean fIgnoreCase = false;
40
41 /**
42 * @param parent the parent node
43 */
44 public TmfFilterContainsNode(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 }
61
62 /**
63 * @return the field name
64 */
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 contains value
78 */
79 public String getValue() {
80 return fValue;
81 }
82
83 /**
84 * @param value the contains value
85 */
86 public void setValue(String value) {
87 this.fValue = value;
88 fValueUpperCase = value.toUpperCase();
89 }
90
91 /**
92 * @return the ignoreCase state
93 */
94 public boolean isIgnoreCase() {
95 return fIgnoreCase;
96 }
97
98 /**
99 * @param ignoreCase the ignoreCase state
100 */
101 public void setIgnoreCase(boolean ignoreCase) {
102 this.fIgnoreCase = ignoreCase;
103 }
104
105 @Override
106 public String getNodeName() {
107 return NODE_NAME;
108 }
109
110 @Override
111 public boolean matches(ITmfEvent event) {
112 Object value = getFieldValue(event, fField);
113 if (value == null) {
114 return false ^ fNot;
115 }
116 String valueString = value.toString();
117 if (fIgnoreCase) {
118 return valueString.toUpperCase().contains(fValueUpperCase) ^ fNot;
119 }
120 return valueString.contains(fValue) ^ fNot;
121 }
122
123 @Override
124 public List<String> getValidChildren() {
125 return new ArrayList<String>(0);
126 }
127
128 @Override
129 public String toString() {
130 return fField + (fNot ? " not" : "") + " contains \"" + fValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
131 }
132
133 @Override
134 public ITmfFilterTreeNode clone() {
135 TmfFilterContainsNode clone = (TmfFilterContainsNode) super.clone();
136 clone.fField = fField;
137 clone.setValue(fValue);
138 return clone;
139 }
140}
This page took 0.031246 seconds and 5 git commands to generate.