1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
;
15 import java
.util
.regex
.Pattern
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
20 * Filter node that matches on an event field (using a field ID).
22 * @author Alexandre Montplaisir
24 public final class TmfFilterMatchesFieldNode
extends TmfFilterMatchesNode
{
26 /** Name/ID of this node */
27 public static final String NODE_NAME
= "MATCHES"; //$NON-NLS-1$
28 /** The string attribute of this node type */
29 public static final String FIELD_ATTR
= "field"; //$NON-NLS-1$
31 private String fField
;
39 public TmfFilterMatchesFieldNode(ITmfFilterTreeNode parent
) {
44 public String
getNodeName() {
49 public boolean matches(ITmfEvent event
) {
50 Pattern pattern
= getPattern();
51 boolean isNot
= isNot();
53 if (pattern
== null) {
57 Object value
= getFieldValue(event
, fField
);
61 String valueString
= value
.toString();
63 return pattern
.matcher(valueString
).matches() ^ isNot
;
67 * @return the field name
69 public String
getField() {
77 public void setField(String field
) {
82 public ITmfFilterTreeNode
clone() {
83 TmfFilterMatchesFieldNode clone
= (TmfFilterMatchesFieldNode
) super.clone();
84 clone
.fField
= fField
;
89 public String
toString() {
90 return fField
+ (isNot() ?
" not" : "") + " matches \"" + getRegex() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
94 public int hashCode() {
96 int result
= super.hashCode();
97 result
= prime
* result
+ ((fField
== null) ?
0 : fField
.hashCode());
102 public boolean equals(Object obj
) {
106 if (!super.equals(obj
)) {
109 if (getClass() != obj
.getClass()) {
112 TmfFilterMatchesFieldNode other
= (TmfFilterMatchesFieldNode
) obj
;
113 if (fField
== null) {
114 if (other
.fField
!= null) {
117 } else if (!fField
.equals(other
.fField
)) {