diff options
author | Noel Grandin <noel@peralex.com> | 2012-09-07 13:41:02 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-09-10 23:43:39 +0200 |
commit | 4c9e62c6e3513a57e86dfb7ea06a74ce2943aaaa (patch) | |
tree | 1008fb1ceb97da428ab451b0d1b83b1bb3b5e089 /odk/examples/java | |
parent | 6bf09ecf1d97455af4a07ae3564886ee69e0a33b (diff) |
Java cleanup, convert ArrayList and Vector to use generics
Change-Id: Ic668b46872ee0bfd259ca335aed9d68fb545c3a4
Diffstat (limited to 'odk/examples/java')
-rw-r--r-- | odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java | 36 | ||||
-rw-r--r-- | odk/examples/java/ToDo/ToDo.java | 73 |
2 files changed, 48 insertions, 61 deletions
diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java index 4b293ce8ab30..44ee37c20982 100644 --- a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java +++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java @@ -59,7 +59,7 @@ public final class OwnEmbeddedObject extends WeakBase protected EditorFrame m_aEditorFrame; - protected Vector m_aListeners; + protected Vector<Object> m_aListeners; com.sun.star.embed.VerbDescriptor[] m_pOwnVerbs; @@ -68,7 +68,7 @@ public final class OwnEmbeddedObject extends WeakBase Dimension m_aObjSize; // ------------------------------------------------------------- - protected Vector GetListeners() + protected Vector<Object> GetListeners() { if ( m_aListeners == null ) m_aListeners = new Vector<Object>( 10, 10 ); @@ -133,12 +133,12 @@ public final class OwnEmbeddedObject extends WeakBase { // save the text XStream xStream = xStorage.openStreamElement( "content.txt", com.sun.star.embed.ElementModes.READWRITE ); - XComponent xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream ); + XComponent xStreamComp = UnoRuntime.queryInterface( XComponent.class, xStream ); if ( xStreamComp == null ) throw new com.sun.star.uno.RuntimeException(); XOutputStream xOutStream = xStream.getOutputStream(); - XTruncate xTruncate = ( XTruncate ) UnoRuntime.queryInterface( XTruncate.class, xOutStream ); + XTruncate xTruncate = UnoRuntime.queryInterface( XTruncate.class, xOutStream ); if ( xTruncate == null ) throw new com.sun.star.io.IOException(); @@ -147,12 +147,12 @@ public final class OwnEmbeddedObject extends WeakBase // save the size xStream = xStorage.openStreamElement( "properties.txt", com.sun.star.embed.ElementModes.READWRITE ); - xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream ); + xStreamComp = UnoRuntime.queryInterface( XComponent.class, xStream ); if ( xStreamComp == null ) throw new com.sun.star.uno.RuntimeException(); xOutStream = xStream.getOutputStream(); - xTruncate = ( XTruncate ) UnoRuntime.queryInterface( XTruncate.class, xOutStream ); + xTruncate = UnoRuntime.queryInterface( XTruncate.class, xOutStream ); if ( xTruncate == null ) throw new com.sun.star.io.IOException(); @@ -161,12 +161,12 @@ public final class OwnEmbeddedObject extends WeakBase xOutStream.writeBytes( aProps.getBytes() ); // set the media type - XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xStorage ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xStorage ); if ( xPropSet == null ) throw new com.sun.star.uno.RuntimeException(); xPropSet.setPropertyValue( "MediaType", "application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" ); - XTransactedObject xTransact = ( XTransactedObject ) UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); + XTransactedObject xTransact = UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); if ( xTransact != null ) xTransact.commit(); @@ -196,8 +196,7 @@ public final class OwnEmbeddedObject extends WeakBase { try { - com.sun.star.document.XEventListener xListener = ( com.sun.star.document.XEventListener ) - UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) ); + com.sun.star.document.XEventListener xListener = UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) ); if ( xListener != null ) xListener.notifyEvent( aEventObject ); @@ -220,8 +219,7 @@ public final class OwnEmbeddedObject extends WeakBase { try { - com.sun.star.embed.XStateChangeListener xListener = ( com.sun.star.embed.XStateChangeListener ) - UnoRuntime.queryInterface( com.sun.star.embed.XStateChangeListener.class, m_aListeners.get( nInd ) ); + com.sun.star.embed.XStateChangeListener xListener = UnoRuntime.queryInterface( com.sun.star.embed.XStateChangeListener.class, m_aListeners.get( nInd ) ); if ( xListener != null ) { @@ -248,7 +246,7 @@ public final class OwnEmbeddedObject extends WeakBase try { XStream xStream = xStorage.openStreamElement( aStreamName, com.sun.star.embed.ElementModes.READWRITE ); - XComponent xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream ); + XComponent xStreamComp = UnoRuntime.queryInterface( XComponent.class, xStream ); if ( xStreamComp == null ) throw new com.sun.star.uno.RuntimeException(); @@ -415,7 +413,7 @@ public final class OwnEmbeddedObject extends WeakBase SwitchOwnPersistence( xStorage, aEntryName ); if ( bElExists ) { - XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, m_xOwnStorage ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, m_xOwnStorage ); if ( xPropSet == null ) throw new com.sun.star.uno.RuntimeException(); @@ -993,19 +991,19 @@ public final class OwnEmbeddedObject extends WeakBase { XMultiComponentFactory xFactory = m_xContext.getServiceManager(); Object obj = xFactory.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", m_xContext ); - XMultiServiceFactory xConfProvider = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, obj ); + XMultiServiceFactory xConfProvider = UnoRuntime.queryInterface( XMultiServiceFactory.class, obj ); if ( xConfProvider == null ) throw new com.sun.star.uno.RuntimeException(); Object[] aArgs = new Object[1]; aArgs[0] = "/org.openoffice.Office.Embedding/Objects"; Object oSettings = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs ); - XNameAccess xObjConfNA = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, oSettings ); + XNameAccess xObjConfNA = UnoRuntime.queryInterface( XNameAccess.class, oSettings ); if ( xObjConfNA == null ) throw new com.sun.star.uno.RuntimeException(); Object oEmbObj = xObjConfNA.getByName( "69474366-FD6F-4806-8374-8EDD1B6E771D" ); - XNameAccess xEmbObjNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, oEmbObj ); + XNameAccess xEmbObjNA = UnoRuntime.queryInterface( XNameAccess.class, oEmbObj ); if ( xEmbObjNA == null ) throw new com.sun.star.uno.RuntimeException(); @@ -1015,7 +1013,7 @@ public final class OwnEmbeddedObject extends WeakBase com.sun.star.embed.VerbDescriptor[] pVerbs = new com.sun.star.embed.VerbDescriptor[pVerbShortcuts.length]; aArgs[0] = "/org.openoffice.Office.Embedding/Verbs"; Object oVerbs = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs ); - XNameAccess xVerbsConfNA = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, oVerbs ); + XNameAccess xVerbsConfNA = UnoRuntime.queryInterface( XNameAccess.class, oVerbs ); if ( xVerbsConfNA == null ) throw new com.sun.star.uno.RuntimeException(); @@ -1023,7 +1021,7 @@ public final class OwnEmbeddedObject extends WeakBase { try { - XNameAccess xVerbNA = (XNameAccess) UnoRuntime.queryInterface( + XNameAccess xVerbNA = UnoRuntime.queryInterface( XNameAccess.class, xVerbsConfNA.getByName( pVerbShortcuts[nInd] ) ); if ( xVerbNA != null ) diff --git a/odk/examples/java/ToDo/ToDo.java b/odk/examples/java/ToDo/ToDo.java index cea35235d83d..98ece6192583 100644 --- a/odk/examples/java/ToDo/ToDo.java +++ b/odk/examples/java/ToDo/ToDo.java @@ -171,21 +171,19 @@ public class ToDo { try { // Querying for the interface XSpreadsheetDocument XSpreadsheetDocument xspreadsheetdocument = - ( XSpreadsheetDocument ) UnoRuntime.queryInterface( - XSpreadsheetDocument.class, aInstance ); + UnoRuntime.queryInterface( + XSpreadsheetDocument.class, aInstance ); // Querying for the interface XIndexAccess - XIndexAccess xindexaccess = ( XIndexAccess ) - UnoRuntime.queryInterface( XIndexAccess.class, - xspreadsheetdocument.getSheets() ); + XIndexAccess xindexaccess = UnoRuntime.queryInterface( XIndexAccess.class, + xspreadsheetdocument.getSheets() ); // Getting the first XSpreadsheet - XSpreadsheet xspreadsheet = (XSpreadsheet)UnoRuntime.queryInterface( + XSpreadsheet xspreadsheet = UnoRuntime.queryInterface( XSpreadsheet.class, xindexaccess.getByIndex( 0 )); // Querying for the interface XCellRange on the XSpeadsheet - XCellRange xcellrange = ( XCellRange ) - UnoRuntime.queryInterface( XCellRange.class, xspreadsheet ); + XCellRange xcellrange = UnoRuntime.queryInterface( XCellRange.class, xspreadsheet ); /* Getting the gregorian calendar with the date on which to start the calculation */ @@ -206,12 +204,11 @@ public class ToDo { // Querying for the interface XFunctionAccess on service // FunctionAccess - XFunctionAccess xfunctionaccess = (XFunctionAccess) - UnoRuntime.queryInterface(XFunctionAccess.class, - objectFunctionAccess ); + XFunctionAccess xfunctionaccess = UnoRuntime.queryInterface(XFunctionAccess.class, + objectFunctionAccess ); // Creating vector for holidays - Vector vectorHolidays = new Vector(); + Vector<Object> vectorHolidays = new Vector<Object>(); // Get the Official Holidays this.getOfficialHolidays( vectorHolidays, xcellrange, @@ -268,11 +265,10 @@ public class ToDo { { // Querying for the interface XPropertySet for the cell // providing the due date - XPropertySet xpropertyset = ( XPropertySet ) - UnoRuntime.queryInterface(XPropertySet.class, + XPropertySet xpropertyset = UnoRuntime.queryInterface(XPropertySet.class, xcellrange.getCellByPosition( - this.INT_COLUMN_DUEDATE, - intRow )); + this.INT_COLUMN_DUEDATE, + intRow )); // Changing the background color of the cell to white xpropertyset.setPropertyValue( "CellBackColor", @@ -283,15 +279,13 @@ public class ToDo { this.INT_COLUMN_FEATURE, intRow ); // Querying for the interface XSimpleText - XSimpleText xsimpletext = ( XSimpleText ) - UnoRuntime.queryInterface( XSimpleText.class, xcell ); + XSimpleText xsimpletext = UnoRuntime.queryInterface( XSimpleText.class, xcell ); // Getting the text cursor XTextCursor xtextcursor = xsimpletext.createTextCursor(); // Querying for the interface XTextRange - XTextRange xtextrange = ( XTextRange ) - UnoRuntime.queryInterface( XTextRange.class, xtextcursor ); + XTextRange xtextrange = UnoRuntime.queryInterface( XTextRange.class, xtextcursor ); // Getting the bug ID from the cell String sBugID = xtextrange.getString(); @@ -302,8 +296,8 @@ public class ToDo { // Querying for the interface XMultiServiceFactory XMultiServiceFactory xMSFTextField = - (XMultiServiceFactory)UnoRuntime.queryInterface( - XMultiServiceFactory.class, aInstance ); + UnoRuntime.queryInterface( + XMultiServiceFactory.class, aInstance ); // Creating an instance of the text field URL Object objectTextField = @@ -311,14 +305,12 @@ public class ToDo { "com.sun.star.text.TextField.URL" ); // Querying for the interface XTextField - XTextField xtextfield = ( XTextField ) - UnoRuntime.queryInterface( XTextField.class, - objectTextField ); + XTextField xtextfield = UnoRuntime.queryInterface( XTextField.class, + objectTextField ); // Querying for the interface XPropertySet - XPropertySet xpropertysetTextField = ( XPropertySet ) - UnoRuntime.queryInterface( XPropertySet.class, - xtextfield ); + XPropertySet xpropertysetTextField = UnoRuntime.queryInterface( XPropertySet.class, + xtextfield ); // Setting the URL xpropertysetTextField.setPropertyValue( "URL", @@ -329,7 +321,7 @@ public class ToDo { sBugID ); // Querying for the interface XText - XText xtext = ( XText )UnoRuntime.queryInterface( + XText xtext = UnoRuntime.queryInterface( XText.class, xcell ); // Delete cell content @@ -504,12 +496,11 @@ public class ToDo { gregCalPreviousDueDate ) ) ) { // Querying for the interface XPropertySet for // the cell providing the due date - XPropertySet xpropertyset = ( XPropertySet ) - UnoRuntime.queryInterface( + XPropertySet xpropertyset = UnoRuntime.queryInterface( XPropertySet.class, xcellrange.getCellByPosition( - this.INT_COLUMN_DUEDATE, - intRow ) ); + this.INT_COLUMN_DUEDATE, + intRow ) ); // Changing the background color of the cell // to red @@ -519,8 +510,8 @@ public class ToDo { // Querying for the interface XColumnRowRange // on the XCellRange XColumnRowRange xcolumnrowrange = - ( XColumnRowRange)UnoRuntime.queryInterface( - XColumnRowRange.class, xcellrange ); + UnoRuntime.queryInterface( + XColumnRowRange.class, xcellrange ); // Inserting one row to the table XTableRows xTableRows = xcolumnrowrange.getRows(); @@ -529,7 +520,7 @@ public class ToDo { // Querying for the interface // XCellRangeMovement on XCellRange XCellRangeMovement xcellrangemovement = - (XCellRangeMovement)UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XCellRangeMovement.class, xcellrange ); // Creating the cell address of the destination @@ -648,8 +639,7 @@ public class ToDo { XCell xcellStartDate = xcellrange.getCellByPosition(intColumn, intRow); // Querying for the interface XTextRange on the XCell - xtextrangeStartDate = (XTextRange) - UnoRuntime.queryInterface(XTextRange.class, xcellStartDate); + xtextrangeStartDate = UnoRuntime.queryInterface(XTextRange.class, xcellStartDate); } catch( Exception exception ) { this.showExceptionMessage( exception ); @@ -672,8 +662,7 @@ public class ToDo { XCell xcellStartDate = xcellrange.getCellByPosition(intColumn, intRow); // Querying for the interface XTextRange on the XCell - XTextRange xtextrange = (XTextRange) - UnoRuntime.queryInterface(XTextRange.class, xcellStartDate); + XTextRange xtextrange = UnoRuntime.queryInterface(XTextRange.class, xcellStartDate); // Setting the new start date xtextrange.setString( sDate ); } @@ -717,7 +706,7 @@ public class ToDo { * @param intYear Year to calculate the official holidays. */ public void getOfficialHolidays( - Vector vectorHolidays, + Vector<Object> vectorHolidays, XCellRange xcellrange, XFunctionAccess xfunctionaccess, int intYear ) { @@ -852,7 +841,7 @@ public class ToDo { * @param xcellrange Providing the cells. * @param xfunctionaccess Provides the access to functions of the Calc. */ - public void getPrivateHolidays( Vector vectorHolidays, + public void getPrivateHolidays( Vector<Object> vectorHolidays, XCellRange xcellrange, XFunctionAccess xfunctionaccess ) { try { |