From 4b4bff34027cca49fd13e82d33d1b399848838fa Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 12 Aug 2014 15:27:21 +0200 Subject: java: no need to instantiate String objects directly Change-Id: I7610774c94bf673ed3b574ffce04c4ee6ca93c03 --- .../CreatingDialogs/SampleDialog.java | 6 ++--- .../DevelopersGuide/Charts/CalcHelper.java | 2 +- .../Charts/JavaSampleChartAddIn.java | 6 ++--- .../Charts/ListenAtCalcRangeInDraw.java | 2 +- .../ProtocolHandlerAddon.java | 2 +- .../dialogcomponent/DialogComponent.java | 2 +- .../DevelopersGuide/Forms/DataAwareness.java | 10 ++++----- .../DevelopersGuide/Forms/DocumentViewHelper.java | 4 ++-- .../DevelopersGuide/Forms/GridFieldValidator.java | 4 ++-- .../DevelopersGuide/Forms/KeyGenerator.java | 4 ++-- .../DevelopersGuide/Forms/SalesFilter.java | 2 +- .../Forms/SingleControlValidation.java | 8 +++---- .../Forms/TableCellTextBinding.java | 2 +- .../OfficeDev/ContextMenuInterceptor.java | 26 +++++++++++----------- .../OfficeDev/DesktopEnvironment/Desk.java | 4 ++-- .../DesktopEnvironment/FunctionHelper.java | 14 ++++++------ .../DisableCommands/DisableCommandsTest.java | 14 ++++++------ .../AsciiFilter/AsciiReplaceFilter.java | 2 +- .../AsciiFilter/FilterOptions.java | 4 ++-- .../OfficeDev/Linguistic/XHyphenatedWord_impl.java | 4 ++-- .../OfficeDev/Linguistic/XMeaning_impl.java | 2 +- .../Linguistic/XPossibleHyphens_impl.java | 4 ++-- .../Linguistic/XSpellAlternatives_impl.java | 2 +- odk/examples/DevelopersGuide/UCB/Helper.java | 7 +++--- .../EmbeddedObject/OwnEmbeddedObject.java | 4 ++-- .../java/Inspector/ProtocolHandlerAddon.java | 2 +- odk/examples/java/Text/StyleCreation.java | 4 ++-- odk/examples/java/Text/StyleInitialization.java | 2 +- 28 files changed, 74 insertions(+), 75 deletions(-) (limited to 'odk') diff --git a/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/SampleDialog.java b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/SampleDialog.java index c455e5ff9f2d..2b25f21fba1b 100644 --- a/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/SampleDialog.java +++ b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/SampleDialog.java @@ -151,7 +151,7 @@ public class SampleDialog extends WeakBase implements XServiceInfo, XJobExecutor xPSetDialog.setPropertyValue( "PositionY", Integer.valueOf( 100 ) ); xPSetDialog.setPropertyValue( "Width", Integer.valueOf( 150 ) ); xPSetDialog.setPropertyValue( "Height", Integer.valueOf( 100 ) ); - xPSetDialog.setPropertyValue( "Title", new String( "Runtime Dialog Demo" ) ); + xPSetDialog.setPropertyValue( "Title", "Runtime Dialog Demo" ); // get the service manager from the dialog model XMultiServiceFactory xMultiServiceFactory = ( XMultiServiceFactory )UnoRuntime.queryInterface( @@ -168,7 +168,7 @@ public class SampleDialog extends WeakBase implements XServiceInfo, XJobExecutor xPSetButton.setPropertyValue( "Height", Integer.valueOf( 14 ) ); xPSetButton.setPropertyValue( "Name", _buttonName ); xPSetButton.setPropertyValue( "TabIndex", Short.valueOf( (short)0 ) ); - xPSetButton.setPropertyValue( "Label", new String( "Click Me" ) ); + xPSetButton.setPropertyValue( "Label", "Click Me" ); // create the label model and set the properties Object labelModel = xMultiServiceFactory.createInstance( @@ -195,7 +195,7 @@ public class SampleDialog extends WeakBase implements XServiceInfo, XJobExecutor xPSetCancelButton.setPropertyValue( "Name", _cancelButtonName ); xPSetCancelButton.setPropertyValue( "TabIndex", Short.valueOf( (short)2 ) ); xPSetCancelButton.setPropertyValue( "PushButtonType", Short.valueOf( (short)2 ) ); - xPSetCancelButton.setPropertyValue( "Label", new String( "Cancel" ) ); + xPSetCancelButton.setPropertyValue( "Label", "Cancel" ); // insert the control models into the dialog model XNameContainer xNameCont = ( XNameContainer )UnoRuntime.queryInterface( diff --git a/odk/examples/DevelopersGuide/Charts/CalcHelper.java b/odk/examples/DevelopersGuide/Charts/CalcHelper.java index fa02dc398ac0..ca9ea94438d3 100644 --- a/odk/examples/DevelopersGuide/Charts/CalcHelper.java +++ b/odk/examples/DevelopersGuide/Charts/CalcHelper.java @@ -303,7 +303,7 @@ public class CalcHelper } else { - aFormula = new String( "=" ); + aFormula = "="; if( nCol % 2 == 0 ) aFormula += "SIN"; else diff --git a/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java b/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java index 8d15ff9d95d5..31b3cf888598 100644 --- a/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java +++ b/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java @@ -283,7 +283,7 @@ public class JavaSampleChartAddIn extends WeakBase implements // XServiceName public String getServiceName() throws RuntimeException { - return new String( smServiceName ); + return smServiceName; } // XServiceInfo @@ -312,7 +312,7 @@ public class JavaSampleChartAddIn extends WeakBase implements // XDiagram public String getDiagramType() throws RuntimeException { - return new String( smServiceName ); + return smServiceName; } public XPropertySet getDataRowProperties( int nRow ) @@ -349,7 +349,7 @@ public class JavaSampleChartAddIn extends WeakBase implements // XShapeDescriptor : XShape : XDiagram public String getShapeType() throws RuntimeException { - return new String( "com.sun.star.comp.Chart.JavaSampleDiagramShape" ); + return "com.sun.star.comp.Chart.JavaSampleDiagramShape"; } diff --git a/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java b/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java index 60ac0b0d5b26..30700ed90faf 100644 --- a/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java +++ b/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java @@ -159,7 +159,7 @@ public class ListenAtCalcRangeInDraw implements XChartDataChangeEventListener public void chartDataChanged( ChartDataChangeEvent aEvent ) { // update subtitle - String aTitle = new String( "Last Update: " + new java.util.Date( System.currentTimeMillis() )); + String aTitle = "Last Update: " + new java.util.Date(); try { diff --git a/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java b/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java index bb1cdb86109d..8c2e95af56f5 100644 --- a/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java +++ b/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java @@ -206,7 +206,7 @@ public class ProtocolHandlerAddon { // describe window properties. WindowDescriptor aDescriptor = new WindowDescriptor(); aDescriptor.Type = WindowClass.MODALTOP; - aDescriptor.WindowServiceName = new String( "infobox" ); + aDescriptor.WindowServiceName = "infobox"; aDescriptor.ParentIndex = -1; aDescriptor.Parent = UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow()); diff --git a/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java b/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java index 7376fddab860..4004a50a9c3e 100644 --- a/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java +++ b/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java @@ -171,7 +171,7 @@ public class DialogComponent { // describe window properties. WindowDescriptor aDescriptor = new WindowDescriptor(); aDescriptor.Type = WindowClass.MODALTOP; - aDescriptor.WindowServiceName = new String( "infobox" ); + aDescriptor.WindowServiceName = "infobox"; aDescriptor.ParentIndex = -1; aDescriptor.Parent = UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow()); diff --git a/odk/examples/DevelopersGuide/Forms/DataAwareness.java b/odk/examples/DevelopersGuide/Forms/DataAwareness.java index 1386aa316385..f831d63fa86c 100644 --- a/odk/examples/DevelopersGuide/Forms/DataAwareness.java +++ b/odk/examples/DevelopersGuide/Forms/DataAwareness.java @@ -70,7 +70,7 @@ class PrintComponentTree extends ComponentTreeTraversal public PrintComponentTree() { - m_sPrefix = new String(); + m_sPrefix = ""; } @Override @@ -186,11 +186,11 @@ public class DataAwareness extends DocumentBasedExample implements XPropertyChan XNamed xNameAcc = UnoRuntime.queryInterface( XNamed.class, xContainer ); if ( null == xNameAcc ) - sObjectName = new String( "" ); + sObjectName = ""; else sObjectName = xNameAcc.getName(); - System.out.println( new String( "enumerating the container named \"" ) + sObjectName + - new String( "\"\n" ) ); + System.out.println( "enumerating the container named \"" + sObjectName + + "\"\n" ); PrintComponentTree aPrinter = new PrintComponentTree(); aPrinter.handle( xContainer ); @@ -745,7 +745,7 @@ public class DataAwareness extends DocumentBasedExample implements XPropertyChan xSalesFormProps.setPropertyValue( "DataSourceName", m_database.getDocumentURL() ); xSalesFormProps.setPropertyValue( "CommandType", Integer.valueOf( CommandType.COMMAND ) ); - String sCommand = new String( "SELECT * FROM " ); + String sCommand = "SELECT * FROM "; sCommand += s_tableNameSales; sCommand += " WHERE " + s_tableNameSales + ".SNR = :salesmen"; xSalesFormProps.setPropertyValue( "Command", sCommand ); diff --git a/odk/examples/DevelopersGuide/Forms/DocumentViewHelper.java b/odk/examples/DevelopersGuide/Forms/DocumentViewHelper.java index 9cac2a864ca7..148eecd2f91e 100644 --- a/odk/examples/DevelopersGuide/Forms/DocumentViewHelper.java +++ b/odk/examples/DevelopersGuide/Forms/DocumentViewHelper.java @@ -99,7 +99,7 @@ class DocumentViewHelper XURLTransformer.class, m_orb.createInstance( "com.sun.star.util.URLTransformer" ) ); xTransformer.parseStrict( aURL ); - xReturn = xProvider.queryDispatch( aURL[0], new String( ), 0 ); + xReturn = xProvider.queryDispatch( aURL[0], "", 0 ); } return xReturn; } @@ -151,7 +151,7 @@ class DocumentViewHelper { // get a dispatcher for the toggle URL URL[] aToggleURL = new URL[] { new URL() }; - aToggleURL[0].Complete = new String( ".uno:SwitchControlDesignMode" ); + aToggleURL[0].Complete = ".uno:SwitchControlDesignMode"; XDispatch xDispatcher = getDispatcher( aToggleURL ); // dispatch the URL - this will result in toggling the mode diff --git a/odk/examples/DevelopersGuide/Forms/GridFieldValidator.java b/odk/examples/DevelopersGuide/Forms/GridFieldValidator.java index aa5a63d65e6e..2a3d92466923 100644 --- a/odk/examples/DevelopersGuide/Forms/GridFieldValidator.java +++ b/odk/examples/DevelopersGuide/Forms/GridFieldValidator.java @@ -95,9 +95,9 @@ class GridFieldValidator implements XUpdateListener sMessage += "\" is not allowed to contain empty strings."; SQLContext aError = new SQLContext( - new String( "Invalid Value Entered" ), + "Invalid Value Entered", null, - new String( "S1000" ), + "S1000", 0, new Any( new Type(), null ), sMessage diff --git a/odk/examples/DevelopersGuide/Forms/KeyGenerator.java b/odk/examples/DevelopersGuide/Forms/KeyGenerator.java index 2e00c842ce81..1b1157b91c1e 100644 --- a/odk/examples/DevelopersGuide/Forms/KeyGenerator.java +++ b/odk/examples/DevelopersGuide/Forms/KeyGenerator.java @@ -101,9 +101,9 @@ class UniqueColumnValue */ private String composeUniqueyKeyStatement( XPropertySet xForm, String sFieldName ) throws com.sun.star.uno.Exception { - String sStatement = new String( "SELECT MAX( " ); + String sStatement = "SELECT MAX( "; sStatement += sFieldName; - sStatement += new String( ") + 1 FROM " ); + sStatement += ") + 1 FROM "; // the table name is a property of the form sStatement += extractTableName( xForm ); diff --git a/odk/examples/DevelopersGuide/Forms/SalesFilter.java b/odk/examples/DevelopersGuide/Forms/SalesFilter.java index ee2aedf1c99d..5a1b46cfc9ec 100644 --- a/odk/examples/DevelopersGuide/Forms/SalesFilter.java +++ b/odk/examples/DevelopersGuide/Forms/SalesFilter.java @@ -214,7 +214,7 @@ class SalesFilter implements XActionListener, XPropertyChangeListener, XResetLis GregorianCalendar aCal = new GregorianCalendar(); aCal.setTime( (java.util.Date)aDate ); - sOdbcDate += new String( "{D '" ); + sOdbcDate += "{D '"; sOdbcDate += (Integer.valueOf( aCal.get( Calendar.YEAR ) ) ).toString(); sOdbcDate += "-"; diff --git a/odk/examples/DevelopersGuide/Forms/SingleControlValidation.java b/odk/examples/DevelopersGuide/Forms/SingleControlValidation.java index 115d4c381bff..a3fe49b7b58f 100644 --- a/odk/examples/DevelopersGuide/Forms/SingleControlValidation.java +++ b/odk/examples/DevelopersGuide/Forms/SingleControlValidation.java @@ -103,18 +103,18 @@ public class SingleControlValidation implements XFormComponentValidityListener controlPos += 4; XPropertySet xLabel = m_formLayer.createControlAndShape( "FixedText", columnPos, controlPos, 70, 4, null ); - xLabel.setPropertyValue( "Label", new String( "Status:" ) ); + xLabel.setPropertyValue( "Label", "Status:" ); controlPos += 4; m_statusField = m_formLayer.createControlAndShape( "FixedText", columnPos, controlPos, 70, 4, null ); - m_statusField.setPropertyValue( "Label", new String( "" ) ); + m_statusField.setPropertyValue( "Label", "" ); controlPos += 6; xLabel = m_formLayer.createControlAndShape( "FixedText", columnPos, controlPos, 70, 4, null ); - xLabel.setPropertyValue( "Label", new String( "Explanation for invalidity:" ) ); + xLabel.setPropertyValue( "Label", "Explanation for invalidity:" ); controlPos += 4; m_explanationField = m_formLayer.createControlAndShape( "FixedText", columnPos, controlPos, 70, 4, null ); - m_explanationField.setPropertyValue( "Label", new String( "" ) ); + m_explanationField.setPropertyValue( "Label", "" ); XValidatable xValidatable = UnoRuntime.queryInterface( XValidatable.class, m_inputField ); xValidatable.setValidator( m_validator ); diff --git a/odk/examples/DevelopersGuide/Forms/TableCellTextBinding.java b/odk/examples/DevelopersGuide/Forms/TableCellTextBinding.java index a7daf3550241..0d95df29b127 100644 --- a/odk/examples/DevelopersGuide/Forms/TableCellTextBinding.java +++ b/odk/examples/DevelopersGuide/Forms/TableCellTextBinding.java @@ -52,7 +52,7 @@ public class TableCellTextBinding { m_cellText = UnoRuntime.queryInterface( XTextRange.class, cell ); - m_newCellText = new String(); + m_newCellText = ""; m_listeners = new java.util.LinkedList(); start(); diff --git a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java index eaecc4c5e44e..bb5a8bd6e1f4 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java +++ b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java @@ -69,7 +69,7 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { com.sun.star.text.XTextDocument xDoc =UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xComponent); - String infoMsg = new String("All context menus of the created document frame contains now a 'Help' entry with the submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' in the shell to remove the context menu interceptor and finish the example!"); + String infoMsg = "All context menus of the created document frame contains now a 'Help' entry with the submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' in the shell to remove the context menu interceptor and finish the example!"; xDoc.getText().setString(infoMsg); // ensure that the document content is optimal visible @@ -176,9 +176,9 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { "com.sun.star.ui.ActionTriggerContainer" )); // intialize root menu entry - xRootMenuEntry.setPropertyValue( "Text", new String( "Help" )); - xRootMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5410" )); - xRootMenuEntry.setPropertyValue( "HelpURL", new String( "5410" )); + xRootMenuEntry.setPropertyValue( "Text", "Help"); + xRootMenuEntry.setPropertyValue( "CommandURL", "slot:5410"); + xRootMenuEntry.setPropertyValue( "HelpURL", "5410"); xRootMenuEntry.setPropertyValue( "SubContainer", xSubMenuContainer ); // create menu entries for the new sub menu @@ -188,9 +188,9 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); - xMenuEntry.setPropertyValue( "Text", new String( "Content" )); - xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5401" )); - xMenuEntry.setPropertyValue( "HelpURL", new String( "5401" )); + xMenuEntry.setPropertyValue( "Text", "Content" ); + xMenuEntry.setPropertyValue( "CommandURL", "slot:5401" ); + xMenuEntry.setPropertyValue( "HelpURL", "5401" ); // insert menu entry to sub menu xSubMenuContainer.insertByIndex( 0, xMenuEntry ); @@ -200,9 +200,9 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { com.sun.star.beans.XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); - xMenuEntry.setPropertyValue( "Text", new String( "Help Agent" )); - xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5962" )); - xMenuEntry.setPropertyValue( "HelpURL", new String( "5962" )); + xMenuEntry.setPropertyValue( "Text", "Help Agent" ); + xMenuEntry.setPropertyValue( "CommandURL", "slot:5962" ); + xMenuEntry.setPropertyValue( "HelpURL", "5962" ); // insert menu entry to sub menu xSubMenuContainer.insertByIndex( 1, xMenuEntry ); @@ -212,9 +212,9 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { com.sun.star.beans.XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); - xMenuEntry.setPropertyValue( "Text", new String( "Tips" )); - xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5404" )); - xMenuEntry.setPropertyValue( "HelpURL", new String( "5404" )); + xMenuEntry.setPropertyValue( "Text", "Tips" ); + xMenuEntry.setPropertyValue( "CommandURL", "slot:5404" ); + xMenuEntry.setPropertyValue( "HelpURL", "5404" ); // insert menu entry to sub menu xSubMenuContainer.insertByIndex( 2, xMenuEntry ); diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java index 77779e73be54..d21f8d36705b 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java +++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java @@ -60,8 +60,8 @@ public class Desk public static void main(String[] lArguments) { // Analyze command line parameters. - String sMode = new String("inplace"); - String sFile = new String("private:factory/swriter"); + String sMode = "inplace"; + String sFile = "private:factory/swriter"; for(int i=0; i