From 289276f8ff9ca11d30036d8673fbaddb9f36409c Mon Sep 17 00:00:00 2001 From: Joao Esperancinha Date: Tue, 21 Jul 2020 06:36:14 +0200 Subject: [PATCH] Revert "[BAEL-4281] Examples of array comparisons" This reverts commit d1a9ff7480f8f21543c02d61992d0dd20fa4e56d. --- java-collections/README.md | 8 --- java-collections/pom.xml | 49 ------------------- .../com/baeldung/comparingarrays/Plane.java | 39 --------------- .../src/main/resources/logback.xml | 13 ----- .../baeldung/DeepEqualsCompareUnitTest.java | 34 ------------- .../com/baeldung/EqualsCompareUnitTest.java | 29 ----------- .../com/baeldung/LengthsCompareUnitTest.java | 22 --------- .../com/baeldung/OrderCompareUnitTest.java | 34 ------------- .../baeldung/ReferenceCompareUnitTest.java | 34 ------------- 9 files changed, 262 deletions(-) delete mode 100644 java-collections/README.md delete mode 100644 java-collections/pom.xml delete mode 100644 java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java delete mode 100644 java-collections/src/main/resources/logback.xml delete mode 100644 java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java delete mode 100644 java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java delete mode 100644 java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java delete mode 100644 java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java delete mode 100644 java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java diff --git a/java-collections/README.md b/java-collections/README.md deleted file mode 100644 index 480b7f257a..0000000000 --- a/java-collections/README.md +++ /dev/null @@ -1,8 +0,0 @@ -## Java Collections Examples - -This module support code for articles about handling java collections and arrays. - -### Relevant Articles: -- [Comparing two integer arrays in Java](https://stackoverflow.com/questions/14897366/comparing-two-integer-arrays-in-java) -- [Compare two arrays with not the same order](https://stackoverflow.com/questions/54711228/compare-two-arrays-with-not-the-same-order) -- More articles: [[next -->]](../java-collections-conversions-2) \ No newline at end of file diff --git a/java-collections/pom.xml b/java-collections/pom.xml deleted file mode 100644 index 5e0ee42244..0000000000 --- a/java-collections/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - 4.0.0 - java-collections - 0.1.0-SNAPSHOT - java-collections - jar - - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.hamcrest - hamcrest-all - ${hamcrest-all.version} - test - - - - - java-collections - - - src/main/resources - true - - - - - - 4.1 - - diff --git a/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java b/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java deleted file mode 100644 index db61807878..0000000000 --- a/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.comparingarrays; - -import java.util.Objects; - -public class Plane { - - private final String name; - - private final String model; - - public Plane(String name, String model) { - - this.name = name; - this.model = model; - } - - public String getName() { - return name; - } - - public String getModel() { - return model; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Plane plane = (Plane) o; - return Objects.equals(name, plane.name) && Objects.equals(model, plane.model); - } - - @Override - public int hashCode() { - return Objects.hash(name, model); - } -} diff --git a/java-collections/src/main/resources/logback.xml b/java-collections/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/java-collections/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java deleted file mode 100644 index f311d0e5c9..0000000000 --- a/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung; - -import com.baeldung.comparingarrays.Plane; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class DeepEqualsCompareUnitTest { - - @Test - public void givenArray1andArray2_whenSameContent_thenDeepEquals() { - final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, - new Plane[] { new Plane("Plane 2", "B738") } }; - final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, - new Plane[] { new Plane("Plane 2", "B738") } }; - - boolean result = Arrays.deepEquals(planes1, planes2); - assertTrue("Result is not true", result); - } - - @Test - public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { - final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, - new Plane[] { new Plane("Plane 2", "B738") } }; - final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 2", "B738") }, - new Plane[] { new Plane("Plane 1", "A320") } }; - - boolean result = Arrays.deepEquals(planes1, planes2); - assertFalse("Result is true", result); - } -} diff --git a/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java deleted file mode 100644 index b56395a848..0000000000 --- a/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung; - -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class EqualsCompareUnitTest { - - @Test - public void givenArray1andArray2_whenSameContent_thenEquals() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - - boolean result = Arrays.equals(planes1, planes2); - assertTrue("Result is not true", result); - } - - @Test - public void givenArray1andArray2_whenSameContentOtherSort_thenNotEquals() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = new String[] { "B738", "A320", "A321", "A319", "B77W", "B737", "A333", "A332" }; - - boolean result = Arrays.equals(planes1, planes2); - assertFalse("Result is true", result); - } -} diff --git a/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java deleted file mode 100644 index 8b3c90c427..0000000000 --- a/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung; - -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; -import static org.junit.Assert.assertThat; - -public class LengthsCompareUnitTest { - - @Test - public void givenArray1andArray2_whenSameSizes_thenSizeEqualsOk() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final Integer[] quantities = new Integer[] { 10, 12, 34, 45, 12, 43, 5, 2 }; - - assertThat(planes1, arrayWithSize(8)); - assertThat(quantities, arrayWithSize(8)); - assertThat(planes1.length, is(8)); - assertThat(quantities.length, is(8)); - } -} - diff --git a/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java deleted file mode 100644 index 8be7251c05..0000000000 --- a/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung; - -import com.baeldung.comparingarrays.Plane; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.Comparator; - -import static org.junit.Assert.assertTrue; - -public class OrderCompareUnitTest { - @Test - public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { - final Plane[][] planes1 = new Plane[][] { - new Plane[] { new Plane("Plane 1", "A320"), new Plane("Plane 2", "B738") } }; - final Plane[][] planes2 = new Plane[][] { - new Plane[] { new Plane("Plane 2", "B738"), new Plane("Plane 1", "A320") } }; - - Comparator planeComparator = (o1, o2) -> { - if (o1.getName() - .equals(o2.getName())) { - return o2.getModel() - .compareTo(o1.getModel()); - } - return o2.getName() - .compareTo(o1.getName()); - }; - Arrays.sort(planes1[0], planeComparator); - Arrays.sort(planes2[0], planeComparator); - - boolean result = Arrays.deepEquals(planes1, planes2); - assertTrue("Result is false", result); - } -} diff --git a/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java deleted file mode 100644 index 9716a34607..0000000000 --- a/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung; - -import org.junit.jupiter.api.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; - -public class ReferenceCompareUnitTest { - - @Test - public void givenArray1andArray2_whenEquals_thenEqual() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = planes1; - - assertSame("Objects are not equal!", planes1, planes2); - - planes2[0] = "747"; - - assertSame("Objects are not same!", planes1, planes2); - assertEquals("Objects are not equal!", "747", planes2[0]); - assertEquals("Objects are not equal!", "747", planes1[0]); - } - - @Test - public void givenArray1andArray2_whenDifferentValues_thenNotEqual() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - - assertNotSame("Objects are the same!", planes1, planes2); - assertNotEquals("Objects are equal!", planes1, planes2); - } -}