From 9e99e2ec7a9b021dc1ed372172c69857344aea9c Mon Sep 17 00:00:00 2001 From: Kamidu Sachith Date: Mon, 21 Dec 2015 17:55:04 +0530 Subject: [PATCH] Improve performance of the core --- .../device/mgt/mobile/impl/android/AndroidDeviceManager.java | 2 +- .../device/mgt/mobile/impl/android/AndroidFeatureManager.java | 4 ++-- .../mobile/impl/android/AndroidPolicyMonitoringService.java | 4 ++-- .../carbon/device/mgt/mobile/impl/android/gcm/GCMService.java | 2 +- .../carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java | 2 +- .../device/mgt/mobile/impl/windows/WindowsDeviceManager.java | 2 +- .../device/mgt/mobile/impl/windows/WindowsFeatureManager.java | 4 ++-- .../device/mgt/mobile/util/MobileDeviceManagementUtil.java | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java index d52115a838..472589e6cb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java @@ -335,7 +335,7 @@ public class AndroidDeviceManager implements DeviceManager { List mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices(); if (mobileDevices != null) { - devices = new ArrayList<>(); + devices = new ArrayList<>(mobileDevices.size()); for (MobileDevice mobileDevice : mobileDevices) { devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java index ada8eb7d32..6b29e84868 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java @@ -64,7 +64,7 @@ public class AndroidFeatureManager implements FeatureManager { @Override public boolean addFeatures(List features) throws DeviceManagementException { - List mobileFeatures = new ArrayList(); + List mobileFeatures = new ArrayList(features.size()); for (Feature feature : features) { mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); } @@ -96,9 +96,9 @@ public class AndroidFeatureManager implements FeatureManager { @Override public List getFeatures() throws DeviceManagementException { - List featureList = new ArrayList(); try { List mobileFeatures = featureDAO.getAllFeatures(); + List featureList = new ArrayList(mobileFeatures.size()); for (MobileFeature mobileFeature : mobileFeatures) { featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java index 0a87cd668e..ced47139f6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java @@ -61,8 +61,6 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService { if (compliancePayload == null || policy == null) { return complianceData; } - List complianceFeatures = new ArrayList(); - List nonComplianceFeatures = new ArrayList<>(); String compliancePayloadString = new Gson().toJson(compliancePayload); // Parsing json string to get compliance features. JsonElement jsonElement; @@ -75,6 +73,8 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService { JsonArray jsonArray = jsonElement.getAsJsonArray(); Gson gson = new Gson(); ComplianceFeature complianceFeature; + List complianceFeatures = new ArrayList(jsonArray.size()); + List nonComplianceFeatures = new ArrayList<>(); for (JsonElement element : jsonArray) { complianceFeature = gson.fromJson(element, ComplianceFeature.class); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java index f3ed7b8b3d..e49e14d32e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java @@ -43,7 +43,7 @@ public class GCMService { } public void sendNotification(String messageData, Device device) { - List devices = new ArrayList<>(); + List devices = new ArrayList<>(1); devices.add(device); GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices); if (result.getStatusCode() != 200) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java index 6e59b2d435..b00ae96394 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java @@ -134,7 +134,7 @@ public class GCMUtil { } private static List getGCMTokens(List devices) { - List tokens = new ArrayList<>(); + List tokens = new ArrayList<>(devices.size()); for (Device device : devices) { tokens.add(getGCMToken(device.getProperties())); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index ab7d451a07..a9a7d9d6ae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -193,7 +193,7 @@ public class WindowsDeviceManager implements DeviceManager { WindowsDAOFactory.openConnection(); List mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices(); if (mobileDevices != null) { - devices = new ArrayList<>(); + devices = new ArrayList<>(mobileDevices.size()); for (MobileDevice mobileDevice : mobileDevices) { devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 0dca8b5d67..00e1d5e009 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -58,7 +58,7 @@ public class WindowsFeatureManager implements FeatureManager { @Override public boolean addFeatures(List features) throws DeviceManagementException { - List mobileFeatures = new ArrayList(); + List mobileFeatures = new ArrayList(features.size()); for (Feature feature : features) { mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); } @@ -92,10 +92,10 @@ public class WindowsFeatureManager implements FeatureManager { @Override public List getFeatures() throws DeviceManagementException { - List featureList = new ArrayList(); try { WindowsDAOFactory.openConnection(); List mobileFeatures = featureDAO.getAllFeatures(); + List featureList = new ArrayList(mobileFeatures.size()); for (MobileFeature mobileFeature : mobileFeatures) { featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index edecd3a768..73612a365b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -165,7 +165,7 @@ public class MobileDeviceManagementUtil { public static List getMobileOperationIdsFromMobileDeviceOperations( List mobileDeviceOperationMappings) { - List mobileOperationIds = new ArrayList(); + List mobileOperationIds = new ArrayList(mobileDeviceOperationMappings.size()); for (MobileDeviceOperationMapping mobileDeviceOperationMapping : mobileDeviceOperationMappings) { mobileOperationIds.add(mobileDeviceOperationMapping.getOperationId()); }