Skip to content

Commit e8b4911

Browse files
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 <soreana@users.noreply.github.com>
1 parent cf249f6 commit e8b4911

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

server/src/main/java/com/cloud/api/query/ViewResponseHelper.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.EnumSet;
2323
import java.util.HashMap;
24-
import java.util.Hashtable;
2524
import java.util.LinkedHashMap;
2625
import java.util.List;
2726
import java.util.Map;
@@ -150,7 +149,7 @@ public static List<UserVmResponse> createUserVmResponse(ResponseView view, Strin
150149
public static List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, Set<VMDetails> details, Boolean accumulateStats, Boolean showUserData,
151150
UserVmJoinVO... userVms) {
152151
Account caller = CallContext.current().getCallingAccount();
153-
Hashtable<Long, UserVmResponse> vmDataList = new Hashtable<Long, UserVmResponse>();
152+
LinkedHashMap<Long, UserVmResponse> vmDataList = new LinkedHashMap<>();
154153
// Initialise the vmdatalist with the input data
155154

156155
for (UserVmJoinVO userVm : userVms) {
@@ -169,7 +168,7 @@ public static List<UserVmResponse> createUserVmResponse(ResponseView view, Strin
169168

170169
public static List<DomainRouterResponse> createDomainRouterResponse(DomainRouterJoinVO... routers) {
171170
Account caller = CallContext.current().getCallingAccount();
172-
Hashtable<Long, DomainRouterResponse> vrDataList = new Hashtable<Long, DomainRouterResponse>();
171+
LinkedHashMap<Long, DomainRouterResponse> vrDataList = new LinkedHashMap<>();
173172
// Initialise the vrdatalist with the input data
174173
for (DomainRouterJoinVO vr : routers) {
175174
DomainRouterResponse vrData = vrDataList.get(vr.getId());
@@ -187,7 +186,7 @@ public static List<DomainRouterResponse> createDomainRouterResponse(DomainRouter
187186

188187
public static List<SecurityGroupResponse> createSecurityGroupResponses(List<SecurityGroupJoinVO> securityGroups) {
189188
Account caller = CallContext.current().getCallingAccount();
190-
Hashtable<Long, SecurityGroupResponse> vrDataList = new Hashtable<Long, SecurityGroupResponse>();
189+
LinkedHashMap<Long, SecurityGroupResponse> vrDataList = new LinkedHashMap<>();
191190
// Initialise the vrdatalist with the input data
192191
for (SecurityGroupJoinVO vr : securityGroups) {
193192
SecurityGroupResponse vrData = vrDataList.get(vr.getId());
@@ -205,7 +204,7 @@ public static List<SecurityGroupResponse> createSecurityGroupResponses(List<Secu
205204
}
206205

207206
public static List<ProjectResponse> createProjectResponse(EnumSet<DomainDetails> details, ProjectJoinVO... projects) {
208-
Hashtable<Long, ProjectResponse> prjDataList = new Hashtable<Long, ProjectResponse>();
207+
LinkedHashMap<Long, ProjectResponse> prjDataList = new LinkedHashMap<>();
209208
// Initialise the prjdatalist with the input data
210209
for (ProjectJoinVO p : projects) {
211210
ProjectResponse pData = prjDataList.get(p.getId());
@@ -247,7 +246,7 @@ public static List<ProjectInvitationResponse> createProjectInvitationResponse(Pr
247246
}
248247

249248
public static List<HostResponse> createHostResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
250-
Hashtable<Long, HostResponse> vrDataList = new Hashtable<Long, HostResponse>();
249+
LinkedHashMap<Long, HostResponse> vrDataList = new LinkedHashMap<>();
251250
// Initialise the vrdatalist with the input data
252251
for (HostJoinVO vr : hosts) {
253252
HostResponse vrData = ApiDBUtils.newHostResponse(vr, details);
@@ -257,7 +256,7 @@ public static List<HostResponse> createHostResponse(EnumSet<HostDetails> details
257256
}
258257

259258
public static List<HostForMigrationResponse> createHostForMigrationResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
260-
Hashtable<Long, HostForMigrationResponse> vrDataList = new Hashtable<Long, HostForMigrationResponse>();
259+
LinkedHashMap<Long, HostForMigrationResponse> vrDataList = new LinkedHashMap<>();
261260
// Initialise the vrdatalist with the input data
262261
for (HostJoinVO vr : hosts) {
263262
HostForMigrationResponse vrData = ApiDBUtils.newHostForMigrationResponse(vr, details);
@@ -267,7 +266,7 @@ public static List<HostForMigrationResponse> createHostForMigrationResponse(Enum
267266
}
268267

269268
public static List<VolumeResponse> createVolumeResponse(ResponseView view, VolumeJoinVO... volumes) {
270-
Hashtable<Long, VolumeResponse> vrDataList = new Hashtable<Long, VolumeResponse>();
269+
LinkedHashMap<Long, VolumeResponse> vrDataList = new LinkedHashMap<>();
271270
DecimalFormat df = new DecimalFormat("0.0%");
272271
for (VolumeJoinVO vr : volumes) {
273272
VolumeResponse vrData = vrDataList.get(vr.getId());
@@ -308,7 +307,7 @@ public static List<VolumeResponse> createVolumeResponse(ResponseView view, Volum
308307
}
309308

310309
public static List<StoragePoolResponse> createStoragePoolResponse(StoragePoolJoinVO... pools) {
311-
Hashtable<Long, StoragePoolResponse> vrDataList = new Hashtable<Long, StoragePoolResponse>();
310+
LinkedHashMap<Long, StoragePoolResponse> vrDataList = new LinkedHashMap<>();
312311
// Initialise the vrdatalist with the input data
313312
for (StoragePoolJoinVO vr : pools) {
314313
StoragePoolResponse vrData = vrDataList.get(vr.getId());
@@ -345,7 +344,7 @@ public static List<HostTagResponse> createHostTagResponse(HostTagVO... hostTags)
345344
}
346345

347346
public static List<ImageStoreResponse> createImageStoreResponse(ImageStoreJoinVO... stores) {
348-
Hashtable<Long, ImageStoreResponse> vrDataList = new Hashtable<Long, ImageStoreResponse>();
347+
LinkedHashMap<Long, ImageStoreResponse> vrDataList = new LinkedHashMap<>();
349348
// Initialise the vrdatalist with the input data
350349
for (ImageStoreJoinVO vr : stores) {
351350
ImageStoreResponse vrData = vrDataList.get(vr.getId());
@@ -362,7 +361,7 @@ public static List<ImageStoreResponse> createImageStoreResponse(ImageStoreJoinVO
362361
}
363362

364363
public static List<StoragePoolResponse> createStoragePoolForMigrationResponse(StoragePoolJoinVO... pools) {
365-
Hashtable<Long, StoragePoolResponse> vrDataList = new Hashtable<Long, StoragePoolResponse>();
364+
LinkedHashMap<Long, StoragePoolResponse> vrDataList = new LinkedHashMap<>();
366365
// Initialise the vrdatalist with the input data
367366
for (StoragePoolJoinVO vr : pools) {
368367
StoragePoolResponse vrData = vrDataList.get(vr.getId());
@@ -577,7 +576,7 @@ public static List<ZoneResponse> createDataCenterResponse(ResponseView view, Boo
577576
}
578577

579578
public static List<TemplateResponse> createTemplateResponse(EnumSet<ApiConstants.DomainDetails> detailsView, ResponseView view, TemplateJoinVO... templates) {
580-
LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<String, TemplateResponse>();
579+
LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<>();
581580
for (TemplateJoinVO vr : templates) {
582581
TemplateResponse vrData = vrDataList.get(vr.getTempZonePair());
583582
if (vrData == null) {
@@ -594,7 +593,7 @@ public static List<TemplateResponse> createTemplateResponse(EnumSet<ApiConstants
594593
}
595594

596595
public static List<TemplateResponse> createTemplateUpdateResponse(ResponseView view, TemplateJoinVO... templates) {
597-
Hashtable<Long, TemplateResponse> vrDataList = new Hashtable<Long, TemplateResponse>();
596+
LinkedHashMap<Long, TemplateResponse> vrDataList = new LinkedHashMap<>();
598597
for (TemplateJoinVO vr : templates) {
599598
TemplateResponse vrData = vrDataList.get(vr.getId());
600599
if (vrData == null) {
@@ -610,7 +609,7 @@ public static List<TemplateResponse> createTemplateUpdateResponse(ResponseView v
610609
}
611610

612611
public static List<TemplateResponse> createIsoResponse(ResponseView view, TemplateJoinVO... templates) {
613-
Hashtable<String, TemplateResponse> vrDataList = new Hashtable<>();
612+
LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<>();
614613
for (TemplateJoinVO vr : templates) {
615614
TemplateResponse vrData = vrDataList.get(vr.getTempZonePair());
616615
if (vrData == null) {
@@ -626,7 +625,7 @@ public static List<TemplateResponse> createIsoResponse(ResponseView view, Templa
626625
}
627626

628627
public static List<AffinityGroupResponse> createAffinityGroupResponses(List<AffinityGroupJoinVO> groups) {
629-
Hashtable<Long, AffinityGroupResponse> vrDataList = new Hashtable<Long, AffinityGroupResponse>();
628+
LinkedHashMap<Long, AffinityGroupResponse> vrDataList = new LinkedHashMap<>();
630629
for (AffinityGroupJoinVO vr : groups) {
631630
AffinityGroupResponse vrData = vrDataList.get(vr.getId());
632631
if (vrData == null) {

0 commit comments

Comments
 (0)