1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
17 import java
.util
.regex
.Pattern
;
18 import java
.util
.regex
.PatternSyntaxException
;
21 * Filter node for the regex match
24 * @author Patrick Tasse
26 @SuppressWarnings("javadoc")
27 public abstract class TmfFilterMatchesNode
extends TmfFilterTreeNode
{
29 public static final String NOT_ATTR
= "not"; //$NON-NLS-1$
30 public static final String REGEX_ATTR
= "regex"; //$NON-NLS-1$
32 private boolean fNot
= false;
34 private String fRegex
;
35 private transient Pattern fPattern
;
41 public TmfFilterMatchesNode(ITmfFilterTreeNode parent
) {
46 * @return the NOT state
48 public boolean isNot() {
56 public void setNot(boolean not
) {
61 * @return the regular expression
63 public String
getRegex() {
69 * the regular expression
71 public void setRegex(String regex
) {
75 this.fPattern
= Pattern
.compile(regex
, Pattern
.DOTALL
);
76 } catch (PatternSyntaxException e
) {
82 protected Pattern
getPattern() {
87 public List
<String
> getValidChildren() {
88 return new ArrayList
<>(0);
92 public ITmfFilterTreeNode
clone() {
93 TmfFilterMatchesNode clone
= (TmfFilterMatchesNode
) super.clone();
94 clone
.setRegex(fRegex
);
100 * the rough regex pattern
101 * @return the compliant regex
103 public static String
regexFix(String pattern
) {
104 String ret
= pattern
;
105 // if the pattern does not contain one of the expressions .* !^
106 // (at the beginning) $ (at the end), then a .* is added at the
107 // beginning and at the end of the pattern
108 if (!(ret
.indexOf(".*") >= 0 || ret
.charAt(0) == '^' || ret
.charAt(ret
.length() - 1) == '$')) { //$NON-NLS-1$
109 ret
= ".*" + ret
+ ".*"; //$NON-NLS-1$ //$NON-NLS-2$
115 public int hashCode() {
116 final int prime
= 31;
117 int result
= super.hashCode();
118 result
= prime
* result
+ (fNot ?
1231 : 1237);
119 result
= prime
* result
+ ((fRegex
== null) ?
0 : fRegex
.hashCode());
124 public boolean equals(Object obj
) {
128 if (!super.equals(obj
)) {
131 if (getClass() != obj
.getClass()) {
134 TmfFilterMatchesNode other
= (TmfFilterMatchesNode
) obj
;
135 if (fNot
!= other
.fNot
) {
138 if (fRegex
== null) {
139 if (other
.fRegex
!= null) {
142 } else if (!fRegex
.equals(other
.fRegex
)) {