tmf: implement hashcode and equals on filter classes
authorVincent Perot <vincent.perot@ericsson.com>
Tue, 5 Aug 2014 20:55:13 +0000 (16:55 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 6 Aug 2014 21:45:45 +0000 (17:45 -0400)
Change-Id: Ic72c475995aaf63f3cb2cff83c4a7de395543f30
Signed-off-by: Vincent Perot <vincent.perot@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/31062
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterAndNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterContainsNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEqualsNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterMatchesNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterOrNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java

index 2c054252dc172e97152461ad5f826f963600046f..6aaef336d4cbf9c78a569eae7d63646d52baf20a 100644 (file)
@@ -87,4 +87,30 @@ public class TmfFilterAndNode extends TmfFilterTreeNode {
         return buf.toString();
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + (fNot ? 1231 : 1237);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterAndNode other = (TmfFilterAndNode) obj;
+        if (fNot != other.fNot) {
+            return false;
+        }
+        return true;
+    }
+
 }
index a452753ab4e768a663f036fb943be0f3f7cdc5f3..0037532e93a15b765636eb1fd13ce455f94f3d1d 100644 (file)
@@ -51,8 +51,8 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
     private int fResult;
     private Type fType = Type.NUM;
     private String fValue;
-    private Number fValueNumber;
-    private TmfTimestamp fValueTimestamp;
+    private transient Number fValueNumber;
+    private transient TmfTimestamp fValueTimestamp;
 
     /**
      * @param parent the parent node
@@ -217,4 +217,54 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode {
         clone.setValue(fValue);
         return clone;
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fField == null) ? 0 : fField.hashCode());
+        result = prime * result + (fNot ? 1231 : 1237);
+        result = prime * result + fResult;
+        result = prime * result + ((fType == null) ? 0 : fType.hashCode());
+        result = prime * result + ((fValue == null) ? 0 : fValue.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterCompareNode other = (TmfFilterCompareNode) obj;
+        if (fField == null) {
+            if (other.fField != null) {
+                return false;
+            }
+        } else if (!fField.equals(other.fField)) {
+            return false;
+        }
+        if (fNot != other.fNot) {
+            return false;
+        }
+        if (fResult != other.fResult) {
+            return false;
+        }
+        if (fType != other.fType) {
+            return false;
+        }
+        if (fValue == null) {
+            if (other.fValue != null) {
+                return false;
+            }
+        } else if (!fValue.equals(other.fValue)) {
+            return false;
+        }
+        return true;
+    }
 }
index ee91c7d0ef24a537de8509dd54cd39d76a8590b0..798787d623eecf55b693cb8a8bfcbe4bf59a6f93 100644 (file)
@@ -35,7 +35,7 @@ public class TmfFilterContainsNode extends TmfFilterTreeNode {
     private boolean fNot = false;
     private String fField;
     private String fValue;
-    private String fValueUpperCase;
+    private transient String fValueUpperCase;
     private boolean fIgnoreCase = false;
 
     /**
@@ -139,4 +139,50 @@ public class TmfFilterContainsNode extends TmfFilterTreeNode {
         clone.setValue(fValue);
         return clone;
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fField == null) ? 0 : fField.hashCode());
+        result = prime * result + (fIgnoreCase ? 1231 : 1237);
+        result = prime * result + (fNot ? 1231 : 1237);
+        result = prime * result + ((fValue == null) ? 0 : fValue.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterContainsNode other = (TmfFilterContainsNode) obj;
+        if (fField == null) {
+            if (other.fField != null) {
+                return false;
+            }
+        } else if (!fField.equals(other.fField)) {
+            return false;
+        }
+        if (fIgnoreCase != other.fIgnoreCase) {
+            return false;
+        }
+        if (fNot != other.fNot) {
+            return false;
+        }
+        if (fValue == null) {
+            if (other.fValue != null) {
+                return false;
+            }
+        } else if (!fValue.equals(other.fValue)) {
+            return false;
+        }
+        return true;
+    }
 }
index d7183765c51b33d04fc0a474dd00e2fc19eaf095..a85a43a598fd239c75f6935899acb5672855fa79 100644 (file)
@@ -139,4 +139,50 @@ public class TmfFilterEqualsNode extends TmfFilterTreeNode {
         clone.fValue = fValue;
         return clone;
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fField == null) ? 0 : fField.hashCode());
+        result = prime * result + (fIgnoreCase ? 1231 : 1237);
+        result = prime * result + (fNot ? 1231 : 1237);
+        result = prime * result + ((fValue == null) ? 0 : fValue.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterEqualsNode other = (TmfFilterEqualsNode) obj;
+        if (fField == null) {
+            if (other.fField != null) {
+                return false;
+            }
+        } else if (!fField.equals(other.fField)) {
+            return false;
+        }
+        if (fIgnoreCase != other.fIgnoreCase) {
+            return false;
+        }
+        if (fNot != other.fNot) {
+            return false;
+        }
+        if (fValue == null) {
+            if (other.fValue != null) {
+                return false;
+            }
+        } else if (!fValue.equals(other.fValue)) {
+            return false;
+        }
+        return true;
+    }
 }
index 28f7ef9f4c33dbcfa36b2d04b5a486edba87f3f1..ab98b3767d7e54134b1769c0c8e8308a2f6a1e9d 100644 (file)
@@ -26,6 +26,44 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 @SuppressWarnings("javadoc")
 public class TmfFilterEventTypeNode extends TmfFilterTreeNode {
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fName == null) ? 0 : fName.hashCode());
+        result = prime * result + ((fType == null) ? 0 : fType.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterEventTypeNode other = (TmfFilterEventTypeNode) obj;
+        if (fName == null) {
+            if (other.fName != null) {
+                return false;
+            }
+        } else if (!fName.equals(other.fName)) {
+            return false;
+        }
+        if (fType == null) {
+            if (other.fType != null) {
+                return false;
+            }
+        } else if (!fType.equals(other.fType)) {
+            return false;
+        }
+        return true;
+    }
+
     public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
     public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
     public static final String NAME_ATTR = "name"; //$NON-NLS-1$
index fc8b918dd97dca240715e26bf806eef167b8d65d..d32115762d7bb7287b767aa2679ccf657b4b27e6 100644 (file)
@@ -36,7 +36,7 @@ public class TmfFilterMatchesNode extends TmfFilterTreeNode {
     private boolean fNot = false;
     private String fField;
     private String fRegex;
-    private Pattern fPattern;
+    private transient Pattern fPattern;
 
     /**
      * @param parent
@@ -151,4 +151,46 @@ public class TmfFilterMatchesNode extends TmfFilterTreeNode {
         }
         return ret;
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fField == null) ? 0 : fField.hashCode());
+        result = prime * result + (fNot ? 1231 : 1237);
+        result = prime * result + ((fRegex == null) ? 0 : fRegex.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterMatchesNode other = (TmfFilterMatchesNode) obj;
+        if (fField == null) {
+            if (other.fField != null) {
+                return false;
+            }
+        } else if (!fField.equals(other.fField)) {
+            return false;
+        }
+        if (fNot != other.fNot) {
+            return false;
+        }
+        if (fRegex == null) {
+            if (other.fRegex != null) {
+                return false;
+            }
+        } else if (!fRegex.equals(other.fRegex)) {
+            return false;
+        }
+        return true;
+    }
 }
index fa20c0dd1ad7da8aa2f66ab6574a3214d17754d1..59ae9c27288fcf64a8f63f56d7fe2623f9e6e6b9 100644 (file)
@@ -104,4 +104,34 @@ public class TmfFilterNode extends TmfFilterTreeNode {
         }
         return buf.toString();
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fFilterName == null) ? 0 : fFilterName.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterNode other = (TmfFilterNode) obj;
+        if (fFilterName == null) {
+            if (other.fFilterName != null) {
+                return false;
+            }
+        } else if (!fFilterName.equals(other.fFilterName)) {
+            return false;
+        }
+        return true;
+    }
 }
index 30bbcdfba10ad2f356d4547d7bdbc4caa4429ac2..a8579e6e8db7723893ec2ecb79d33fce2705c873 100644 (file)
@@ -85,4 +85,30 @@ public class TmfFilterOrNode extends TmfFilterTreeNode {
         }
         return buf.toString();
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + (fNot ? 1231 : 1237);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterOrNode other = (TmfFilterOrNode) obj;
+        if (fNot != other.fNot) {
+            return false;
+        }
+        return true;
+    }
 }
index 6f6c5ef38289cb2d1f399855c7c6a1133ce81c07..6bf7f5f1df4e7c007d5cc057302ec810abdea176 100644 (file)
@@ -126,8 +126,10 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable
     public abstract boolean matches(ITmfEvent event);
 
     /**
-     * @param event the event
-     * @param field the field id
+     * @param event
+     *            the event
+     * @param field
+     *            the field id
      * @return the field value
      */
     protected Object getFieldValue(ITmfEvent event, String field) {
@@ -229,4 +231,34 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable
             return null;
         }
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((children == null) ? 0 : children.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TmfFilterTreeNode other = (TmfFilterTreeNode) obj;
+        if (children == null) {
+            if (other.children != null) {
+                return false;
+            }
+        } else if (!children.equals(other.children)) {
+            return false;
+        }
+        return true;
+    }
 }
This page took 0.050896 seconds and 5 git commands to generate.