From e8b491177f16882879bbcff4bfd7022dd61bae67 Mon Sep 17 00:00:00 2001 From: Charles Queiroz Date: Wed, 16 Aug 2023 07:58:41 +0100 Subject: [PATCH] server: Replace Hashtable with LinkedHashMap in createIsoResponse (#7844) * Replace Hashtable with LinkedHashMap in createIsoResponse This change replaces the use of Hashtable with LinkedHashMap in the `createIsoResponse` method of `ViewResponseHelper`. The reason for this modification is to maintain the insertion order of entries, which isn't the case with Hashtable. This could lead to more predictable results and behaviors in calling methods. * Replace Hashtable with LinkedHashMap in view response creation methods Changed Hashtable to LinkedHashMap in various response creation methods within ViewResponseHelper class. This modification ensures an ordered iteration which is beneficial for scenarios where the insertion order of responses needs to be maintained consistently. --------- Co-authored-by: Sina Kashipazha --- .../cloud/api/query/ViewResponseHelper.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java index 8fd42ea3c41..48031425bb8 100644 --- a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java +++ b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; -import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -150,7 +149,7 @@ public class ViewResponseHelper { public static List createUserVmResponse(ResponseView view, String objectName, Set details, Boolean accumulateStats, Boolean showUserData, UserVmJoinVO... userVms) { Account caller = CallContext.current().getCallingAccount(); - Hashtable vmDataList = new Hashtable(); + LinkedHashMap vmDataList = new LinkedHashMap<>(); // Initialise the vmdatalist with the input data for (UserVmJoinVO userVm : userVms) { @@ -169,7 +168,7 @@ public class ViewResponseHelper { public static List createDomainRouterResponse(DomainRouterJoinVO... routers) { Account caller = CallContext.current().getCallingAccount(); - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); // Initialise the vrdatalist with the input data for (DomainRouterJoinVO vr : routers) { DomainRouterResponse vrData = vrDataList.get(vr.getId()); @@ -187,7 +186,7 @@ public class ViewResponseHelper { public static List createSecurityGroupResponses(List securityGroups) { Account caller = CallContext.current().getCallingAccount(); - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); // Initialise the vrdatalist with the input data for (SecurityGroupJoinVO vr : securityGroups) { SecurityGroupResponse vrData = vrDataList.get(vr.getId()); @@ -205,7 +204,7 @@ public class ViewResponseHelper { } public static List createProjectResponse(EnumSet details, ProjectJoinVO... projects) { - Hashtable prjDataList = new Hashtable(); + LinkedHashMap prjDataList = new LinkedHashMap<>(); // Initialise the prjdatalist with the input data for (ProjectJoinVO p : projects) { ProjectResponse pData = prjDataList.get(p.getId()); @@ -247,7 +246,7 @@ public class ViewResponseHelper { } public static List createHostResponse(EnumSet details, HostJoinVO... hosts) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); // Initialise the vrdatalist with the input data for (HostJoinVO vr : hosts) { HostResponse vrData = ApiDBUtils.newHostResponse(vr, details); @@ -257,7 +256,7 @@ public class ViewResponseHelper { } public static List createHostForMigrationResponse(EnumSet details, HostJoinVO... hosts) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); // Initialise the vrdatalist with the input data for (HostJoinVO vr : hosts) { HostForMigrationResponse vrData = ApiDBUtils.newHostForMigrationResponse(vr, details); @@ -267,7 +266,7 @@ public class ViewResponseHelper { } public static List createVolumeResponse(ResponseView view, VolumeJoinVO... volumes) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); DecimalFormat df = new DecimalFormat("0.0%"); for (VolumeJoinVO vr : volumes) { VolumeResponse vrData = vrDataList.get(vr.getId()); @@ -308,7 +307,7 @@ public class ViewResponseHelper { } public static List createStoragePoolResponse(StoragePoolJoinVO... pools) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); // Initialise the vrdatalist with the input data for (StoragePoolJoinVO vr : pools) { StoragePoolResponse vrData = vrDataList.get(vr.getId()); @@ -345,7 +344,7 @@ public class ViewResponseHelper { } public static List createImageStoreResponse(ImageStoreJoinVO... stores) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); // Initialise the vrdatalist with the input data for (ImageStoreJoinVO vr : stores) { ImageStoreResponse vrData = vrDataList.get(vr.getId()); @@ -362,7 +361,7 @@ public class ViewResponseHelper { } public static List createStoragePoolForMigrationResponse(StoragePoolJoinVO... pools) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); // Initialise the vrdatalist with the input data for (StoragePoolJoinVO vr : pools) { StoragePoolResponse vrData = vrDataList.get(vr.getId()); @@ -577,7 +576,7 @@ public class ViewResponseHelper { } public static List createTemplateResponse(EnumSet detailsView, ResponseView view, TemplateJoinVO... templates) { - LinkedHashMap vrDataList = new LinkedHashMap(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); for (TemplateJoinVO vr : templates) { TemplateResponse vrData = vrDataList.get(vr.getTempZonePair()); if (vrData == null) { @@ -594,7 +593,7 @@ public class ViewResponseHelper { } public static List createTemplateUpdateResponse(ResponseView view, TemplateJoinVO... templates) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); for (TemplateJoinVO vr : templates) { TemplateResponse vrData = vrDataList.get(vr.getId()); if (vrData == null) { @@ -610,7 +609,7 @@ public class ViewResponseHelper { } public static List createIsoResponse(ResponseView view, TemplateJoinVO... templates) { - Hashtable vrDataList = new Hashtable<>(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); for (TemplateJoinVO vr : templates) { TemplateResponse vrData = vrDataList.get(vr.getTempZonePair()); if (vrData == null) { @@ -626,7 +625,7 @@ public class ViewResponseHelper { } public static List createAffinityGroupResponses(List groups) { - Hashtable vrDataList = new Hashtable(); + LinkedHashMap vrDataList = new LinkedHashMap<>(); for (AffinityGroupJoinVO vr : groups) { AffinityGroupResponse vrData = vrDataList.get(vr.getId()); if (vrData == null) {