From 7aaae1d1433995ffd5a25a5d24d817a1bc072737 Mon Sep 17 00:00:00 2001 From: Nancy Bosecker Date: Mon, 26 Sep 2016 22:40:46 -0700 Subject: [PATCH] Moved project to core-java from eclipse folder (#703) --- .../equalshashcode/entities/ComplexClass.java | 65 +++++++++++++++++++ .../entities/PrimitiveClass.java | 0 .../equalshashcode/entities/Rectangle.java | 2 - .../equalshashcode/entities/Shape.java | 0 .../equalshashcode/entities/Square.java | 0 .../entities/ComplexClassTest.java | 5 +- .../entities/PrimitiveClassTest.java | 5 +- .../entities/SquareClassTest.java | 5 +- .../equalshashcode/entities/ComplexClass.java | 63 ------------------ 9 files changed, 71 insertions(+), 74 deletions(-) create mode 100644 core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java rename {eclipse => core-java}/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java (100%) rename {eclipse => core-java}/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java (96%) rename {eclipse => core-java}/src/main/java/org/baeldung/equalshashcode/entities/Shape.java (100%) rename {eclipse => core-java}/src/main/java/org/baeldung/equalshashcode/entities/Square.java (100%) rename {eclipse => core-java}/src/test/java/org/baeldung/equalshashcode/entities/ComplexClassTest.java (90%) rename {eclipse => core-java}/src/test/java/org/baeldung/equalshashcode/entities/PrimitiveClassTest.java (84%) rename {eclipse => core-java}/src/test/java/org/baeldung/equalshashcode/entities/SquareClassTest.java (84%) delete mode 100644 eclipse/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java diff --git a/core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java new file mode 100644 index 0000000000..d4a6a0f42e --- /dev/null +++ b/core-java/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java @@ -0,0 +1,65 @@ +package org.baeldung.equalshashcode.entities; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class ComplexClass { + + private List genericList; + private Set integerSet; + + public ComplexClass(ArrayList genericArrayList, HashSet integerHashSet) { + super(); + this.genericList = genericArrayList; + this.integerSet = integerHashSet; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((genericList == null) ? 0 : genericList.hashCode()); + result = prime * result + ((integerSet == null) ? 0 : integerSet.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof ComplexClass)) + return false; + ComplexClass other = (ComplexClass) obj; + if (genericList == null) { + if (other.genericList != null) + return false; + } else if (!genericList.equals(other.genericList)) + return false; + if (integerSet == null) { + if (other.integerSet != null) + return false; + } else if (!integerSet.equals(other.integerSet)) + return false; + return true; + } + + protected List getGenericList() { + return genericList; + } + + protected void setGenericArrayList(List genericList) { + this.genericList = genericList; + } + + protected Set getIntegerSet() { + return integerSet; + } + + protected void setIntegerSet(Set integerSet) { + this.integerSet = integerSet; + } +} diff --git a/eclipse/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java similarity index 100% rename from eclipse/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java rename to core-java/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java diff --git a/eclipse/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java similarity index 96% rename from eclipse/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java rename to core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java index 315ef41a12..1e1423f0b3 100644 --- a/eclipse/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java +++ b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java @@ -11,13 +11,11 @@ public class Rectangle extends Shape { @Override public double area() { - // A = w * l return width * length; } @Override public double perimeter() { - // P = 2(w + l) return 2 * (width + length); } diff --git a/eclipse/src/main/java/org/baeldung/equalshashcode/entities/Shape.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Shape.java similarity index 100% rename from eclipse/src/main/java/org/baeldung/equalshashcode/entities/Shape.java rename to core-java/src/main/java/org/baeldung/equalshashcode/entities/Shape.java diff --git a/eclipse/src/main/java/org/baeldung/equalshashcode/entities/Square.java b/core-java/src/main/java/org/baeldung/equalshashcode/entities/Square.java similarity index 100% rename from eclipse/src/main/java/org/baeldung/equalshashcode/entities/Square.java rename to core-java/src/main/java/org/baeldung/equalshashcode/entities/Square.java diff --git a/eclipse/src/test/java/org/baeldung/equalshashcode/entities/ComplexClassTest.java b/core-java/src/test/java/org/baeldung/equalshashcode/entities/ComplexClassTest.java similarity index 90% rename from eclipse/src/test/java/org/baeldung/equalshashcode/entities/ComplexClassTest.java rename to core-java/src/test/java/org/baeldung/equalshashcode/entities/ComplexClassTest.java index 09123e988b..75d96e5989 100644 --- a/eclipse/src/test/java/org/baeldung/equalshashcode/entities/ComplexClassTest.java +++ b/core-java/src/test/java/org/baeldung/equalshashcode/entities/ComplexClassTest.java @@ -22,11 +22,10 @@ public class ComplexClassTest { strArrayListD.add("pqr"); ComplexClass dObject = new ComplexClass(strArrayListD, new HashSet(45, 67)); - // equals() Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject)); - // hashCode() + Assert.assertTrue(aObject.hashCode() == bObject.hashCode()); - // non-equal objects are not equals() and have different hashCode() + Assert.assertFalse(aObject.equals(dObject)); Assert.assertFalse(aObject.hashCode() == dObject.hashCode()); } diff --git a/eclipse/src/test/java/org/baeldung/equalshashcode/entities/PrimitiveClassTest.java b/core-java/src/test/java/org/baeldung/equalshashcode/entities/PrimitiveClassTest.java similarity index 84% rename from eclipse/src/test/java/org/baeldung/equalshashcode/entities/PrimitiveClassTest.java rename to core-java/src/test/java/org/baeldung/equalshashcode/entities/PrimitiveClassTest.java index feb04d65ff..16f25ae021 100644 --- a/eclipse/src/test/java/org/baeldung/equalshashcode/entities/PrimitiveClassTest.java +++ b/core-java/src/test/java/org/baeldung/equalshashcode/entities/PrimitiveClassTest.java @@ -12,11 +12,10 @@ public class PrimitiveClassTest { PrimitiveClass bObject = new PrimitiveClass(false, 2); PrimitiveClass dObject = new PrimitiveClass(true, 2); - // equals() Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject)); - // hashCode() + Assert.assertTrue(aObject.hashCode() == bObject.hashCode()); - // non-equal objects are not equals() and have different hashCode() + Assert.assertFalse(aObject.equals(dObject)); Assert.assertFalse(aObject.hashCode() == dObject.hashCode()); } diff --git a/eclipse/src/test/java/org/baeldung/equalshashcode/entities/SquareClassTest.java b/core-java/src/test/java/org/baeldung/equalshashcode/entities/SquareClassTest.java similarity index 84% rename from eclipse/src/test/java/org/baeldung/equalshashcode/entities/SquareClassTest.java rename to core-java/src/test/java/org/baeldung/equalshashcode/entities/SquareClassTest.java index 53ca199405..52d024a696 100644 --- a/eclipse/src/test/java/org/baeldung/equalshashcode/entities/SquareClassTest.java +++ b/core-java/src/test/java/org/baeldung/equalshashcode/entities/SquareClassTest.java @@ -15,11 +15,10 @@ public class SquareClassTest { Square dObject = new Square(20, Color.BLUE); - // equals() Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject)); - // hashCode() + Assert.assertTrue(aObject.hashCode() == bObject.hashCode()); - // non-equal objects are not equals() and have different hashCode() + Assert.assertFalse(aObject.equals(dObject)); Assert.assertFalse(aObject.hashCode() == dObject.hashCode()); } diff --git a/eclipse/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java b/eclipse/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java deleted file mode 100644 index 3f7723facd..0000000000 --- a/eclipse/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.baeldung.equalshashcode.entities; - -import java.util.ArrayList; -import java.util.HashSet; - -public class ComplexClass { - - private ArrayList genericArrayList; - private HashSet integerHashSet; - - public ComplexClass(ArrayList genericArrayList, HashSet integerHashSet) { - super(); - this.genericArrayList = genericArrayList; - this.integerHashSet = integerHashSet; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((genericArrayList == null) ? 0 : genericArrayList.hashCode()); - result = prime * result + ((integerHashSet == null) ? 0 : integerHashSet.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof ComplexClass)) - return false; - ComplexClass other = (ComplexClass) obj; - if (genericArrayList == null) { - if (other.genericArrayList != null) - return false; - } else if (!genericArrayList.equals(other.genericArrayList)) - return false; - if (integerHashSet == null) { - if (other.integerHashSet != null) - return false; - } else if (!integerHashSet.equals(other.integerHashSet)) - return false; - return true; - } - - protected ArrayList getGenericArrayList() { - return genericArrayList; - } - - protected void setGenericArrayList(ArrayList genericArrayList) { - this.genericArrayList = genericArrayList; - } - - protected HashSet getIntegerHashSet() { - return integerHashSet; - } - - protected void setIntegerHashSet(HashSet integerHashSet) { - this.integerHashSet = integerHashSet; - } -}