forms/qa/integration/forms/BooleanValidator.java | 8 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java | 556 +++++----- nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java | 10 odk/examples/DevelopersGuide/Config/ConfigExamples.java | 14 odk/examples/DevelopersGuide/Forms/BooleanValidator.java | 8 odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java | 12 odk/examples/java/Inspector/InspectorPane.java | 47 odk/examples/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 11 files changed, 347 insertions(+), 355 deletions(-)
New commits: commit fb39e719895689a290d3eb910bee994e5ffa2c25 Author: Noel Grandin <n...@peralex.com> Date: Thu Apr 25 14:55:32 2013 +0200 Java cleanup, call static methods statically Change-Id: Ibe0454d490153f723a58c3c619be7f8d443639c8 diff --git a/forms/qa/integration/forms/BooleanValidator.java b/forms/qa/integration/forms/BooleanValidator.java index d69ee58..dfd3fca 100644 --- a/forms/qa/integration/forms/BooleanValidator.java +++ b/forms/qa/integration/forms/BooleanValidator.java @@ -24,23 +24,23 @@ package integration.forms; +import com.sun.star.uno.AnyConverter; + public class BooleanValidator extends integration.forms.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 ) ) @@ -57,7 +57,7 @@ public class BooleanValidator extends integration.forms.ControlValidator { try { - if ( m_converter.isVoid( Value ) ) + if ( AnyConverter.isVoid( Value ) ) return false; boolean value = ((Boolean)Value).booleanValue(); diff --git a/odk/examples/DevelopersGuide/Config/ConfigExamples.java b/odk/examples/DevelopersGuide/Config/ConfigExamples.java index 0281dca..ae3b0ce 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 1237f06..3a6ba05 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 b818e76..62726ef 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<aNames.length; i++ ) { Object aRangeObj = xRanges.getByName( aNames[i] ); com.sun.star.beans.XPropertySet xRangeProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aRangeObj ); - boolean bUser = aAnyConv.toBoolean(xRangeProp.getPropertyValue( "IsUserDefined" )); + boolean bUser = AnyConverter.toBoolean(xRangeProp.getPropertyValue( "IsUserDefined" )); if ( !bUser ) { // this is the temporary database range - get the cell range and format it @@ -1340,7 +1338,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper com.sun.star.beans.XPropertySet.class, aSettings ); AnyConverter aAnyConv = new AnyConverter(); String[] aEntries = (String[]) - aAnyConv.toObject(String[].class, + AnyConverter.toObject(String[].class, xPropSet.getPropertyValue( "UserLists" )); System.out.println("User defined sort lists:"); for ( int i=0; i<aEntries.length; i++ ) diff --git a/odk/examples/java/Inspector/InspectorPane.java b/odk/examples/java/Inspector/InspectorPane.java index 11640ce..79cddd7 100644 --- a/odk/examples/java/Inspector/InspectorPane.java +++ b/odk/examples/java/Inspector/InspectorPane.java @@ -33,19 +33,21 @@ *************************************************************************/ +import org.openoffice.XInstanceInspector; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XIntrospectionAccess; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.XServiceInfo; import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.reflection.XIdlMethod; import com.sun.star.uno.Any; -import com.sun.star.lang.XServiceInfo; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Type; import com.sun.star.uno.TypeClass; import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.Type; import com.sun.star.uno.XComponentContext; -import com.sun.star.beans.XIntrospectionAccess; -import com.sun.star.beans.Property; -import com.sun.star.beans.PropertyValue; -import com.sun.star.beans.XPropertySet; -import com.sun.star.reflection.XIdlMethod; -import org.openoffice.XInstanceInspector; public class InspectorPane extends WeakBase implements XInstanceInspector{ //, XServiceInfo private XIdlMethod[] xIdlMethods; @@ -111,7 +113,7 @@ import org.openoffice.XInstanceInspector; private Type[] getTypes(Object _oUnoObject){ Type[] aTypes = null; - if (m_oIntrospector.isArray(_oUnoObject)){ + if (AnyConverter.isArray(_oUnoObject)){ aTypes = (Type[])_oUnoObject; } else{ @@ -144,17 +146,17 @@ import org.openoffice.XInstanceInspector; } else{ Any aReturnObject = Any.complete(oUnoReturnObject); - String sShortClassName = m_oIntrospector.getShortClassName(aReturnObject.getType().getTypeName()); + String sShortClassName = Introspector.getShortClassName(aReturnObject.getType().getTypeName()); sNodeDescription += m_oSourceCodeGenerator.getVariableNameforUnoObject(sShortClassName); } - if (m_oIntrospector.isArray(oUnoReturnObject)){ - if (m_oIntrospector.isUnoTypeObject(oUnoReturnObject)){ + if (Introspector.isArray(oUnoReturnObject)){ + if (Introspector.isUnoTypeObject(oUnoReturnObject)){ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoMethodNode.getUnoObject()); } - else if(m_oIntrospector.isUnoPropertyTypeObject(oUnoReturnObject)){ + else if(Introspector.isUnoPropertyTypeObject(oUnoReturnObject)){ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYINFODESCRIPTION, oUnoReturnObject); } - else if(m_oIntrospector.isUnoPropertyValueTypeObject(oUnoReturnObject)){ + else if(Introspector.isUnoPropertyValueTypeObject(oUnoReturnObject)){ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION, oUnoReturnObject); } } @@ -245,7 +247,7 @@ import org.openoffice.XInstanceInspector; public void addMethodsToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, XIdlMethod[] _xIdlMethods){ - if (this.m_oIntrospector.isValid(_xIdlMethods)){ + if (Introspector.isValid(_xIdlMethods)){ for ( int n = 0; n < _xIdlMethods.length; n++ ) { XIdlMethod xIdlMethod = _xIdlMethods[n]; if (!xIdlMethod.getDeclaringClass().getName().equals("com.sun.star.uno.XInterface")){ @@ -347,7 +349,7 @@ import org.openoffice.XInstanceInspector; public void addContainerElementsToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject){ Object[] oUnoContainerElements = m_oIntrospector.getUnoObjectsOfContainer(_oUnoParentObject); - if (m_oIntrospector.isValid(oUnoContainerElements)){ + if (Introspector.isValid(oUnoContainerElements)){ if (oUnoContainerElements.length > 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 5855ed4..0601da9 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 92fef18..dac2e82 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 2f4f1d4..51b419d 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 e092a36..21e0f9b 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 commit d2d3e5d2a86cf91a9b38fabe76dc919c77c62852 Author: Noel Grandin <n...@peralex.com> Date: Thu Apr 25 14:48:24 2013 +0200 Java cleanup, use generics Change-Id: I164e0f8386558641497258cc0a1d731e81a51c15 diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java index 3dc20c6..14449e2 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java @@ -1,277 +1,279 @@ -/** - * Description: Global package for file operations. - * - * @ Author Create/Modi Note - * Xiaofeng Xie Jun 15, 2002 - * - * @version 1.0 - * @Since MAOS1.0 - */ - - -package net.adaptivebox.global; - -import java.io.*; -import java.util.*; - -public class GlobalFile { - -// used by the createTempDir to give an index of temp number. - private static int counter = -1; - -/** - * Create a temp directory in the given directory. - * @param prefix the prefix for the directory. - * @param directory the directory that the temp dirctory placed. - * @return If a temp directory is created, return a File Object, else - * return null. - */ - public static File createTempDir(String prefix, String directory) throws IOException { - File f = null; - String tempDir; - boolean isCreated = false; - do { - if (counter == -1) { - counter = new Random().nextInt() & 0xffff; - } - counter++; - if (prefix == null) throw new NullPointerException(); - if (prefix.length() < 3) - throw new IllegalArgumentException("Prefix string too short"); - if (directory == null) { - tempDir = prefix+counter; - } else { - tempDir = getFileLocation(directory,prefix+counter); - } - f = new File(tempDir); - isCreated = f.mkdir(); - } while (!isCreated); - return f; - } - -/** - * Add the given text string to the end of a given file. - * @param inStr The string to be added. - * @param fileStr the name of the file to be added. - */ - public static void addStringToFile(String inStr, String fileStr) throws Exception { - - RandomAccessFile raFile = new RandomAccessFile(fileStr,"rw"); - raFile.seek(raFile.length()); - raFile.writeBytes(inStr); - raFile.close(); - - -// String oldFileStr = getStringFromFile(fileStr); -// String newFileStr = inStr; -// if (oldFileStr != null) { -// newFileStr = oldFileStr+inStr; -// } -// saveStringToFile(newFileStr,fileStr); - - } - - public static Object loadObjectFromFile(String fileName) throws Exception { - FileInputStream fis = new FileInputStream(fileName); - ObjectInputStream ois = new ObjectInputStream(fis); - Object obj = ois.readObject(); - ois.close(); - return obj; - } - - public static void saveObjectToFile(String fileName, Object obj) throws Exception { - FileOutputStream ostream = new FileOutputStream(fileName); - ObjectOutputStream p = new ObjectOutputStream(ostream); - p.writeObject(obj); - p.flush(); - ostream.close(); - } - -/** - * Save the given text string to a given file. - * @param inStr The string to be saved. - * @param fileStr the name of the file to be saved. - */ - public static void saveStringToFile(String inStr, String fileStr) throws Exception{ - new File(new File(fileStr).getParent()).mkdirs(); - FileOutputStream pspOutputStream = new FileOutputStream(new File(fileStr)); - pspOutputStream.write(inStr.getBytes()); - pspOutputStream.close(); - } - -/** - * Load text string from a given file. - * @param fileStr the name of the file to be loaded. - * @return A text string that is the content of the file. if the given file is - * not exist, then return null. - */ - public static String getStringFromFile(String fileStr) throws Exception { - String getStr = null; - FileInputStream pspInputStream = new FileInputStream(fileStr); - byte[] pspFileBuffer = new byte[pspInputStream.available()]; - pspInputStream.read(pspFileBuffer); - pspInputStream.close(); - getStr = new String(pspFileBuffer); - return(getStr); - } - -/** - * Load curve data from a specified file. - * @param fileStr the name of the file to be loaded. - * @return A Vector that include the curve data. - */ - public static Vector getCurveDataFromFile(String fileName) { - File file = new File(fileName); - if(!file.exists()){ - //showMessage(); - return null; - } - //open data file - FileInputStream inStream = null; - BufferedReader inReader = null; - try{ - inStream = new FileInputStream(file); - inReader = new BufferedReader(new InputStreamReader(inStream)); - }catch(Exception e){ - //showMessage(); - return null;//Data file open error. - } - Vector xaxes = new Vector(1,1); - Vector yaxes = new Vector(1,1); - try{ - StringTokenizer st; - String s; - boolean start = false; - while(inReader.ready()!=false){ - st = new StringTokenizer(inReader.readLine()); - over:{ - while(!st.hasMoreTokens()){//Justify blank lines. - if(inReader.ready()!=false){ - st = new StringTokenizer(inReader.readLine()); - }else - break over; - } - s = st.nextToken(); - if((!start)&&(!s.startsWith("@"))) - break over; - if(!start){ - start = true; - break over; - } - if(s.startsWith("#")||s.startsWith("$")||s.startsWith("/")) break over;//Justify comment line. - Double xaxis = null; - Double yaxis = null; - try{ - xaxis = Double.valueOf(s); - xaxes.addElement(xaxis); - }catch(Exception e){ - //showMessage(); - inReader.close(); - inStream.close(); - return null;//Data file data format error. - } - s = st.nextToken(); - try{ - yaxis = Double.valueOf(s); - yaxes.addElement(yaxis); - }catch(Exception e){ - //showMessage(); - inReader.close(); - inStream.close(); - return null;//Data file data format error. - } - } - } - }catch(Exception e){ - //showMessage(); - return null;//Uncertain data file error. - } - Vector curveData = new Vector(); - curveData.addElement(xaxes); - curveData.addElement(yaxes); - return(curveData); - } - -/** - * Get a full path of a given file name and a directory name. - * @param fileName the name of the file. - * @param dir the name of directory. - * @return The full path. - */ - public static String getFileLocation(String dir, String fileName) { - String realDir = dir; - while (realDir.length()>0 && (realDir.endsWith("/")||realDir.endsWith("\\"))) { - realDir = dir.substring(0, dir.length()-1); - } - return realDir+BasicTag.FILE_SEP_TAG+fileName; - } - - public static String getFileName(String nameBody, String suffix) { - if (suffix==null || suffix.trim().length()==0) { - return nameBody; - } - String fileName = nameBody; - if(nameBody.endsWith(".")) { - return fileName+suffix; - } else { - return nameBody+"."+suffix; - } - } - - public static String getFileLocation(String dir, String fileNameBody, String fileNameSuffix) { - String filename = getFileName(fileNameBody, fileNameSuffix); - return getFileLocation(dir, filename); - } - - public static void clear(String fileStr) throws Exception { - File file = new File(fileStr); - if(file.isFile()) { - file.delete(); - return; - } - String[] fileNames = file.list(); - if (fileNames==null) { - return; - } - for (int i=0; i<fileNames.length; i++) { - String newFileName = GlobalFile.getFileLocation(fileStr,fileNames[i]); - clear(newFileName); - } - file.delete(); - } - - public static String getFilePrefix(String fileStr) { - int index = fileStr.lastIndexOf(BasicTag.DOT_TAG); - if(index==-1) index = fileStr.length(); - return fileStr.substring(0, index); - } - - public static String getFileSuffix(String fileStr) { - String[] subNames = GlobalString.tokenize(fileStr, BasicTag.DOT_TAG); - int subNameLen = subNames.length; - if(subNameLen==1) return ""; - else return subNames[subNameLen-1]; - } - - public static String createTempImageFile(String origFile) throws Exception { - return createTempImageFile(origFile, "img", ".inf"); - } - - public static String createTempImageFile(String origFile, String prefix, String suffix) throws Exception { - File outputFile = createTempFile(prefix, suffix); - outputFile.deleteOnExit(); - copyFile(outputFile.getAbsolutePath(), origFile); - return outputFile.getAbsolutePath(); - } - - public static void copyFile(String imgFile, String origFile) throws Exception { - String fileContent = GlobalFile.getStringFromFile(origFile); - GlobalFile.saveStringToFile(fileContent, imgFile); - } - - public static File createTempFile(String prefix, String suffix) throws Exception { - String realSuffix = suffix; - if (!realSuffix.startsWith(".")) realSuffix = "."+suffix; - return File.createTempFile(prefix, realSuffix); - } -} +/** + * Description: Global package for file operations. + * + * @ Author Create/Modi Note + * Xiaofeng Xie Jun 15, 2002 + * + * @version 1.0 + * @Since MAOS1.0 + */ + + +package net.adaptivebox.global; + +import java.io.*; +import java.util.*; + +public class GlobalFile { + +// used by the createTempDir to give an index of temp number. + private static int counter = -1; + +/** + * Create a temp directory in the given directory. + * @param prefix the prefix for the directory. + * @param directory the directory that the temp dirctory placed. + * @return If a temp directory is created, return a File Object, else + * return null. + */ + public static File createTempDir(String prefix, String directory) + throws IOException { + File f = null; + String tempDir; + boolean isCreated = false; + do { + if (counter == -1) { + counter = new Random().nextInt() & 0xffff; + } + counter++; + if (prefix == null) + throw new NullPointerException(); + if (prefix.length() < 3) + throw new IllegalArgumentException("Prefix string too short"); + if (directory == null) { + tempDir = prefix + counter; + } else { + tempDir = getFileLocation(directory, prefix + counter); + } + f = new File(tempDir); + isCreated = f.mkdir(); + } while (!isCreated); + return f; + } + +/** + * Add the given text string to the end of a given file. + * @param inStr The string to be added. + * @param fileStr the name of the file to be added. + */ + public static void addStringToFile(String inStr, String fileStr) throws Exception { + + RandomAccessFile raFile = new RandomAccessFile(fileStr,"rw"); + raFile.seek(raFile.length()); + raFile.writeBytes(inStr); + raFile.close(); + + +// String oldFileStr = getStringFromFile(fileStr); +// String newFileStr = inStr; +// if (oldFileStr != null) { +// newFileStr = oldFileStr+inStr; +// } +// saveStringToFile(newFileStr,fileStr); + + } + + public static Object loadObjectFromFile(String fileName) throws Exception { + FileInputStream fis = new FileInputStream(fileName); + ObjectInputStream ois = new ObjectInputStream(fis); + Object obj = ois.readObject(); + ois.close(); + return obj; + } + + public static void saveObjectToFile(String fileName, Object obj) throws Exception { + FileOutputStream ostream = new FileOutputStream(fileName); + ObjectOutputStream p = new ObjectOutputStream(ostream); + p.writeObject(obj); + p.flush(); + ostream.close(); + } + +/** + * Save the given text string to a given file. + * @param inStr The string to be saved. + * @param fileStr the name of the file to be saved. + */ + public static void saveStringToFile(String inStr, String fileStr) throws Exception{ + new File(new File(fileStr).getParent()).mkdirs(); + FileOutputStream pspOutputStream = new FileOutputStream(new File(fileStr)); + pspOutputStream.write(inStr.getBytes()); + pspOutputStream.close(); + } + +/** + * Load text string from a given file. + * @param fileStr the name of the file to be loaded. + * @return A text string that is the content of the file. if the given file is + * not exist, then return null. + */ + public static String getStringFromFile(String fileStr) throws Exception { + String getStr = null; + FileInputStream pspInputStream = new FileInputStream(fileStr); + byte[] pspFileBuffer = new byte[pspInputStream.available()]; + pspInputStream.read(pspFileBuffer); + pspInputStream.close(); + getStr = new String(pspFileBuffer); + return(getStr); + } + +/** + * Load curve data from a specified file. + * @param fileStr the name of the file to be loaded. + * @return An ArrayList that include the curve data. + */ + public static ArrayList<ArrayList<Double>> getCurveDataFromFile(String fileName) { + File file = new File(fileName); + if(!file.exists()){ + //showMessage(); + return null; + } + //open data file + FileInputStream inStream = null; + BufferedReader inReader = null; + try{ + inStream = new FileInputStream(file); + inReader = new BufferedReader(new InputStreamReader(inStream)); + }catch(Exception e){ + //showMessage(); + return null;//Data file open error. + } + ArrayList<Double> xaxes = new ArrayList<Double>(1); + ArrayList<Double> yaxes = new ArrayList<Double>(1); + try{ + StringTokenizer st; + String s; + boolean start = false; + while(inReader.ready()!=false){ + st = new StringTokenizer(inReader.readLine()); + over:{ + while(!st.hasMoreTokens()){//Justify blank lines. + if(inReader.ready()!=false){ + st = new StringTokenizer(inReader.readLine()); + }else + break over; + } + s = st.nextToken(); + if((!start)&&(!s.startsWith("@"))) + break over; + if(!start){ + start = true; + break over; + } + if(s.startsWith("#")||s.startsWith("$")||s.startsWith("/")) break over;//Justify comment line. + Double xaxis = null; + Double yaxis = null; + try{ + xaxis = Double.valueOf(s); + xaxes.add(xaxis); + }catch(NumberFormatException e){ + //showMessage(); + inReader.close(); + inStream.close(); + return null;//Data file data format error. + } + s = st.nextToken(); + try{ + yaxis = Double.valueOf(s); + yaxes.add(yaxis); + }catch(NumberFormatException e){ + //showMessage(); + inReader.close(); + inStream.close(); + return null;//Data file data format error. + } + } + } + }catch(Exception e){ + //showMessage(); + return null;//Uncertain data file error. + } + ArrayList<ArrayList<Double>> curveData = new ArrayList<ArrayList<Double>>(2); + curveData.add(xaxes); + curveData.add(yaxes); + return curveData; + } + +/** + * Get a full path of a given file name and a directory name. + * @param fileName the name of the file. + * @param dir the name of directory. + * @return The full path. + */ + public static String getFileLocation(String dir, String fileName) { + String realDir = dir; + while (realDir.length()>0 && (realDir.endsWith("/")||realDir.endsWith("\\"))) { + realDir = dir.substring(0, dir.length()-1); + } + return realDir+BasicTag.FILE_SEP_TAG+fileName; + } + + public static String getFileName(String nameBody, String suffix) { + if (suffix==null || suffix.trim().length()==0) { + return nameBody; + } + String fileName = nameBody; + if(nameBody.endsWith(".")) { + return fileName+suffix; + } else { + return nameBody+"."+suffix; + } + } + + public static String getFileLocation(String dir, String fileNameBody, String fileNameSuffix) { + String filename = getFileName(fileNameBody, fileNameSuffix); + return getFileLocation(dir, filename); + } + + public static void clear(String fileStr) throws Exception { + File file = new File(fileStr); + if(file.isFile()) { + file.delete(); + return; + } + String[] fileNames = file.list(); + if (fileNames==null) { + return; + } + for (int i=0; i<fileNames.length; i++) { + String newFileName = GlobalFile.getFileLocation(fileStr,fileNames[i]); + clear(newFileName); + } + file.delete(); + } + + public static String getFilePrefix(String fileStr) { + int index = fileStr.lastIndexOf(BasicTag.DOT_TAG); + if(index==-1) index = fileStr.length(); + return fileStr.substring(0, index); + } + + public static String getFileSuffix(String fileStr) { + String[] subNames = GlobalString.tokenize(fileStr, BasicTag.DOT_TAG); + int subNameLen = subNames.length; + if(subNameLen==1) return ""; + else return subNames[subNameLen-1]; + } + + public static String createTempImageFile(String origFile) throws Exception { + return createTempImageFile(origFile, "img", ".inf"); + } + + public static String createTempImageFile(String origFile, String prefix, String suffix) throws Exception { + File outputFile = createTempFile(prefix, suffix); + outputFile.deleteOnExit(); + copyFile(outputFile.getAbsolutePath(), origFile); + return outputFile.getAbsolutePath(); + } + + public static void copyFile(String imgFile, String origFile) throws Exception { + String fileContent = GlobalFile.getStringFromFile(origFile); + GlobalFile.saveStringToFile(fileContent, imgFile); + } + + public static File createTempFile(String prefix, String suffix) throws Exception { + String realSuffix = suffix; + if (!realSuffix.startsWith(".")) realSuffix = "."+suffix; + return File.createTempFile(prefix, realSuffix); + } +} diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java index 80d1f97..28b4023 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java @@ -38,15 +38,11 @@ public class GlobalString { * divided by the tokenKey. */ public static String[] tokenize(String input , String tokenKey) { - Vector v = new Vector(); + ArrayList<String> v = new ArrayList<String>(); StringTokenizer t = new StringTokenizer(input, tokenKey); - String cmd[]; while (t.hasMoreTokens()) - v.addElement(t.nextToken()); - cmd = new String[v.size()]; - for (int i = 0; i < cmd.length; i++) - cmd[i] = (String) v.elementAt(i); - return cmd; + v.add(t.nextToken()); + return v.toArray(new String[v.size()]); } public static String[] getMeaningfulLines(String srcStr) throws Exception { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits