From fb39e719895689a290d3eb910bee994e5ffa2c25 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 25 Apr 2013 14:55:32 +0200 Subject: Java cleanup, call static methods statically Change-Id: Ibe0454d490153f723a58c3c619be7f8d443639c8 --- .../DevelopersGuide/Config/ConfigExamples.java | 14 +++---- .../DevelopersGuide/Forms/BooleanValidator.java | 8 ++-- .../Spreadsheet/SpreadsheetSample.java | 12 +++--- odk/examples/java/Inspector/InspectorPane.java | 47 +++++++++++----------- .../java/Inspector/SourceCodeGenerator.java | 24 +++++------ odk/examples/java/Inspector/UnoNode.java | 2 +- odk/examples/java/Spreadsheet/EuroAdaption.java | 19 ++++----- odk/examples/java/Text/StyleInitialization.java | 2 +- 8 files changed, 61 insertions(+), 67 deletions(-) (limited to 'odk/examples') diff --git a/odk/examples/DevelopersGuide/Config/ConfigExamples.java b/odk/examples/DevelopersGuide/Config/ConfigExamples.java index 0281dca8324a..ae3b0ceede52 100644 --- a/odk/examples/DevelopersGuide/Config/ConfigExamples.java +++ b/odk/examples/DevelopersGuide/Config/ConfigExamples.java @@ -465,9 +465,8 @@ public class ConfigExamples for(int i=0; i< aElementNames.length; ++i) { Object aChild = xChildAccess.getByName( aElementNames[i] ); - AnyConverter aAnyConv = new AnyConverter(); // is it a structural element (object) ... - if ( aAnyConv.isObject(aChild) && !aAnyConv.isArray(aChild) ) + if ( AnyConverter.isObject(aChild) && !AnyConverter.isArray(aChild) ) { // then get an interface XInterface xChildElement = UnoRuntime.queryInterface(XInterface.class, aChild); @@ -527,7 +526,7 @@ public class ConfigExamples new IConfigurationProcessor () { /// prints Path and Value of properties public void processValueElement( String sPath_, Object aValue_ ) { - if (new AnyConverter().isArray(aValue_)) + if (AnyConverter.isArray(aValue_)) { final Object [] aArray = (Object [])aValue_; @@ -751,11 +750,10 @@ public class ConfigExamples String aItemNames [] = aReplace.getElementNames(); for (int i=0; i < aItemNames.length; ++i) { Object aItem = aReplace.getByName( aItemNames [i] ); - AnyConverter aAnyConv = new AnyConverter(); // replace integers by a 'complement' value - if ( aAnyConv.isInt(aItem) ) + if ( AnyConverter.isInt(aItem) ) { - int nOld = aAnyConv.toInt(aItem); + int nOld = AnyConverter.toInt(aItem); int nNew = 9999 - nOld; System.out.println("Replacing integer value: " + aItemNames [i]); @@ -763,9 +761,9 @@ public class ConfigExamples } // and booleans by their negated value - else if ( aAnyConv.isBoolean(aItem) ) + else if ( AnyConverter.isBoolean(aItem) ) { - boolean bOld = aAnyConv.toBoolean(aItem); + boolean bOld = AnyConverter.toBoolean(aItem); boolean bNew = ! bOld; System.out.println("Replacing boolean value: " + aItemNames [i]); diff --git a/odk/examples/DevelopersGuide/Forms/BooleanValidator.java b/odk/examples/DevelopersGuide/Forms/BooleanValidator.java index 1237f068d2bd..3a6ba05d5037 100644 --- a/odk/examples/DevelopersGuide/Forms/BooleanValidator.java +++ b/odk/examples/DevelopersGuide/Forms/BooleanValidator.java @@ -1,3 +1,5 @@ +import com.sun.star.uno.AnyConverter; + /************************************************************************* * * The Contents of this file are made available subject to the terms of @@ -35,20 +37,18 @@ public class BooleanValidator extends ControlValidator { private boolean m_preventChecked; - private com.sun.star.uno.AnyConverter m_converter; /** Creates a new instance of BooleanValidator */ public BooleanValidator( boolean preventChecked ) { m_preventChecked = preventChecked; - m_converter = new com.sun.star.uno.AnyConverter(); } public String explainInvalid( Object Value ) { try { - if ( m_converter.isVoid( Value ) ) + if ( AnyConverter.isVoid( Value ) ) return "'indetermined' is not an allowed state"; boolean value = ((Boolean)Value).booleanValue(); if ( m_preventChecked && ( value == true ) ) @@ -65,7 +65,7 @@ public class BooleanValidator extends ControlValidator { try { - if ( m_converter.isVoid( Value ) ) + if ( AnyConverter.isVoid( Value ) ) return false; boolean value = ((Boolean)Value).booleanValue(); diff --git a/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java b/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java index b818e76a60b9..62726efafcbf 100644 --- a/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java +++ b/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java @@ -830,16 +830,15 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Document properties --- com.sun.star.beans.XPropertySet xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, getDocument() ); - AnyConverter aAnyConv = new AnyConverter(); String aText = "Value of property IsIterationEnabled: "; - aText += aAnyConv.toBoolean(xPropSet.getPropertyValue( "IsIterationEnabled" )); + aText += AnyConverter.toBoolean(xPropSet.getPropertyValue( "IsIterationEnabled" )); System.out.println( aText ); aText = "Value of property IterationCount: "; - aText += aAnyConv.toInt(xPropSet.getPropertyValue( "IterationCount" )); + aText += AnyConverter.toInt(xPropSet.getPropertyValue( "IterationCount" )); System.out.println( aText ); aText = "Value of property NullDate: "; com.sun.star.util.Date aDate = (com.sun.star.util.Date) - aAnyConv.toObject(com.sun.star.util.Date.class, xPropSet.getPropertyValue( "NullDate" )); + AnyConverter.toObject(com.sun.star.util.Date.class, xPropSet.getPropertyValue( "NullDate" )); aText += aDate.Year + "-" + aDate.Month + "-" + aDate.Day; System.out.println( aText ); @@ -1202,12 +1201,11 @@ public class SpreadsheetSample extends SpreadsheetDocHelper UnoRuntime.queryInterface( com.sun.star.container.XNameAccess.class, aRangesObj ); String[] aNames = xRanges.getElementNames(); - AnyConverter aAnyConv = new AnyConverter(); for ( int i=0; i 0){ for (int i=0; i< oUnoContainerElements.length; i++){ XUnoNode oChildNode = addUnoNode(_oParentNode, oUnoContainerElements[i], UnoNode.getNodeDescription(oUnoContainerElements[i])); @@ -371,7 +373,7 @@ import org.openoffice.XInstanceInspector; private void setNodeFoldable(XUnoNode _oUnoNode, Object _oUnoObject){ if (_oUnoObject != null){ - if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){ + if (!Introspector.isObjectPrimitive(_oUnoObject)){ _oUnoNode.setFoldable(true); } } @@ -406,7 +408,7 @@ import org.openoffice.XInstanceInspector; if (!_oUnoObject.getClass().getComponentType().isPrimitive()){ Object[] object = ( Object[] ) _oUnoObject; for ( int i = 0; i < object.length; i++ ) { - if (m_oIntrospector.isObjectPrimitive(object[i])){ + if (Introspector.isObjectPrimitive(object[i])){ XUnoNode oChildNode = addUnoNode(_oUnoNode, null, UnoNode.getNodeDescription(object[i])); } } @@ -431,14 +433,14 @@ import org.openoffice.XInstanceInspector; private void addPropertyValueSubNodes(XUnoFacetteNode _oUnoFacetteNode, Object _oUnoObject){ - if (m_oIntrospector.isUnoPropertyValueTypeObject(_oUnoObject)){ + if (Introspector.isUnoPropertyValueTypeObject(_oUnoObject)){ Object[] object = ( Object[] ) _oUnoObject; for ( int i = 0; i < object.length; i++ ) { String sObjectClassName = object[i].getClass().getName(); if (sObjectClassName.equals("com.sun.star.beans.PropertyValue")){ XUnoNode oChildNode = null; PropertyValue aPropertyValue = (PropertyValue) object[i]; - if (! m_oIntrospector.isObjectPrimitive(aPropertyValue.Value)){ + if (! Introspector.isObjectPrimitive(aPropertyValue.Value)){ oChildNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoObject, aPropertyValue, _oUnoObject); } else{ @@ -491,7 +493,7 @@ import org.openoffice.XInstanceInspector; } if (oUnoFacetteNode.isPropertyNode()){ String sNodeDescription = oUnoFacetteNode.getLabel(); - // TODO: it's very dangerous to distinguishe the different UnoFacetteNodes only by the nodedescription + // TODO: it's very dangerous to distinguish the different UnoFacetteNodes only by the node description if (sNodeDescription.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){ addPropertySetInfoNodesToTreeNode(oUnoFacetteNode, oUnoObject); } @@ -597,7 +599,7 @@ import org.openoffice.XInstanceInspector; if (oUnoObject instanceof String){ } else{ - if (!m_oIntrospector.isUnoTypeObject(oUnoObject)){ + if (!Introspector.isUnoTypeObject(oUnoObject)){ return oUnoObject; } } @@ -622,4 +624,3 @@ import org.openoffice.XInstanceInspector; m_xDialogProvider.showPopUpMenu(_invoker, x, y); } } - \ No newline at end of file diff --git a/odk/examples/java/Inspector/SourceCodeGenerator.java b/odk/examples/java/Inspector/SourceCodeGenerator.java index 5855ed4e2c65..0601da98b4a8 100644 --- a/odk/examples/java/Inspector/SourceCodeGenerator.java +++ b/odk/examples/java/Inspector/SourceCodeGenerator.java @@ -394,10 +394,10 @@ public class SourceCodeGenerator { bisDeclared = aVariables.containsKey(sVariableStemName); if (bisDeclared){ Object oUnoObject = _oUnoObjectDefinition.getUnoObject(); - if (m_oIntrospector.isObjectPrimitive(oUnoObject)){ + if (Introspector.isObjectPrimitive(oUnoObject)){ bisDeclared = false; } - else if (m_oIntrospector.isObjectSequence(oUnoObject)){ + else if (Introspector.isObjectSequence(oUnoObject)){ bisDeclared = false; } else{ @@ -513,7 +513,7 @@ public class SourceCodeGenerator { TypeClass aLocTypeClass = aTypeClass; boolean bIsArray = false; if (_oUnoObjectDefinition.getUnoObject() != null){ - bIsArray = m_oIntrospector.isObjectSequence(_oUnoObjectDefinition.getUnoObject()); + bIsArray = Introspector.isObjectSequence(_oUnoObjectDefinition.getUnoObject()); } else{ bIsArray = _oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.SEQUENCE_value; @@ -756,8 +756,8 @@ class UnoObjectDefinition{ if (aVariables.containsKey(sVariableName)){ String sUnoObjectIdentity = aVariables.get(sVariableName).getUnoObject().toString(); if (m_oUnoObject != null){ - if ((sUnoObjectIdentity.equals(m_oUnoObject.toString()) && (!m_oIntrospector.isPrimitive(this.getTypeClass())) && - (! m_oIntrospector.isObjectSequence(m_oUnoObject)))){ + if ((sUnoObjectIdentity.equals(m_oUnoObject.toString()) && (!Introspector.isPrimitive(this.getTypeClass())) && + (! Introspector.isObjectSequence(m_oUnoObject)))){ bleaveloop = true; } else{ @@ -871,11 +871,11 @@ class UnoObjectDefinition{ String sClassName = _sClassName; String sHeaderStatement = ""; if (_oUnoObject != null){ - if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){ - if (m_oIntrospector.isObjectSequence(_oUnoObject)){ + if (!Introspector.isObjectPrimitive(_oUnoObject)){ + if (Introspector.isObjectSequence(_oUnoObject)){ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName); if (xTypeDescription != null){ - if (!m_oIntrospector.isPrimitive(xTypeDescription.getTypeClass())){ + if (!Introspector.isPrimitive(xTypeDescription.getTypeClass())){ sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true); } // primitive Types are not supposed to turn up in the import section... @@ -1428,11 +1428,11 @@ class UnoObjectDefinition{ String sClassName = _sClassName; String sHeaderStatement = ""; if (_oUnoObject != null){ - if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){ - if (m_oIntrospector.isObjectSequence(_oUnoObject)){ + if (!Introspector.isObjectPrimitive(_oUnoObject)){ + if (Introspector.isObjectSequence(_oUnoObject)){ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName); if (xTypeDescription != null){ - if (!m_oIntrospector.isPrimitive(xTypeDescription.getTypeClass())){ + if (!Introspector.isPrimitive(xTypeDescription.getTypeClass())){ sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true); } // primitive Types are not supposed to turn up in the import section... @@ -1682,7 +1682,7 @@ class UnoObjectDefinition{ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize){ - boolean bIsPrimitive = m_oIntrospector.isPrimitive(_aTypeClass); + boolean bIsPrimitive = Introspector.isPrimitive(_aTypeClass); // uno::Reference< frame::XDispatch > m_xDispatch String sReturn = ""; diff --git a/odk/examples/java/Inspector/UnoNode.java b/odk/examples/java/Inspector/UnoNode.java index 92fef1885aec..dac2e82ed58d 100644 --- a/odk/examples/java/Inspector/UnoNode.java +++ b/odk/examples/java/Inspector/UnoNode.java @@ -419,7 +419,7 @@ public class UnoNode{ return xServiceInfo.getImplementationName(); } String sClassName = _oUnoObject.getClass().getName(); - if (Introspector.getIntrospector().isObjectPrimitive(_oUnoObject)){ //super.isO{sObjectClassName.equals("java.lang.String"))issClassName.equals("java.lang.String")) + if (Introspector.isObjectPrimitive(_oUnoObject)){ //super.isO{sObjectClassName.equals("java.lang.String"))issClassName.equals("java.lang.String")) return _oUnoObject.toString(); } else{ diff --git a/odk/examples/java/Spreadsheet/EuroAdaption.java b/odk/examples/java/Spreadsheet/EuroAdaption.java index 2f4f1d4f95e6..51b419df5d92 100644 --- a/odk/examples/java/Spreadsheet/EuroAdaption.java +++ b/odk/examples/java/Spreadsheet/EuroAdaption.java @@ -165,9 +165,6 @@ public class EuroAdaption { XEnumeration xRanges = xEnumerationAccess.createEnumeration(); - // create an AnyConverter for later use - AnyConverter aAnyConv = new AnyConverter(); - while( xRanges.hasMoreElements() ) { // the enumeration returns a cellrange XCellRange xCellRange = UnoRuntime.queryInterface( @@ -180,28 +177,28 @@ public class EuroAdaption { // getPropertyValue returns an Object, you have to cast it to // type that you need Object oNumberObject = xCellProp.getPropertyValue( "NumberFormat" ); - int iNumberFormat = aAnyConv.toInt(oNumberObject); + int iNumberFormat = AnyConverter.toInt(oNumberObject); // get the properties from the cellrange numberformat XPropertySet xFormat = xNumberFormats.getByKey(iNumberFormat ); - short fType = aAnyConv.toShort(xFormat.getPropertyValue("Type")); - String sCurrencySymbol = aAnyConv.toString( + short fType = AnyConverter.toShort(xFormat.getPropertyValue("Type")); + String sCurrencySymbol = AnyConverter.toString( xFormat.getPropertyValue("CurrencySymbol")); // change the numberformat only on cellranges with a // currency numberformat if( ( (fType & com.sun.star.util.NumberFormat.CURRENCY) > 0) && ( sCurrencySymbol.compareTo( sOldSymbol ) == 0 ) ) { - boolean bThousandSep = aAnyConv.toBoolean( + boolean bThousandSep = AnyConverter.toBoolean( xFormat.getPropertyValue("ThousandsSeparator")); - boolean bNegativeRed = aAnyConv.toBoolean( + boolean bNegativeRed = AnyConverter.toBoolean( xFormat.getPropertyValue("NegativeRed")); - short fDecimals = aAnyConv.toShort( + short fDecimals = AnyConverter.toShort( xFormat.getPropertyValue("Decimals")); - short fLeadingZeros = aAnyConv.toShort( + short fLeadingZeros = AnyConverter.toShort( xFormat.getPropertyValue("LeadingZeros")); - Locale oLocale = (Locale) aAnyConv.toObject( + Locale oLocale = (Locale) AnyConverter.toObject( new com.sun.star.uno.Type(Locale.class), xFormat.getPropertyValue("Locale")); diff --git a/odk/examples/java/Text/StyleInitialization.java b/odk/examples/java/Text/StyleInitialization.java index e092a3634fb9..21e0f9bf2bc3 100644 --- a/odk/examples/java/Text/StyleInitialization.java +++ b/odk/examples/java/Text/StyleInitialization.java @@ -202,7 +202,7 @@ public class StyleInitialization { com.sun.star.beans.XPropertySet.class, xStyle ); AnyConverter aAnyConv = new AnyConverter(); - String sFontname = aAnyConv.toString(xPropertySet.getPropertyValue("CharFontName")); + String sFontname = AnyConverter.toString(xPropertySet.getPropertyValue("CharFontName")); sFontname = sFontname.toLowerCase(); // if the style use the font 'Albany', apply it to the current paragraph -- cgit