From b73db446ac9681fdfc4ad602c6da7ce3e36a8588 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 5 Nov 2015 14:16:35 +0200 Subject: java: combine nested if statements Change-Id: I0457b81668e9427a3c8d6a4af93438b7fb2bb7ba --- wizards/com/sun/star/wizards/common/JavaTools.java | 8 +- .../com/sun/star/wizards/common/Properties.java | 11 +- .../sun/star/wizards/common/PropertySetHelper.java | 7 +- wizards/com/sun/star/wizards/db/DBMetaData.java | 14 +- .../com/sun/star/wizards/db/TableDescriptor.java | 17 +-- wizards/com/sun/star/wizards/db/TypeInspector.java | 7 +- .../sun/star/wizards/form/FormConfiguration.java | 7 +- .../com/sun/star/wizards/form/FormDocument.java | 13 +- wizards/com/sun/star/wizards/query/Finalizer.java | 13 +- wizards/com/sun/star/wizards/table/Finalizer.java | 152 ++++++++++----------- .../sun/star/wizards/table/PrimaryKeyHandler.java | 16 +-- .../com/sun/star/wizards/table/TableWizard.java | 11 +- .../star/wizards/ui/DBLimitedFieldSelection.java | 23 ++-- 13 files changed, 126 insertions(+), 173 deletions(-) (limited to 'wizards') diff --git a/wizards/com/sun/star/wizards/common/JavaTools.java b/wizards/com/sun/star/wizards/common/JavaTools.java index cfeb1427cac7..65bb3f644840 100644 --- a/wizards/com/sun/star/wizards/common/JavaTools.java +++ b/wizards/com/sun/star/wizards/common/JavaTools.java @@ -126,11 +126,9 @@ public class JavaTools int FieldLen = SearchList.length; if (FieldLen > 0) { for (int i = 0; i < FieldLen; i++) { - if (SearchList[i][0] != null) { - if (SearchList[i][0].equals(SearchString)) { - retvalue = i; - break; - } + if (SearchList[i][0] != null && SearchList[i][0].equals(SearchString)) { + retvalue = i; + break; } } } diff --git a/wizards/com/sun/star/wizards/common/Properties.java b/wizards/com/sun/star/wizards/common/Properties.java index 764703c74ac2..2056921d36c6 100644 --- a/wizards/com/sun/star/wizards/common/Properties.java +++ b/wizards/com/sun/star/wizards/common/Properties.java @@ -72,15 +72,12 @@ public class Properties extends HashMap public static PropertyValue[] convertToPropertyValueArray(Object[] _oObjectArray) { PropertyValue[] retproperties = null; - if (_oObjectArray != null) + if (_oObjectArray != null && _oObjectArray.length > 0) { - if (_oObjectArray.length > 0) + retproperties = new PropertyValue[_oObjectArray.length]; + for (int i = 0; i < _oObjectArray.length; i++) { - retproperties = new PropertyValue[_oObjectArray.length]; - for (int i = 0; i < _oObjectArray.length; i++) - { - retproperties[i] = (PropertyValue) _oObjectArray[i]; - } + retproperties[i] = (PropertyValue) _oObjectArray[i]; } } return retproperties; diff --git a/wizards/com/sun/star/wizards/common/PropertySetHelper.java b/wizards/com/sun/star/wizards/common/PropertySetHelper.java index 1def4f063580..0fb0959a0f18 100644 --- a/wizards/com/sun/star/wizards/common/PropertySetHelper.java +++ b/wizards/com/sun/star/wizards/common/PropertySetHelper.java @@ -167,12 +167,9 @@ public class PropertySetHelper DebugHelper.writeInfo(e.getMessage()); } } - if (aObject == null) + if (aObject == null && getHashMap().containsKey(_sName)) { - if (getHashMap().containsKey(_sName)) - { - aObject = getHashMap().get(_sName); - } + aObject = getHashMap().get(_sName); } if (aObject != null) { diff --git a/wizards/com/sun/star/wizards/db/DBMetaData.java b/wizards/com/sun/star/wizards/db/DBMetaData.java index d62a547803c4..0b03f0453024 100644 --- a/wizards/com/sun/star/wizards/db/DBMetaData.java +++ b/wizards/com/sun/star/wizards/db/DBMetaData.java @@ -324,12 +324,9 @@ public class DBMetaData public String[] getQueryNames() { - if (QueryNames != null) + if (QueryNames != null && QueryNames.length > 0) { - if (QueryNames.length > 0) - { - return QueryNames; - } + return QueryNames; } QueryNames = getQueryNamesAsNameAccess().getElementNames(); return QueryNames; @@ -337,12 +334,9 @@ public class DBMetaData public String[] getTableNames() { - if (TableNames != null) + if (TableNames != null && TableNames.length > 0) { - if (TableNames.length > 0) - { - return TableNames; - } + return TableNames; } TableNames = getTableNamesAsNameAccess().getElementNames(); return TableNames; diff --git a/wizards/com/sun/star/wizards/db/TableDescriptor.java b/wizards/com/sun/star/wizards/db/TableDescriptor.java index ee9c427ba6f2..2db69f52c31c 100644 --- a/wizards/com/sun/star/wizards/db/TableDescriptor.java +++ b/wizards/com/sun/star/wizards/db/TableDescriptor.java @@ -351,18 +351,15 @@ public class TableDescriptor extends CommandMetaData implements XContainerListen private void assignTableProperty(String _spropname, String _svalue) { - if (_svalue != null) + if (_svalue != null && !_svalue.equals(PropertyNames.EMPTY_STRING)) { - if (!_svalue.equals(PropertyNames.EMPTY_STRING)) + try { - try - { - xPropTableDataDescriptor.setPropertyValue(_spropname, _svalue); - } - catch (Exception e) - { - e.printStackTrace(System.err); - } + xPropTableDataDescriptor.setPropertyValue(_spropname, _svalue); + } + catch (Exception e) + { + e.printStackTrace(System.err); } } } diff --git a/wizards/com/sun/star/wizards/db/TypeInspector.java b/wizards/com/sun/star/wizards/db/TypeInspector.java index bc9f696a4e86..4acc32e1af08 100644 --- a/wizards/com/sun/star/wizards/db/TypeInspector.java +++ b/wizards/com/sun/star/wizards/db/TypeInspector.java @@ -322,12 +322,9 @@ public class TypeInspector int i = JavaTools.FieldInIntTable(nDataTypeInfos, curDataType, startindex); startindex = i + 1; bleaveloop = (i == -1); - if (!bleaveloop) + if (!bleaveloop && bisAutoIncrementableInfos[i]) { - if (bisAutoIncrementableInfos[i]) - { - return nDataTypeInfos[i]; - } + return nDataTypeInfos[i]; } } } diff --git a/wizards/com/sun/star/wizards/form/FormConfiguration.java b/wizards/com/sun/star/wizards/form/FormConfiguration.java index dbdaa6272be3..9782a5aa25ea 100644 --- a/wizards/com/sun/star/wizards/form/FormConfiguration.java +++ b/wizards/com/sun/star/wizards/form/FormConfiguration.java @@ -203,12 +203,9 @@ public class FormConfiguration if (areexistingRelationsdefined()) { short[] iselected = (short[]) Helper.getUnoArrayPropertyValue(UnoDialog.getModel(lstRelations), PropertyNames.SELECTED_ITEMS); - if (iselected != null) + if (iselected != null && iselected.length > 0) { - if (iselected.length > 0) - { - return sreferencedTables[iselected[0]]; - } + return sreferencedTables[iselected[0]]; } } return PropertyNames.EMPTY_STRING; diff --git a/wizards/com/sun/star/wizards/form/FormDocument.java b/wizards/com/sun/star/wizards/form/FormDocument.java index 532c979b5f61..72faa38c491c 100644 --- a/wizards/com/sun/star/wizards/form/FormDocument.java +++ b/wizards/com/sun/star/wizards/form/FormDocument.java @@ -299,15 +299,12 @@ public class FormDocument extends TextDocument { LinkFieldNames = _curFieldLinker.getLinkFieldNames(_curFormConfiguration.getRelationController(), sRefTableName); } - if (LinkFieldNames != null) + if (LinkFieldNames != null && LinkFieldNames.length > 0) { - if (LinkFieldNames.length > 0) - { - oSubControlForm.xPropertySet.setPropertyValue("DetailFields", LinkFieldNames[0]); - oSubControlForm.xPropertySet.setPropertyValue("MasterFields", LinkFieldNames[1]); - oSubControlForm.finalizeControls(); - return true; - } + oSubControlForm.xPropertySet.setPropertyValue("DetailFields", LinkFieldNames[0]); + oSubControlForm.xPropertySet.setPropertyValue("MasterFields", LinkFieldNames[1]); + oSubControlForm.finalizeControls(); + return true; } return false; } diff --git a/wizards/com/sun/star/wizards/query/Finalizer.java b/wizards/com/sun/star/wizards/query/Finalizer.java index 8efe9abf76ed..a14923b4d75c 100644 --- a/wizards/com/sun/star/wizards/query/Finalizer.java +++ b/wizards/com/sun/star/wizards/query/Finalizer.java @@ -140,15 +140,12 @@ public class Finalizer try { String sCurQueryName = AnyConverter.toString(Helper.getUnoPropertyValue(UnoDialog.getModel(m_aTxtTitle), "Text")); - if (sCurQueryName != null) + if (sCurQueryName != null && sCurQueryName.equals(PropertyNames.EMPTY_STRING)) { - if (sCurQueryName.equals(PropertyNames.EMPTY_STRING)) - { - String[] sCommandNames = CurDBMetaData.getIncludedCommandNames(); - sCurQueryName = resQuery + "_" + sCommandNames[0]; - sCurQueryName = CurDBMetaData.suggestName( CommandType.QUERY, sCurQueryName ); - Helper.setUnoPropertyValue(UnoDialog.getModel(m_aTxtTitle), "Text", sCurQueryName); - } + String[] sCommandNames = CurDBMetaData.getIncludedCommandNames(); + sCurQueryName = resQuery + "_" + sCommandNames[0]; + sCurQueryName = CurDBMetaData.suggestName( CommandType.QUERY, sCurQueryName ); + Helper.setUnoPropertyValue(UnoDialog.getModel(m_aTxtTitle), "Text", sCurQueryName); } CurDBMetaData.setSummaryString(); m_queryWizard.setControlProperty("txtSummary", "Text", CurDBMetaData.getSummaryString()); diff --git a/wizards/com/sun/star/wizards/table/Finalizer.java b/wizards/com/sun/star/wizards/table/Finalizer.java index b824d515e9cd..86496efedbfb 100644 --- a/wizards/com/sun/star/wizards/table/Finalizer.java +++ b/wizards/com/sun/star/wizards/table/Finalizer.java @@ -93,110 +93,104 @@ public class Finalizer txtTableName.setMaxTextLen((short) this.curtabledescriptor.getMaxTableNameLength()); if (this.curtabledescriptor.xDBMetaData.supportsCatalogsInTableDefinitions()) { - if (sCatalogNames != null) + if (sCatalogNames != null && sCatalogNames.length > 0) { - if (sCatalogNames.length > 0) + bsupportsCatalogs = true; + String sCatalog = PropertyNames.EMPTY_STRING; + try { - bsupportsCatalogs = true; - String sCatalog = PropertyNames.EMPTY_STRING; - try - { - sCatalog = curtabledescriptor.DBConnection.getCatalog(); - } - catch (SQLException e1) - { - e1.printStackTrace(System.err); - } - CurUnoDialog.insertLabel("lblCatalog", + sCatalog = curtabledescriptor.DBConnection.getCatalog(); + } + catch (SQLException e1) + { + e1.printStackTrace(System.err); + } + CurUnoDialog.insertLabel("lblCatalog", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, slblCatalog, Integer.valueOf(nListBoxPosX), 52, IFINALSTEP, Short.valueOf(curtabindex++), 120 + }); + + try + { + xCatalogListBox = CurUnoDialog.insertListBox("lstCatalog", null, null, new String[] { - PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH }, new Object[] { - 8, slblCatalog, Integer.valueOf(nListBoxPosX), 52, IFINALSTEP, Short.valueOf(curtabindex++), 120 + Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_CATALOG", Short.valueOf(UnoDialog.getListBoxLineCount()), Integer.valueOf(nListBoxPosX), 62, IFINALSTEP, sCatalogNames, Short.valueOf(curtabindex++), 80 }); - - try - { - xCatalogListBox = CurUnoDialog.insertListBox("lstCatalog", null, null, - new String[] - { - "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH - }, - new Object[] - { - Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_CATALOG", Short.valueOf(UnoDialog.getListBoxLineCount()), Integer.valueOf(nListBoxPosX), 62, IFINALSTEP, sCatalogNames, Short.valueOf(curtabindex++), 80 - }); - int isel = JavaTools.FieldInList(sCatalogNames, sCatalog); - if (isel < 0) - { - isel = 0; - } - CurUnoDialog.setControlProperty("lstCatalog", PropertyNames.SELECTED_ITEMS, new short[] - { - (short) isel - }); - } - catch (Exception e) + int isel = JavaTools.FieldInList(sCatalogNames, sCatalog); + if (isel < 0) { - e.printStackTrace(System.err); + isel = 0; } - nListBoxPosX = 200; + CurUnoDialog.setControlProperty("lstCatalog", PropertyNames.SELECTED_ITEMS, new short[] + { + (short) isel + }); + } + catch (Exception e) + { + e.printStackTrace(System.err); } + nListBoxPosX = 200; } } if (this.curtabledescriptor.xDBMetaData.supportsSchemasInTableDefinitions()) { - if (sSchemaNames != null) + if (sSchemaNames != null && sSchemaNames.length > 0) { - if (sSchemaNames.length > 0) + bsupportsSchemata = true; + String sSchema = PropertyNames.EMPTY_STRING; + try { - bsupportsSchemata = true; - String sSchema = PropertyNames.EMPTY_STRING; - try - { - sSchema = (String) curtabledescriptor.getDataSourcePropertySet().getPropertyValue("User"); - } - catch (Exception e1) - { - e1.printStackTrace(System.err); - } - CurUnoDialog.insertLabel("lblSchema", + sSchema = (String) curtabledescriptor.getDataSourcePropertySet().getPropertyValue("User"); + } + catch (Exception e1) + { + e1.printStackTrace(System.err); + } + CurUnoDialog.insertLabel("lblSchema", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, slblSchema, Integer.valueOf(nListBoxPosX), 52, IFINALSTEP, Short.valueOf(curtabindex++), 80 + }); + + try + { + xSchemaListBox = CurUnoDialog.insertListBox("lstSchema", null, null, new String[] { - PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH }, new Object[] { - 8, slblSchema, Integer.valueOf(nListBoxPosX), 52, IFINALSTEP, Short.valueOf(curtabindex++), 80 + Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_SCHEMA", Short.valueOf(UnoDialog.getListBoxLineCount()), Integer.valueOf(nListBoxPosX), 62, IFINALSTEP, sSchemaNames, Short.valueOf(curtabindex++), 80 }); - - try - { - xSchemaListBox = CurUnoDialog.insertListBox("lstSchema", null, null, - new String[] - { - "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH - }, - new Object[] - { - Boolean.TRUE, 12, "HID:WIZARDS_HID_DLGTABLE_LST_SCHEMA", Short.valueOf(UnoDialog.getListBoxLineCount()), Integer.valueOf(nListBoxPosX), 62, IFINALSTEP, sSchemaNames, Short.valueOf(curtabindex++), 80 - }); - int isel = JavaTools.FieldInList(sSchemaNames, sSchema); - if (isel < 0) - { - isel = 0; - } - CurUnoDialog.setControlProperty("lstSchema", PropertyNames.SELECTED_ITEMS, new short[] - { - (short) isel - }); - } - catch (Exception e) + int isel = JavaTools.FieldInList(sSchemaNames, sSchema); + if (isel < 0) { - e.printStackTrace(System.err); + isel = 0; } + CurUnoDialog.setControlProperty("lstSchema", PropertyNames.SELECTED_ITEMS, new short[] + { + (short) isel + }); + } + catch (Exception e) + { + e.printStackTrace(System.err); } } } diff --git a/wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java b/wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java index 4f5b2d22a694..e45c3dab97c0 100644 --- a/wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java +++ b/wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java @@ -224,13 +224,10 @@ public class PrimaryKeyHandler implements XFieldSelectionListener fieldnames = curTableDescriptor.getNonBinaryFieldNames(); String[] skeyfieldnames = curPrimaryKeySelection.getSelectedFieldNames(); curPrimaryKeySelection.initialize(fieldnames, false); - if (skeyfieldnames != null) + if (skeyfieldnames != null && skeyfieldnames.length > 0) { - if (skeyfieldnames.length > 0) - { - String[] snewkeyfieldnames = JavaTools.removeOutdatedFields(skeyfieldnames, fieldnames); - curPrimaryKeySelection.setSelectedFieldNames(snewkeyfieldnames); - } + String[] snewkeyfieldnames = JavaTools.removeOutdatedFields(skeyfieldnames, fieldnames); + curPrimaryKeySelection.setSelectedFieldNames(snewkeyfieldnames); } String selfield = lstSinglePrimeKey.getSelectedItem(); Helper.setUnoPropertyValue(UnoDialog.getModel(lstSinglePrimeKey), PropertyNames.STRING_ITEM_LIST, fieldnames); @@ -313,12 +310,9 @@ public class PrimaryKeyHandler implements XFieldSelectionListener try { XPropertySet xColPropertySet = curTableDescriptor.getByName(_fieldname); - if (xColPropertySet != null) + if (xColPropertySet != null && curTableDescriptor.getDBDataTypeInspector() != null) { - if (curTableDescriptor.getDBDataTypeInspector() != null) - { - return curTableDescriptor.getDBDataTypeInspector().isAutoIncrementable(xColPropertySet); - } + return curTableDescriptor.getDBDataTypeInspector().isAutoIncrementable(xColPropertySet); } } catch (Exception e) diff --git a/wizards/com/sun/star/wizards/table/TableWizard.java b/wizards/com/sun/star/wizards/table/TableWizard.java index 7acfb593938e..60632764a3e4 100644 --- a/wizards/com/sun/star/wizards/table/TableWizard.java +++ b/wizards/com/sun/star/wizards/table/TableWizard.java @@ -237,14 +237,11 @@ public class TableWizard extends DatabaseObjectWizard implements XTextListener if (curTableDescriptor.supportsPrimaryKeys()) { String[] keyfieldnames = curPrimaryKeyHandler.getPrimaryKeyFields(); - if (keyfieldnames != null) + if (keyfieldnames != null && keyfieldnames.length > 0) { - if (keyfieldnames.length > 0) - { - boolean bIsAutoIncrement = curPrimaryKeyHandler.isAutoIncremented(); - bIsSuccessfull = curTableDescriptor.createTable(catalogname, schemaname, tablename, keyfieldnames, bIsAutoIncrement); - bTableCreated = true; - } + boolean bIsAutoIncrement = curPrimaryKeyHandler.isAutoIncremented(); + bIsSuccessfull = curTableDescriptor.createTable(catalogname, schemaname, tablename, keyfieldnames, bIsAutoIncrement); + bTableCreated = true; } } if (!bTableCreated) diff --git a/wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java b/wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java index 270e19f77f8a..c08aa9996ef2 100644 --- a/wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java +++ b/wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java @@ -95,22 +95,19 @@ public abstract class DBLimitedFieldSelection { short[] SelList = null; Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.STRING_ITEM_LIST, _AllFieldNames); - if (_SelFieldNames != null) + if (_SelFieldNames != null && curindex < _SelFieldNames.length) { - if (curindex < _SelFieldNames.length) + int index = JavaTools.FieldInList(_AllFieldNames, _SelFieldNames[curindex]); + if (index > -1) { - int index = JavaTools.FieldInList(_AllFieldNames, _SelFieldNames[curindex]); - if (index > -1) - { - SelList = new short[] { (short) (index) }; - } - else - { - SelList = new short[] { (short) (0) }; - } - Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList); - return; + SelList = new short[] { (short) (index) }; } + else + { + SelList = new short[] { (short) (0) }; + } + Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList); + return; } SelList = new short[] { (short) (0) }; Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList); -- cgit