related to issue 40564: minor code improvements
authorCarlos Aristu <carlos.aristu@openbravo.com>
Fri, 12 Apr 2019 10:11:29 +0200
changeset 35693 f3ff80a1ad20
parent 35692 c40147ef32b3
child 35694 2ccef54104f1
related to issue 40564: minor code improvements

- Use isEmpty() to check whether the collection is empty or not
- Use diamond operator
- Removed useless assignment for "alertListToRemove"
- Immediately return the result instead of assigning it to the temporary "total" variable
modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertActionHandler.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java	Fri Apr 12 09:55:18 2019 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java	Fri Apr 12 10:11:29 2019 +0200
@@ -151,7 +151,7 @@
 
   private List<String> getAlertIdsFromAlertRules(
       Map<String, List<String>> alertRulesGroupByFilterClause, String alertStatus) {
-    List<String> alertIds = new ArrayList<String>();
+    List<String> alertIds = new ArrayList<>();
     for (Entry<String, List<String>> alertRuleList : alertRulesGroupByFilterClause.entrySet()) {
       String filterClause;
       try {
@@ -206,9 +206,8 @@
     List<String> alertList = getAlertIds(alertStatus);
     int chunkSize = 1000;
     String whereClause = "";
-    ArrayList<String> alertListToRemove;
 
-    if (alertList.size() == 0) {
+    if (alertList.isEmpty()) {
       return "1 = 2";
     }
 
@@ -218,9 +217,8 @@
 
     // There are more than 1000 alerts to include in the where clause, Oracle doesn't
     // support it, so let's split them in chunks with <=1000 elements each
-    alertListToRemove = new ArrayList<String>();
     while (alertList.size() > chunkSize) {
-      alertListToRemove = new ArrayList<String>(alertList.subList(0, chunkSize - 1));
+      ArrayList<String> alertListToRemove = new ArrayList<>(alertList.subList(0, chunkSize - 1));
       if (StringUtils.isEmpty(whereClause)) {
         whereClause = "(e.id in (" + commaSeparated(alertListToRemove) + ")";
       } else {
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertActionHandler.java	Fri Apr 12 09:55:18 2019 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertActionHandler.java	Fri Apr 12 10:11:29 2019 +0200
@@ -131,15 +131,13 @@
         .setParameterList("clients", OBContext.getOBContext().getReadableClients())
         .setParameterList("orgs", OBContext.getOBContext().getReadableClients());
 
-    long total = qry.stream()
+    return qry.stream()
         .collect(groupingBy(rule -> Objects.toString(rule.getFilterClause(), ""))) // null can't be
                                                                                    // key
         .values()
         .stream()
         .mapToLong(rulesByFilterClause -> countActiveAlertsForRules(rulesByFilterClause, vars))
         .sum();
-
-    return total;
   }
 
   private long countActiveAlertsForRules(List<AlertRule> rules, VariablesSecureApp vars) {