diff options
author | Noel Grandin <noel@peralex.com> | 2014-11-12 09:55:57 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2014-11-12 11:03:29 +0000 |
commit | bb437029c1e5331bcc3f8fb2fc87837142a52f33 (patch) | |
tree | 56bde4059792a5284e90ae3b10ee4388cc913a54 /nlpsolver | |
parent | 84f7f412bfc9e18b1ff8b133ceda7757eae28c36 (diff) |
java: convert fields to local variables where possible
found by PMD
Change-Id: I05b45382b8fb1b734657ce9421a20e6ef6fbe542
Reviewed-on: https://gerrit.libreoffice.org/12376
Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'nlpsolver')
7 files changed, 40 insertions, 68 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java index a67fe77e12c0..58b7e5e60c31 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/DEPSAgent.java @@ -51,8 +51,6 @@ public class DEPSAgent implements ILibEngine { //temp variable private AbsGTBehavior selectGTBehavior; - //The referred library - private Library socialLib; //the own memory: store the point that generated in old learning cycle private BasicPoint pold_t; //the own memory: store the point that generated in last learning cycle @@ -66,9 +64,8 @@ public class DEPSAgent implements ILibEngine { public double switchP = 0.5; public void setLibrary(Library lib) { - socialLib = lib; - deGTBehavior.setLibrary(socialLib); - psGTBehavior.setLibrary(socialLib); + deGTBehavior.setLibrary(lib); + psGTBehavior.setLibrary(lib); } public void setProblemEncoder(ProblemEncoder encoder) { diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/BaseNLPSolver.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/BaseNLPSolver.java index 8794beb96e0c..1e91448e0a31 100644 --- a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/BaseNLPSolver.java +++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/BaseNLPSolver.java @@ -82,9 +82,9 @@ public abstract class BaseNLPSolver extends WeakBase m_xContext = xContext; m_name = name; - m_componentFactory = xContext.getServiceManager(); + XMultiComponentFactory componentFactory = xContext.getServiceManager(); try { - Object toolkit = m_componentFactory.createInstanceWithContext("com.sun.star.awt.Toolkit", xContext); + Object toolkit = componentFactory.createInstanceWithContext("com.sun.star.awt.Toolkit", xContext); m_xReschedule = UnoRuntime.queryInterface(XReschedule.class, toolkit); } catch (Exception ex) { Logger.getLogger(BaseNLPSolver.class.getName()).log(Level.SEVERE, null, ex); @@ -115,7 +115,6 @@ public abstract class BaseNLPSolver extends WeakBase // com.sun.star.sheet.XSolver: private XSpreadsheetDocument m_document; - private XMultiComponentFactory m_componentFactory; private XModel m_xModel; protected XReschedule m_xReschedule; private CellAddress m_objective; @@ -129,7 +128,6 @@ public abstract class BaseNLPSolver extends WeakBase protected int m_cellRangeCount; protected XCell m_objectiveCell; protected XCell[] m_variableCells; - private CellRangeAddress[] m_cellRanges; protected XChartDataArray[] m_cellRangeData; protected CellMap[] m_variableMap; protected double[][][] m_variableData; @@ -280,21 +278,19 @@ public abstract class BaseNLPSolver extends WeakBase } m_cellRangeCount = cellRangeAddresses.size(); - m_cellRanges = new CellRangeAddress[m_cellRangeCount]; - m_cellRanges = cellRangeAddresses.toArray(m_cellRanges); m_cellRangeData = new XChartDataArray[m_cellRangeCount]; int varID = 0; //get cell range data and map the variables to their new location for (int i = 0; i < m_cellRangeCount; i++) { - for (int y = 0; y <= m_cellRanges[i].EndRow - m_cellRanges[i].StartRow; y++) - for (int x = 0; x <= m_cellRanges[i].EndColumn - m_cellRanges[i].StartColumn; x++) { + for (int y = 0; y <= cellRangeAddresses.get(i).EndRow - cellRangeAddresses.get(i).StartRow; y++) + for (int x = 0; x <= cellRangeAddresses.get(i).EndColumn - cellRangeAddresses.get(i).StartColumn; x++) { CellMap map = new CellMap(); m_variableMap[varID++] = map; map.Range = i; map.Col = x; map.Row = y; } - m_cellRangeData[i] = getChartDataArray(m_cellRanges[i]); + m_cellRangeData[i] = getChartDataArray(cellRangeAddresses.get(i)); m_variableData[i] = m_cellRangeData[i].getData(); } } diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java index 523ae209ca9a..f7fc741fc6bf 100644 --- a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java +++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/DEPSSolverImpl.java @@ -100,9 +100,6 @@ public final class DEPSSolverImpl extends BaseEvolutionarySolver return m_serviceNames; } - // com.sun.star.sheet.XSolver: - private DEPSAgent[] m_agents; - private PropertyInfo<Double> m_agentSwitchRate = new PropertyInfo<Double>("AgentSwitchRate", 0.5, "Agent Switch Rate (DE Probability)"); // --DE private PropertyInfo<Double> m_factor = new PropertyInfo<Double>("DEFactor", 0.5, "DE: Scaling Factor (0-1.2)"); @@ -122,11 +119,11 @@ public final class DEPSSolverImpl extends BaseEvolutionarySolver initializeSolve(); //Init: - m_agents = new DEPSAgent[m_swarmSize.getValue()]; + DEPSAgent[] agents = new DEPSAgent[m_swarmSize.getValue()]; for (int i = 0; i < m_swarmSize.getValue(); i++) { - m_agents[i] = new DEPSAgent(); - m_agents[i].setProblemEncoder(m_problemEncoder); - m_agents[i].setPbest(m_library.getSelectedPoint(i)); + agents[i] = new DEPSAgent(); + agents[i].setProblemEncoder(m_problemEncoder); + agents[i].setPbest(m_library.getSelectedPoint(i)); DEGTBehavior deGTBehavior = new DEGTBehavior(); deGTBehavior.FACTOR = m_factor.getValue(); @@ -138,12 +135,12 @@ public final class DEPSSolverImpl extends BaseEvolutionarySolver psGTBehavior.CL = m_CL.getValue(); psGTBehavior.weight = m_weight.getValue(); - m_agents[i].switchP = m_agentSwitchRate.getValue(); - m_agents[i].setGTBehavior(deGTBehavior); - m_agents[i].setGTBehavior(psGTBehavior); + agents[i].switchP = m_agentSwitchRate.getValue(); + agents[i].setGTBehavior(deGTBehavior); + agents[i].setGTBehavior(psGTBehavior); - m_agents[i].setSpecComparator(m_specCompareEngine); - m_agents[i].setLibrary(m_library); + agents[i].setSpecComparator(m_specCompareEngine); + agents[i].setLibrary(m_library); } //Learn: @@ -170,13 +167,13 @@ public final class DEPSSolverImpl extends BaseEvolutionarySolver m_library.refreshGbest(m_specCompareEngine); for (int i = 0; i < m_swarmSize.getValue(); i++) - m_agents[i].generatePoint(); + agents[i].generatePoint(); for (int i = 0; i < m_swarmSize.getValue(); i++) - m_agents[i].learn(); + agents[i].learn(); for (int i = 0; i < m_swarmSize.getValue(); i++) { - SearchPoint agentPoint = m_agents[i].getMGState(); + SearchPoint agentPoint = agents[i].getMGState(); boolean inRange = (agentPoint.getObjectiveValue() >= m_toleratedMin && agentPoint.getObjectiveValue() <= m_toleratedMax); if (Library.replace(m_envCompareEngine, agentPoint, m_totalBestPoint)) { m_solverStatusDialog.setBestSolution(m_totalBestPoint.getObjectiveValue(), m_totalBestPoint.isFeasible()); diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/ResourceManager.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/ResourceManager.java index 5acffa0a4ec2..33eebc8310eb 100644 --- a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/ResourceManager.java +++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/ResourceManager.java @@ -45,35 +45,30 @@ import com.sun.star.uno.XComponentContext; public class ResourceManager { - private final XComponentContext m_context; - private final String m_oxtRoot; - private final String m_resourceBaseUrl; private final String m_resourceBasename; private XStringResourceWithLocation m_xStrResource; - private Locale m_locale; public ResourceManager(XComponentContext xContext, String oxtId, String relativeResourceBaseUrl, String resourceBasename) { - m_context = xContext; m_resourceBasename = resourceBasename; - XPackageInformationProvider xPkgInfo = PackageInformationProvider.get(m_context); - m_oxtRoot = xPkgInfo.getPackageLocation(oxtId); - m_resourceBaseUrl = m_oxtRoot + relativeResourceBaseUrl; + XPackageInformationProvider xPkgInfo = PackageInformationProvider.get(xContext); + final String oxtRoot = xPkgInfo.getPackageLocation(oxtId); + final String resourceBaseUrl = oxtRoot + relativeResourceBaseUrl; try { - XMultiServiceFactory xConfig = theDefaultProvider.get(m_context); + XMultiServiceFactory xConfig = theDefaultProvider.get(xContext); Object[] args = new Object[1]; args[0] = new PropertyValue("nodepath", 0, "/org.openoffice.Setup/L10N", PropertyState.DIRECT_VALUE); XPropertySet xConfigProps = UnoRuntime.queryInterface(XPropertySet.class, xConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", args)); - String[] locale = AnyConverter.toString(xConfigProps.getPropertyValue("ooLocale")).split("-"); - String lang = locale[0]; - String country = (locale.length >= 2 ? locale[1] : ""); - String variant = (locale.length >= 3 ? locale[2] : ""); - m_locale = new Locale(lang, country, variant); + String[] localeProp = AnyConverter.toString(xConfigProps.getPropertyValue("ooLocale")).split("-"); + String lang = localeProp[0]; + String country = (localeProp.length >= 2 ? localeProp[1] : ""); + String variant = (localeProp.length >= 3 ? localeProp[2] : ""); + Locale locale = new Locale(lang, country, variant); - m_xStrResource = StringResourceWithLocation.create(m_context, m_resourceBaseUrl, true, m_locale, m_resourceBasename, "", null); + m_xStrResource = StringResourceWithLocation.create(xContext, resourceBaseUrl, true, locale, m_resourceBasename, "", null); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/SCOSolverImpl.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/SCOSolverImpl.java index 67e0ce7c86a6..cefe51006751 100644 --- a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/SCOSolverImpl.java +++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/SCOSolverImpl.java @@ -87,21 +87,17 @@ public final class SCOSolverImpl extends BaseEvolutionarySolver return m_serviceNames; } - // com.sun.star.sheet.XSolver: - - private SCAgent[] m_agents; - public void solve() { initializeSolve(); //Init: int swarmSize = m_swarmSize.getValue(); - m_agents = new SCAgent[swarmSize]; + SCAgent[] agents = new SCAgent[swarmSize]; for (int i = 0; i < swarmSize; i++) { - m_agents[i] = new SCAgent(); - m_agents[i].setProblemEncoder(m_problemEncoder); - m_agents[i].setSpecComparator(m_specCompareEngine); - m_agents[i].setExternalLib(m_library); + agents[i] = new SCAgent(); + agents[i].setProblemEncoder(m_problemEncoder); + agents[i].setSpecComparator(m_specCompareEngine); + agents[i].setExternalLib(m_library); } //Learn: @@ -127,7 +123,7 @@ public final class SCOSolverImpl extends BaseEvolutionarySolver m_toleratedCount < m_required.getValue() && m_solverStatusDialog.getUserState() != IEvolutionarySolverStatusDialog.CANCEL; learningCycle++) { for (int i = 0; i < swarmSize; i++) { - SearchPoint point = m_agents[i].generatePoint(); + SearchPoint point = agents[i].generatePoint(); boolean inRange = (point.getObjectiveValue() >= m_toleratedMin && point.getObjectiveValue() <= m_toleratedMax); if (Library.replace(m_envCompareEngine, point, m_totalBestPoint)) { m_solverStatusDialog.setBestSolution(m_totalBestPoint.getObjectiveValue(), m_totalBestPoint.isFeasible()); @@ -140,7 +136,7 @@ public final class SCOSolverImpl extends BaseEvolutionarySolver } for (int i = 0; i < swarmSize; i++) - m_agents[i].updateInfo(); + agents[i].updateInfo(); if (m_specCompareEngine instanceof IUpdateCycleEngine) ((IUpdateCycleEngine)m_specCompareEngine).updateCycle(learningCycle); diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java index 6cbde1ed1688..bf73962151c8 100644 --- a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java +++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java @@ -57,12 +57,10 @@ import java.util.logging.Logger; public abstract class BaseDialog extends BaseControl { private XMultiComponentFactory xMCF; - private Object toolkit; private XMultiServiceFactory xMSF; protected XWindow xWindow; protected XDialog xDialog; private XWindowPeer xWindowPeer; - private ModalState modalState; @Override public String getName() { @@ -92,7 +90,7 @@ public abstract class BaseDialog extends BaseControl { public BaseDialog(XComponentContext context, String title, int x, int y, int width, int height) { super(context); - modalState = ModalState.Exit; + ModalState modalState = ModalState.Exit; try { xMCF = context.getServiceManager(); setUnoModel(xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", context)); @@ -107,7 +105,7 @@ public abstract class BaseDialog extends BaseControl { XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, getUnoModel()); xControl.setModel(xControlModel); - toolkit = xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", context); + Object toolkit = xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", context); XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit); xWindow = UnoRuntime.queryInterface(XWindow.class, unoControl); xWindow.setVisible(false); diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java index 024e90978205..cd3dc0c3c7cb 100644 --- a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java +++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java @@ -45,9 +45,6 @@ public class EvolutionarySolverStatusUno extends BaseDialog XActionListener { private int userState; - - // <editor-fold defaultstate="collapsed" desc="UNO Controls"> - private Label lblSolution; private Label lblSolutionValue; private Label lblIteration; private ProgressBar pbIteration; @@ -55,12 +52,10 @@ public class EvolutionarySolverStatusUno extends BaseDialog private Label lblStagnation; private ProgressBar pbStagnation; private Label lblStagnationValue; - private Label lblRuntime; private Label lblRuntimeValue; private Button btnStop; private Button btnOK; private Button btnContinue; - // </editor-fold> private int defaultTextColor; private int maxIterations; private int maxStagnation; @@ -81,9 +76,8 @@ public class EvolutionarySolverStatusUno extends BaseDialog setProperty("Title", resourceManager.getLocalizedString("Dialog.Caption")); } catch (com.sun.star.resource.MissingResourceException ex) {} //leave the title as it is - // <editor-fold defaultstate="collapsed" desc="Create UNO Controls"> int y = 5; - lblSolution = new Label(this, "lblSolution"); + Label lblSolution = new Label(this, "lblSolution"); lblSolution.setPosition(5, y); lblSolution.setSize(60, 10); lblSolution.setLabel(resourceManager.getLocalizedString("Controls.lblSolution", "Current Solution:")); @@ -138,7 +132,7 @@ public class EvolutionarySolverStatusUno extends BaseDialog lblStagnationValue.setVisible(false); y+= 20; - lblRuntime = new Label(this, "lblRuntime"); + Label lblRuntime = new Label(this, "lblRuntime"); lblRuntime.setPosition(5, y); lblRuntime.setSize(60, 10); lblRuntime.setLabel(resourceManager.getLocalizedString("Controls.lblRuntime", "Runtime:")); @@ -176,7 +170,6 @@ public class EvolutionarySolverStatusUno extends BaseDialog btnContinue.setActionCommand("btnContinueClick"); btnContinue.setEnabled(false); y += 15; - // </editor-fold> } public int getUserState() { |