From fd7c3b8859173bf03f0eb19947e4e6902e06b93c Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Wed, 27 Sep 2023 20:28:23 +0300 Subject: [PATCH] Optimization PR Clean up --- .../smartregister/model/location/LocationHierarchyTree.java | 3 --- src/main/java/org/smartregister/model/location/Tree.java | 5 +---- .../model/location/LocationHierarchyTreeTest.java | 4 +--- .../org/smartregister/model/location/utils/TestUtils.java | 3 +-- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/smartregister/model/location/LocationHierarchyTree.java b/src/main/java/org/smartregister/model/location/LocationHierarchyTree.java index 721b596..48b8d24 100755 --- a/src/main/java/org/smartregister/model/location/LocationHierarchyTree.java +++ b/src/main/java/org/smartregister/model/location/LocationHierarchyTree.java @@ -58,12 +58,9 @@ public void addLocation(Location location) { * @param locations */ public void buildTreeFromList(List locations) { - long start = System.currentTimeMillis(); for (Location location : locations) { addLocation(location); } - logger.info(String.format("LocationHierarchyTree.buildTreeFromList took : %d ms", System.currentTimeMillis() - start)); - } public Tree getLocationsHierarchy() { diff --git a/src/main/java/org/smartregister/model/location/Tree.java b/src/main/java/org/smartregister/model/location/Tree.java index 9628993..420fdb6 100755 --- a/src/main/java/org/smartregister/model/location/Tree.java +++ b/src/main/java/org/smartregister/model/location/Tree.java @@ -32,7 +32,6 @@ import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Logger; @DatatypeDef(name = "Tree") public class Tree extends Type implements ICompositeType { @@ -52,8 +51,6 @@ public class Tree extends Type implements ICompositeType { summary = false) private List parentChildren; - private static final Logger logger = Logger.getLogger(Tree.class.getSimpleName()); - public SingleTreeNode getTree() { return listOfNodes; } @@ -143,7 +140,7 @@ public void addNode(String id, String label, Location node, String parentId) { } } else { - logger.severe("Node with ID " + id + " already exists in tree"); + throw new IllegalArgumentException("Node with ID " + id + " already exists in tree"); } } diff --git a/src/test/java/org/smartregister/model/location/LocationHierarchyTreeTest.java b/src/test/java/org/smartregister/model/location/LocationHierarchyTreeTest.java index 4c2e3ad..960edf4 100644 --- a/src/test/java/org/smartregister/model/location/LocationHierarchyTreeTest.java +++ b/src/test/java/org/smartregister/model/location/LocationHierarchyTreeTest.java @@ -18,7 +18,6 @@ import org.hl7.fhir.r4.model.Location; import org.hl7.fhir.r4.model.Reference; import org.junit.Test; -import org.smartregister.model.location.utils.TestUtils; import java.util.ArrayList; import java.util.List; @@ -52,10 +51,9 @@ public void testAddLocationWithoutChildLocations() { @Test public void testBuildTreeFromList() { - List locationList = TestUtils.getTestLocations(); + List locationList = getLocationList(); LocationHierarchyTree locationHierarchyTree = new LocationHierarchyTree(); locationHierarchyTree.buildTreeFromList(locationList); - Tree tree = locationHierarchyTree.getLocationsHierarchy(); assertNotNull(tree); assertNotNull(tree.getTree()); diff --git a/src/test/java/org/smartregister/model/location/utils/TestUtils.java b/src/test/java/org/smartregister/model/location/utils/TestUtils.java index d5c03f0..6525a6e 100644 --- a/src/test/java/org/smartregister/model/location/utils/TestUtils.java +++ b/src/test/java/org/smartregister/model/location/utils/TestUtils.java @@ -14,10 +14,9 @@ public static List getTestLocations() { List locationList = new ArrayList<>(); - int parentId = 1; - for (Integer i = 1; i < TOTAL_LOCATIONS + 1; i++) { + for (int i = 1; i < TOTAL_LOCATIONS + 1; i++) { if(i == 1){ parentId = 1;