From 0756ad6c7f713dd5c05f0a31c6b85cee0ffa62c5 Mon Sep 17 00:00:00 2001 From: Family Date: Sat, 3 Oct 2020 21:12:36 +0530 Subject: [PATCH] Addressed comments --- .../commons/collections4/MapBuilder.java | 15 ++++++------- .../commons/collections4/MapBuilderTest.java | 22 +++++++++---------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/MapBuilder.java b/src/main/java/org/apache/commons/collections4/MapBuilder.java index a668ff857..da1964a56 100644 --- a/src/main/java/org/apache/commons/collections4/MapBuilder.java +++ b/src/main/java/org/apache/commons/collections4/MapBuilder.java @@ -17,19 +17,18 @@ import java.util.*; * builderMap.put("Y", 26); * } * - * @author Amita Pradhan */ -public class MapBuilder { +public class MapBuilder { - private Comparator comparator; + private Comparator comparator; private KeyOrder iterationOrder; private boolean synchronizedMap; private boolean immutable; - private Map data; + private Map data; public MapBuilder() { comparator = null; - iterationOrder = KeyOrder.RANDOM; + iterationOrder = KeyOrder.UNORDERED; synchronizedMap = false; immutable = false; data = null; @@ -44,7 +43,7 @@ public class MapBuilder { } /* - Sets the Iteration order to be used from [RANDOM, NATURAL_ORDER, INSERTION_ORDER, COMPARATOR_ORDER] + Sets the Iteration order to be used from [UNORDERED, NATURAL_ORDER, INSERTION_ORDER, COMPARATOR_ORDER] */ public MapBuilder setIterationOrder(KeyOrder iterationOrder) { this.iterationOrder = iterationOrder; @@ -79,7 +78,7 @@ public class MapBuilder { Builder Method which takes care of all the conditions and returns the required Map. */ public Map build() { - Map map; + Map map; switch (iterationOrder) { case NATURAL_ORDER : case COMPARATOR_ORDER: @@ -110,6 +109,6 @@ public class MapBuilder { enum KeyOrder { - RANDOM, NATURAL_ORDER, INSERTION_ORDER, COMPARATOR_ORDER; + UNORDERED, NATURAL_ORDER, INSERTION_ORDER, COMPARATOR_ORDER; } } diff --git a/src/test/java/org/apache/commons/collections4/MapBuilderTest.java b/src/test/java/org/apache/commons/collections4/MapBuilderTest.java index 7cb6df31e..f36a0f04a 100644 --- a/src/test/java/org/apache/commons/collections4/MapBuilderTest.java +++ b/src/test/java/org/apache/commons/collections4/MapBuilderTest.java @@ -7,8 +7,6 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Map; -import static org.junit.jupiter.api.Assertions.*; - /** * Test Cases for Map Builder */ @@ -17,12 +15,12 @@ class MapBuilderTest { @Test void setComparator() { // Null Comparator - Map myMap = new HashMap(); + Map myMap = new HashMap(); myMap.put("A", 1); myMap.put("X", 24); myMap.put("B", 2); myMap.put("Y", 26); - Map builderMap = new MapBuilder().setData(myMap).setComparator(null).build(); + Map builderMap = new MapBuilder().setData(myMap).setComparator(null).build(); Assert.assertEquals(myMap, builderMap); // Reverse comparator @@ -35,13 +33,13 @@ class MapBuilderTest { @Test void setIterationOrder() { - //Key Order = RANDOM - Map myMap = new HashMap(); + //Key Order = UNORDERED + Map myMap = new HashMap(); myMap.put("A", 1); myMap.put("X", 24); myMap.put("B", 2); myMap.put("Y", 26); - Map builderMap = new MapBuilder().setData(myMap).setIterationOrder(MapBuilder.KeyOrder.RANDOM).build(); + Map builderMap = new MapBuilder().setData(myMap).setIterationOrder(MapBuilder.KeyOrder.UNORDERED).build(); Assert.assertEquals(myMap, builderMap); //Key Order = INSERTION ORDER @@ -91,10 +89,10 @@ class MapBuilderTest { @Test void setImmutable() { - Map myMap = new HashMap(); + Map myMap = new HashMap(); myMap.put("A", 1); myMap.put("B", 2); - Map builderMap = new MapBuilder().setData(myMap).setImmutable(true).build(); + Map builderMap = new MapBuilder().setData(myMap).setImmutable(true).build(); boolean exceptionThrown = false; try { builderMap.put("C", 3); @@ -107,16 +105,16 @@ class MapBuilderTest { @Test void setData() { - Map myMap = new HashMap(); + Map myMap = new HashMap(); myMap.put("A", 1); myMap.put("B", 2); - Map builderMap = new MapBuilder().setData(myMap).build(); + Map builderMap = new MapBuilder().setData(myMap).build(); Assert.assertEquals(myMap, builderMap); } @Test void build() { - Map builderMap = new MapBuilder().build(); + Map builderMap = new MapBuilder().build(); Assert.assertTrue(builderMap.size() == 0); } } \ No newline at end of file