details: https://code.openbravo.com/erp/devel/pi/rev/f3ff80a1ad20 changeset: 35653:f3ff80a1ad20 user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Fri Apr 12 10:11:29 2019 +0200 summary: 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 diffstat: modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java | 8 +++----- modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertActionHandler.java | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diffs (54 lines): diff -r c40147ef32b3 -r f3ff80a1ad20 modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.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 { diff -r c40147ef32b3 -r f3ff80a1ad20 modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertActionHandler.java --- 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) { _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits