Title: [2119] trunk/xstream/src/test/com/thoughtworks/acceptance/objects/Product.java: Implement equals and hashCode for Product.
Revision
2119
Author
joehni
Date
2013-09-17 17:29:49 -0500 (Tue, 17 Sep 2013)

Log Message

Implement equals and hashCode for Product.

Modified Paths


Diff

Modified: trunk/xstream/src/test/com/thoughtworks/acceptance/objects/Product.java (2118 => 2119)


--- trunk/xstream/src/test/com/thoughtworks/acceptance/objects/Product.java	2013-09-17 21:52:21 UTC (rev 2118)
+++ trunk/xstream/src/test/com/thoughtworks/acceptance/objects/Product.java	2013-09-17 22:29:49 UTC (rev 2119)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 XStream Committers.
+ * Copyright (C) 2007, 2013 XStream Committers.
  * All rights reserved.
  *
  * The software in this package is published under the terms of the BSD
@@ -59,6 +59,37 @@
         this.tags = tags;
     }
 
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
+        result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
+        long temp;
+        temp = Double.doubleToLongBits(this.price);
+        result = prime * result + (int)(temp ^ (temp >>> 32));
+        result = prime * result + ((this.tags == null) ? 0 : this.tags.hashCode());
+        return result;
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj == null) return false;
+        if (getClass() != obj.getClass()) return false;
+        Product other = (Product)obj;
+        if (this.id == null) {
+            if (other.id != null) return false;
+        } else if (!this.id.equals(other.id)) return false;
+        if (this.name == null) {
+            if (other.name != null) return false;
+        } else if (!this.name.equals(other.name)) return false;
+        if (Double.doubleToLongBits(this.price) != Double.doubleToLongBits(other.price))
+            return false;
+        if (this.tags == null) {
+            if (other.tags != null) return false;
+        } else if (!this.tags.equals(other.tags)) return false;
+        return true;
+    }
+
     public String toString() {
         String ret = "[" + name + ", " + id + ", " + price;
         if (tags != null) {

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to