details: https://code.openbravo.com/erp/devel/pi/rev/75217c44f638 changeset: 35328:75217c44f638 user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Fri Jan 18 12:54:55 2019 +0100 summary: related to issue 38516: Initial code cleanup
- Use diamond operator - Remove the usage of the literal "false" boolean value. - Replaced if-then-else statement by a single return statement in isDataSourceTable() - Use isEmpty() to check whether the collection is empty or not - Removed commented-out line of code - Add missing "@Override" annotation above getComponentTemplate() signature - Iterate over the "entrySet" instead of the "keySet" - Put single-quotes around '/' to use the faster "indexOf(char)" method. - Define a constant instead of duplicating literal "OBUIAPP_PickAndExecute" 5 times diffstat: modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java | 69 ++++----- 1 files changed, 34 insertions(+), 35 deletions(-) diffs (261 lines): diff -r 8d73ffc2b531 -r 75217c44f638 modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java Thu Jan 17 14:57:34 2019 +0530 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java Fri Jan 18 12:54:55 2019 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2010-2018 Openbravo SLU + * All portions are Copyright (C) 2010-2019 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -26,6 +26,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import javax.inject.Inject; @@ -80,17 +81,18 @@ private static final Logger log = LogManager.getLogger(); private static final String DEFAULT_TEMPLATE_ID = "B5124C0A450D4D3A867AEAC7DF64D6F0"; - protected static final Map<String, String> TEMPLATE_MAP = new HashMap<String, String>(); + private static final String PICK_AND_EXECUTE = "OBUIAPP_PickAndExecute"; + protected static final Map<String, String> TEMPLATE_MAP = new HashMap<>(); static { // Map: WindowType - Template - TEMPLATE_MAP.put("OBUIAPP_PickAndExecute", "FF808181330BD14F01330BD34EA00008"); + TEMPLATE_MAP.put(PICK_AND_EXECUTE, "FF808181330BD14F01330BD34EA00008"); } private Entity entity; private Tab tab; private String tabTitle; - private List<OBViewTab> childTabs = new ArrayList<OBViewTab>(); + private List<OBViewTab> childTabs = new ArrayList<>(); private OBViewTab parentTabComponent; private String parentProperty = null; private List<ButtonField> buttonFields = null; @@ -101,7 +103,7 @@ private boolean isRootTab; private String uniqueString = "" + System.currentTimeMillis(); - private Map<String, String> preferenceAttributesMap = new HashMap<String, String>(); + private Map<String, String> preferenceAttributesMap = new HashMap<>(); @Inject private OBViewFieldHandler fieldHandler; @@ -114,9 +116,9 @@ public String getDataSourceJavaScript() { final String dsId = getDataSourceId(); - final Map<String, Object> dsParameters = new HashMap<String, Object>(getParameters()); + final Map<String, Object> dsParameters = new HashMap<>(getParameters()); dsParameters.put(DataSourceConstants.DS_ONLY_GENERATE_CREATESTATEMENT, true); - if ("OBUIAPP_PickAndExecute".equals(tab.getWindow().getWindowType())) { + if (PICK_AND_EXECUTE.equals(tab.getWindow().getWindowType())) { dsParameters.put(DataSourceConstants.DS_CLASS_NAME, "OBPickAndExecuteDataSource"); } else { dsParameters.put(DataSourceConstants.DS_CLASS_NAME, "OBViewDataSource"); @@ -143,20 +145,21 @@ } DataSourceComponent component = (DataSourceComponent) dsComponentProvider.getComponent(dsId, dsParameters); - if ("OBUIAPP_PickAndExecute".equals(tab.getWindow().getWindowType())) { + if (PICK_AND_EXECUTE.equals(tab.getWindow().getWindowType())) { component.setIncludeCreationCode(false); } return component.generate(); } public String getNotesDataSourceJavaScript() { - final Map<String, Object> dsParameters = new HashMap<String, Object>(getParameters()); + final Map<String, Object> dsParameters = new HashMap<>(getParameters()); dsParameters.put(DataSourceConstants.DS_ONLY_GENERATE_CREATESTATEMENT, true); final Component component = dsComponentProvider.getComponent( "090A37D22E61FE94012E621729090048", dsParameters); return component.generate(); } + @Override protected Template getComponentTemplate() { final String windowType = tab.getWindow().getWindowType(); if (TEMPLATE_MAP.containsKey(windowType)) { @@ -170,7 +173,7 @@ } public List<OtherField> getOtherFields() { - final List<OtherField> otherFields = new ArrayList<OBViewTab.OtherField>(); + final List<OtherField> otherFields = new ArrayList<>(); for (Field fld : fieldHandler.getIgnoredFields()) { if (fld.getColumn() == null) { continue; @@ -195,7 +198,7 @@ } public boolean getDefaultEditMode() { - return tab.isDefaultEditMode() == null ? false : tab.isDefaultEditMode(); + return tab.isDefaultEditMode() != null && tab.isDefaultEditMode(); } public String getMapping250() { @@ -206,8 +209,8 @@ if (buttonFields != null) { return buttonFields; } - buttonFields = new ArrayList<ButtonField>(); - final List<Field> adFields = new ArrayList<Field>(tab.getADFieldList()); + buttonFields = new ArrayList<>(); + final List<Field> adFields = new ArrayList<>(tab.getADFieldList()); Collections.sort(adFields, new FormFieldComparator()); for (Field fld : adFields) { if (fld.isActive() && fld.isDisplayed()) { @@ -235,8 +238,8 @@ if (allButtonFields != null) { return allButtonFields; } - allButtonFields = new ArrayList<ButtonField>(); - final List<Field> adFields = new ArrayList<Field>(tab.getADFieldList()); + allButtonFields = new ArrayList<>(); + final List<Field> adFields = new ArrayList<>(tab.getADFieldList()); Collections.sort(adFields, new FormFieldComparator()); for (Field fld : adFields) { if (fld.isActive()) { @@ -255,7 +258,7 @@ return iconButtons; } - iconButtons = new ArrayList<IconButton>(); + iconButtons = new ArrayList<>(); // Print/email button if (tab.getProcess() != null) { @@ -306,7 +309,7 @@ } private Collection<? extends IconButton> getPrintEmailButtons() { - List<IconButton> btns = new ArrayList<IconButton>(); + List<IconButton> btns = new ArrayList<>(); PrintButton printBtn = new PrintButton(); btns.add(printBtn); @@ -521,11 +524,8 @@ } public boolean isDataSourceTable() { - if (ApplicationConstants.DATASOURCEBASEDTABLE.equals(this.tab.getTable().getDataOriginType())) { - return true; - } else { - return false; - } + return ApplicationConstants.DATASOURCEBASEDTABLE + .equals(this.tab.getTable().getDataOriginType()); } public String getKeyPropertyType() { @@ -561,16 +561,16 @@ public String getProcessViews() { StringBuilder views = new StringBuilder(); // Use HashSet to avoid processId duplicities - HashSet<String> processIds = new HashSet<String>(); + HashSet<String> processIds = new HashSet<>(); for (ButtonField f : getButtonFields()) { // Get processes coming from action buttons if (f.column.getOBUIAPPProcess() == null - || !"OBUIAPP_PickAndExecute".equals(f.column.getOBUIAPPProcess().getUIPattern())) { + || !PICK_AND_EXECUTE.equals(f.column.getOBUIAPPProcess().getUIPattern())) { continue; } processIds.add(f.column.getOBUIAPPProcess().getId()); } - final List<Field> adFields = new ArrayList<Field>(tab.getADFieldList()); + final List<Field> adFields = new ArrayList<>(tab.getADFieldList()); Collections.sort(adFields, new FormFieldComparator()); for (Field fld : adFields) { // Get processes coming from selectors @@ -579,7 +579,7 @@ continue; } List<Selector> selectors = fld.getColumn().getReferenceSearchKey().getOBUISELSelectorList(); - if (selectors.size() == 0) { + if (selectors.isEmpty()) { continue; } Selector selector = selectors.get(0); @@ -599,7 +599,6 @@ processWindow.setProcess(process); processWindow.setParentWindow(getTab().getWindow()); processWindow.setPoup(true); - // processWindow.setWindow(OBDal.getInstance().get(Window.class, f.getWindowId())); views.append(processWindow.generate()).append("\n"); } return views.toString(); @@ -704,8 +703,8 @@ if (!preferenceAttributesMap.isEmpty()) { try { JSONObject preferenceAttributesJSON = new JSONObject(); - for (String attr : preferenceAttributesMap.keySet()) { - preferenceAttributesJSON.put(attr, preferenceAttributesMap.get(attr)); + for (Entry<String, String> entry : preferenceAttributesMap.entrySet()) { + preferenceAttributesJSON.put(entry.getKey(), entry.getValue()); } preferenceAttributes = preferenceAttributesJSON.toString(); } catch (JSONException e) { @@ -735,7 +734,7 @@ public List<String> getDisplayLogicFields() { boolean getOnlyFirstLevelSubTabs = false; List<Tab> subTabs = KernelUtils.getInstance().getTabSubtabs(tab, getOnlyFirstLevelSubTabs); - List<String> displayLogicFields = new ArrayList<String>(); + List<String> displayLogicFields = new ArrayList<>(); for (Tab subTab : subTabs) { if (subTab.getDisplayLogic() != null && !subTab.getDisplayLogic().isEmpty()) { boolean inpColumnNames = true; @@ -795,7 +794,7 @@ multiRecord = newProcess.isMultiRecord(); setWindowId(tab.getWindow().getId()); - if ("OBUIAPP_PickAndExecute".equals(uiPattern)) { + if (PICK_AND_EXECUTE.equals(uiPattern)) { // TODO: modal should be a parameter in the process definition? modal = false; } @@ -836,7 +835,7 @@ } if (labelValues == null) { - labelValues = new ArrayList<Value>(); + labelValues = new ArrayList<>(); if (column.getReferenceSearchKey() != null) { for (org.openbravo.model.ad.domain.List valueList : column.getReferenceSearchKey() @@ -851,7 +850,7 @@ final DynamicExpressionParser parser = new DynamicExpressionParser(fld.getDisplayLogic(), tab, fld); showIf = parser.getJSExpression(); - if (parser.getSessionAttributes().size() > 0) { + if (!parser.getSessionAttributes().isEmpty()) { sessionLogic = true; } } @@ -861,7 +860,7 @@ final DynamicExpressionParser parser = new DynamicExpressionParser(fld.getColumn() .getReadOnlyLogic(), tab); readOnlyIf = parser.getJSExpression(); - if (parser.getSessionAttributes().size() > 0) { + if (!parser.getSessionAttributes().isEmpty()) { sessionLogic = true; } } @@ -1032,7 +1031,7 @@ if (processUrl.isEmpty()) { processUrl = process.getSearchKey() + ".pdf"; } - if (processUrl.indexOf("/") == -1) { + if (processUrl.indexOf('/') == -1) { processUrl = "/" + FormatUtilities.replace(processUrl); } } _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits