Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterMatchesNode.java
index 8d2c35c87597b8badc53cbd0f8b284f2e96fbe15..eb3d5ae48e7149e22cb5610ec24471515ec350f1 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *   Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.core.filter.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.regex.Pattern;\r
-import java.util.regex.PatternSyntaxException;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-\r
-/**\r
- * Filter node for the regex match\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-@SuppressWarnings("javadoc")\r
-public class TmfFilterMatchesNode extends TmfFilterTreeNode {\r
-\r
-    public static final String NODE_NAME = "MATCHES"; //$NON-NLS-1$\r
-       public static final String NOT_ATTR = "not"; //$NON-NLS-1$\r
-       public static final String FIELD_ATTR = "field"; //$NON-NLS-1$\r
-       public static final String REGEX_ATTR = "regex"; //$NON-NLS-1$\r
-\r
-       private boolean fNot = false;\r
-       private String fField;\r
-       private String fRegex;\r
-       private Pattern fPattern;\r
-\r
-       /**\r
-        * @param parent the parent node\r
-        */\r
-       public TmfFilterMatchesNode(ITmfFilterTreeNode parent) {\r
-               super(parent);\r
-       }\r
-\r
-       /**\r
-        * @return the NOT state\r
-        */\r
-       public boolean isNot() {\r
-               return fNot;\r
-       }\r
-\r
-       /**\r
-        * @param not the NOT state\r
-        */\r
-       public void setNot(boolean not) {\r
-               this.fNot = not;\r
-       }\r
-\r
-       /**\r
-        * @return the field name\r
-        */\r
-       public String getField() {\r
-               return fField;\r
-       }\r
-\r
-       /**\r
-        * @param field the field name\r
-        */\r
-       public void setField(String field) {\r
-               this.fField = field;\r
-       }\r
-\r
-       /**\r
-        * @return the regular expression\r
-        */\r
-       public String getRegex() {\r
-               return fRegex;\r
-       }\r
-\r
-       /**\r
-        * @param regex the regular expression\r
-        */\r
-       public void setRegex(String regex) {\r
-               this.fRegex = regex;\r
-               try {\r
-                       this.fPattern = Pattern.compile(regex);\r
-               } catch (PatternSyntaxException e) {\r
-                       this.fPattern = null;\r
-               }\r
-       }\r
-\r
-       @Override\r
-       public String getNodeName() {\r
-               return NODE_NAME;\r
-       }\r
-\r
-       @Override\r
-       public boolean matches(ITmfEvent event) {\r
-        if (fPattern == null) {\r
-            return false ^ fNot;\r
-        }\r
-\r
-        Object value = getFieldValue(event, fField);\r
-        if (value == null) {\r
-            return false ^ fNot;\r
-        }\r
-        String valueString = value.toString();\r
-\r
-        return fPattern.matcher(valueString).matches() ^ fNot;\r
-       }\r
-\r
-       @Override\r
-       public List<String> getValidChildren() {\r
-               return new ArrayList<String>(0);\r
-       }\r
-\r
-       @Override\r
-       public String toString() {\r
-               return fField + (fNot ? " not" : "") + " matches \"" + fRegex + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$\r
-       }\r
-\r
-       @Override\r
-       public ITmfFilterTreeNode clone() {\r
-               TmfFilterMatchesNode clone = (TmfFilterMatchesNode) super.clone();\r
-               clone.fField = fField;\r
-               clone.setRegex(fRegex);\r
-               return clone;\r
-       }\r
-\r
-       /**\r
-        * @param pattern the rough regex pattern\r
-        * @return the compliant regex\r
-        */\r
-       public static String regexFix(String pattern) {\r
-               // if the pattern does not contain one of the expressions .* !^\r
-               // (at the beginning) $ (at the end), then a .* is added at the\r
-               // beginning and at the end of the pattern\r
-               if (!(pattern.indexOf(".*") >= 0 || pattern.charAt(0) == '^' || pattern.charAt(pattern.length() - 1) == '$')) { //$NON-NLS-1$\r
-                       pattern = ".*" + pattern + ".*"; //$NON-NLS-1$ //$NON-NLS-2$\r
-               }\r
-               return pattern;\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * Filter node for the regex match
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterMatchesNode extends TmfFilterTreeNode {
+
+    public static final String NODE_NAME = "MATCHES"; //$NON-NLS-1$
+       public static final String NOT_ATTR = "not"; //$NON-NLS-1$
+       public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
+       public static final String REGEX_ATTR = "regex"; //$NON-NLS-1$
+
+       private boolean fNot = false;
+       private String fField;
+       private String fRegex;
+       private Pattern fPattern;
+
+       /**
+        * @param parent the parent node
+        */
+       public TmfFilterMatchesNode(ITmfFilterTreeNode parent) {
+               super(parent);
+       }
+
+       /**
+        * @return the NOT state
+        */
+       public boolean isNot() {
+               return fNot;
+       }
+
+       /**
+        * @param not the NOT state
+        */
+       public void setNot(boolean not) {
+               this.fNot = not;
+       }
+
+       /**
+        * @return the field name
+        */
+       public String getField() {
+               return fField;
+       }
+
+       /**
+        * @param field the field name
+        */
+       public void setField(String field) {
+               this.fField = field;
+       }
+
+       /**
+        * @return the regular expression
+        */
+       public String getRegex() {
+               return fRegex;
+       }
+
+       /**
+        * @param regex the regular expression
+        */
+       public void setRegex(String regex) {
+               this.fRegex = regex;
+               try {
+                       this.fPattern = Pattern.compile(regex);
+               } catch (PatternSyntaxException e) {
+                       this.fPattern = null;
+               }
+       }
+
+       @Override
+       public String getNodeName() {
+               return NODE_NAME;
+       }
+
+       @Override
+       public boolean matches(ITmfEvent event) {
+        if (fPattern == null) {
+            return false ^ fNot;
+        }
+
+        Object value = getFieldValue(event, fField);
+        if (value == null) {
+            return false ^ fNot;
+        }
+        String valueString = value.toString();
+
+        return fPattern.matcher(valueString).matches() ^ fNot;
+       }
+
+       @Override
+       public List<String> getValidChildren() {
+               return new ArrayList<String>(0);
+       }
+
+       @Override
+       public String toString() {
+               return fField + (fNot ? " not" : "") + " matches \"" + fRegex + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+       }
+
+       @Override
+       public ITmfFilterTreeNode clone() {
+               TmfFilterMatchesNode clone = (TmfFilterMatchesNode) super.clone();
+               clone.fField = fField;
+               clone.setRegex(fRegex);
+               return clone;
+       }
+
+       /**
+        * @param pattern the rough regex pattern
+        * @return the compliant regex
+        */
+       public static String regexFix(String pattern) {
+               // if the pattern does not contain one of the expressions .* !^
+               // (at the beginning) $ (at the end), then a .* is added at the
+               // beginning and at the end of the pattern
+               if (!(pattern.indexOf(".*") >= 0 || pattern.charAt(0) == '^' || pattern.charAt(pattern.length() - 1) == '$')) { //$NON-NLS-1$
+                       pattern = ".*" + pattern + ".*"; //$NON-NLS-1$ //$NON-NLS-2$
+               }
+               return pattern;
+       }
+}
This page took 0.048059 seconds and 5 git commands to generate.