Code cleanup to use Java 8 features

This commit is contained in:
Fabian Becker 2015-12-31 18:51:42 +01:00
parent ed563d485f
commit 2a48844d9a
55 changed files with 261 additions and 516 deletions

View File

@ -1053,12 +1053,10 @@ public class OptimizerFactory {
OptimizerRunnable runnable, InterfacePostProcessParams ppp) { OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
Population resPop = postProcess(runnable, ppp); Population resPop = postProcess(runnable, ppp);
List<double[]> ret = new ArrayList<>(resPop.size()); List<double[]> ret = new ArrayList<>(resPop.size());
for (Object o : resPop) { resPop.stream().filter(o -> o instanceof InterfaceDataTypeDouble).forEach(o -> {
if (o instanceof InterfaceDataTypeDouble) { InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) o;
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) o; ret.add(indy.getDoubleData());
ret.add(indy.getDoubleData()); });
}
}
return ret; return ret;
} }
@ -1094,17 +1092,10 @@ public class OptimizerFactory {
Population resPop = postProcess(runnable, ppp); Population resPop = postProcess(runnable, ppp);
List<AbstractEAIndividual> ret = new ArrayList<>( List<AbstractEAIndividual> ret = new ArrayList<>(
resPop.size()); resPop.size());
for (Object o : resPop) { resPop.stream().filter(o -> o != null).forEach(ret::add);
if (o instanceof AbstractEAIndividual) {
AbstractEAIndividual indy = (AbstractEAIndividual) o;
ret.add(indy);
}
}
return ret; return ret;
} }
///////////////////////////// termination management
/** /**
* Replace the current user-defined terminator by the given one. * Replace the current user-defined terminator by the given one.
* *

View File

@ -93,19 +93,16 @@ public class HtmlDemo {
* *
*/ */
public HyperlinkListener createHyperLinkListener() { public HyperlinkListener createHyperLinkListener() {
return new HyperlinkListener() { return e -> {
@Override if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
public void hyperlinkUpdate(HyperlinkEvent e) { if (e instanceof HTMLFrameHyperlinkEvent) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { ((HTMLDocument) htmlEditorPane.getDocument()).processHTMLFrameHyperlinkEvent(
if (e instanceof HTMLFrameHyperlinkEvent) { (HTMLFrameHyperlinkEvent) e);
((HTMLDocument) htmlEditorPane.getDocument()).processHTMLFrameHyperlinkEvent( } else {
(HTMLFrameHyperlinkEvent) e); try {
} else { htmlEditorPane.setPage(e.getURL());
try { } catch (IOException ioe) {
htmlEditorPane.setPage(e.getURL()); System.out.println("IOE: " + ioe);
} catch (IOException ioe) {
System.out.println("IOE: " + ioe);
}
} }
} }
} }

View File

@ -87,9 +87,7 @@ public class JEFrame extends JInternalFrame {
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
java.util.List<JEFrame> frameList = JEFrameRegister.getInstance().getFrameList(); java.util.List<JEFrame> frameList = JEFrameRegister.getInstance().getFrameList();
for (JEFrame frame : frameList) { frameList.forEach(JEFrame::toFront);
frame.toFront();
}
} }
} }
); );

View File

@ -512,12 +512,7 @@ public class MOCCOStandalone implements InterfaceStandaloneOptimization, Interfa
*/ */
void updateStatus(final String t, final int i) { void updateStatus(final String t, final int i) {
if (this.progressBar != null) { if (this.progressBar != null) {
Runnable doSetProgressBarValue = new Runnable() { Runnable doSetProgressBarValue = () -> progressBar.setValue(i);
@Override
public void run() {
progressBar.setValue(i);
}
};
SwingUtilities.invokeLater(doSetProgressBarValue); SwingUtilities.invokeLater(doSetProgressBarValue);
} }
this.currentState.setText(t); this.currentState.setText(t);

View File

@ -838,9 +838,7 @@ public class MainFrame extends JFrame implements OptimizationStateListener {
@Override @Override
public void performedStop() { public void performedStop() {
if (superListenerList != null) { if (superListenerList != null) {
for (OptimizationStateListener l : superListenerList) { superListenerList.forEach(OptimizationStateListener::performedStop);
l.performedStop();
}
} }
long t = (System.currentTimeMillis() - startTime); long t = (System.currentTimeMillis() - startTime);
LOGGER.info(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000))); LOGGER.info(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000)));

View File

@ -50,13 +50,9 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
runButton = ToolBoxGui.createIconifiedButton("images/Play24.gif", "Start", true); runButton = ToolBoxGui.createIconifiedButton("images/Play24.gif", "Start", true);
runButton.setToolTipText("Start the current optimization run."); runButton.setToolTipText("Start the current optimization run.");
runButton.addActionListener(new ActionListener() { runButton.addActionListener(event -> {
//Run Opt pressed !
@Override onUserStart();
public void actionPerformed(ActionEvent event) {
//Run Opt pressed !
onUserStart();
}
}); });
runButton.setEnabled(!runningState); // enabled if not running runButton.setEnabled(!runningState); // enabled if not running
@ -65,16 +61,12 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
stopButton = ToolBoxGui.createIconifiedButton("images/Stop24.gif", "Stop", true); stopButton = ToolBoxGui.createIconifiedButton("images/Stop24.gif", "Stop", true);
stopButton.setToolTipText("Stop the current optimization run."); stopButton.setToolTipText("Stop the current optimization run.");
stopButton.addActionListener(new ActionListener() { stopButton.addActionListener(event -> {
try {
@Override // this means user break
public void actionPerformed(ActionEvent event) { moduleAdapter.stopOptimization();
try { } catch (Exception ee) {
// this means user break LOGGER.log(Level.WARNING, "Error while stopping job.", ee);
moduleAdapter.stopOptimization();
} catch (Exception ee) {
LOGGER.log(Level.WARNING, "Error while stopping job.", ee);
}
} }
}); });
@ -84,17 +76,13 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
postProcessButton = ToolBoxGui.createIconifiedButton("images/History24.gif", "Post Process", true); postProcessButton = ToolBoxGui.createIconifiedButton("images/History24.gif", "Post Process", true);
postProcessButton.setToolTipText("Start post processing according to available parameters."); postProcessButton.setToolTipText("Start post processing according to available parameters.");
//postProcessButton.setBorderPainted(false); //postProcessButton.setBorderPainted(false);
postProcessButton.addActionListener(new ActionListener() { postProcessButton.addActionListener(event -> {
try {
@Override if (!moduleAdapter.startPostProcessing()) {
public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null, "Post processing seems deactivated! Check the settings.", "Warning", JOptionPane.WARNING_MESSAGE);
try {
if (!moduleAdapter.startPostProcessing()) {
JOptionPane.showMessageDialog(null, "Post processing seems deactivated! Check the settings.", "Warning", JOptionPane.WARNING_MESSAGE);
}
} catch (Exception ee) {
LOGGER.log(Level.WARNING, "Error in run", ee);
} }
} catch (Exception ee) {
LOGGER.log(Level.WARNING, "Error in run", ee);
} }
}); });
postProcessButton.setEnabled(runningState && moduleAdapter.hasPostProcessing()); postProcessButton.setEnabled(runningState && moduleAdapter.hasPostProcessing());
@ -102,14 +90,10 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
scheduleButton = ToolBoxGui.createIconifiedButton("images/Server24.gif", "Schedule", true); scheduleButton = ToolBoxGui.createIconifiedButton("images/Server24.gif", "Schedule", true);
scheduleButton.setToolTipText("Schedule the currently configured optimization as a job."); scheduleButton.setToolTipText("Schedule the currently configured optimization as a job.");
scheduleButton.addActionListener(new ActionListener() { scheduleButton.addActionListener(event -> {
OptimizationJob job = moduleAdapter.scheduleJob();
@Override if (job == null) {
public void actionPerformed(ActionEvent event) { LOGGER.log(Level.WARNING, "There was an error on scheduling your job");
OptimizationJob job = moduleAdapter.scheduleJob();
if (job == null) {
LOGGER.log(Level.WARNING, "There was an error on scheduling your job");
}
} }
}); });
scheduleButton.setEnabled(true); scheduleButton.setEnabled(true);
@ -136,20 +120,16 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
if (helpFileName != null && (!helpFileName.equals(""))) { if (helpFileName != null && (!helpFileName.equals(""))) {
helpButton = new JButton("Description"); helpButton = new JButton("Description");
helpButton.setToolTipText("Description of the current optimization algorithm."); helpButton.setToolTipText("Description of the current optimization algorithm.");
helpButton.addActionListener(new ActionListener() { helpButton.addActionListener(e -> {
try {
@Override if (helpFileName != null) {
public void actionPerformed(ActionEvent e) { HtmlDemo temp = new HtmlDemo(helpFileName);
try { temp.show();
if (helpFileName != null) {
HtmlDemo temp = new HtmlDemo(helpFileName);
temp.show();
}
helpButton.setEnabled(true);
} catch (Exception ee) {
ee.printStackTrace();
System.out.print("Error in run: " + ee + " : " + ee.getMessage());
} }
helpButton.setEnabled(true);
} catch (Exception ee) {
ee.printStackTrace();
System.out.print("Error in run: " + ee + " : " + ee.getMessage());
} }
}); });
toolBar.add(helpButton); toolBar.add(helpButton);

View File

@ -38,13 +38,7 @@ class PropertySlider extends JPanel {
slider.setMinorTickSpacing(5); slider.setMinorTickSpacing(5);
slider.setPaintLabels(true); slider.setPaintLabels(true);
this.add(slider); this.add(slider);
propertyEditor.addPropertyChangeListener(new PropertyChangeListener() { propertyEditor.addPropertyChangeListener(evt -> updateUs());
@Override
public void propertyChange(PropertyChangeEvent evt) {
updateUs();
}
});
addKeyListener(new KeyAdapter() { addKeyListener(new KeyAdapter() {
@Override @Override

View File

@ -509,12 +509,7 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization,
*/ */
void updateStatus(final int i) { void updateStatus(final int i) {
if (this.progressBar != null) { if (this.progressBar != null) {
Runnable doSetProgressBarValue = new Runnable() { Runnable doSetProgressBarValue = () -> progressBar.setValue(i);
@Override
public void run() {
progressBar.setValue(i);
}
};
SwingUtilities.invokeLater(doSetProgressBarValue); SwingUtilities.invokeLater(doSetProgressBarValue);
} }
} }
@ -580,9 +575,9 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization,
tmpData[1] = this.optimizationParameters.getProblem().getDoublePlotValue(population); tmpData[1] = this.optimizationParameters.getProblem().getDoublePlotValue(population);
if (this.plot != null) { if (this.plot != null) {
if (this.continueFlag) { if (this.continueFlag) {
this.plot.setConnectedPoint(tmpData[0] + this.recentFunctionCalls, tmpData[1].doubleValue(), 1000 + this.currentRun); this.plot.setConnectedPoint(tmpData[0] + this.recentFunctionCalls, tmpData[1], 1000 + this.currentRun);
} else { } else {
this.plot.setConnectedPoint(tmpData[0].doubleValue(), tmpData[1].doubleValue(), 1000 + this.currentRun); this.plot.setConnectedPoint(tmpData[0], tmpData[1], 1000 + this.currentRun);
} }
} }
this.tmpData.add(tmpData); this.tmpData.add(tmpData);

View File

@ -97,24 +97,16 @@ public abstract class SwingWorker {
* and then exit. * and then exit.
*/ */
public SwingWorker() { public SwingWorker() {
final Runnable doFinished = new Runnable() { final Runnable doFinished = () -> finished();
@Override
public void run() {
finished();
}
};
Runnable doConstruct = new Runnable() { Runnable doConstruct = () -> {
@Override try {
public void run() { setValue(construct());
try { } finally {
setValue(construct()); threadVar.clear();
} finally {
threadVar.clear();
}
SwingUtilities.invokeLater(doFinished);
} }
SwingUtilities.invokeLater(doFinished);
}; };
Thread t = new Thread(doConstruct); Thread t = new Thread(doConstruct);

View File

@ -101,11 +101,9 @@ public class TabbedFrameMaker implements Serializable, PanelMaker, InterfaceNoti
} }
public void refreshPanels() { public void refreshPanels() {
for (PanelMaker jpp : pmContainer) { pmContainer.stream().filter(jpp -> jpp instanceof JParaPanel).forEach(jpp -> {
if (jpp instanceof JParaPanel) { ((JParaPanel) jpp).propertyEditor.setValue(((JParaPanel) jpp).propertyEditor.getValue());
((JParaPanel) jpp).propertyEditor.setValue(((JParaPanel) jpp).propertyEditor.getValue()); });
}
}
} }
@Override @Override
@ -225,22 +223,18 @@ class ClosableTabComponent extends JPanel {
JButton tabButton = new JButton(tabTitle); JButton tabButton = new JButton(tabTitle);
/* Rotate it by -90° */ /* Rotate it by -90° */
tabButton.setUI(new eva2.gui.utils.VerticalButtonUI(-90)); tabButton.setUI(new eva2.gui.utils.VerticalButtonUI(-90));
tabButton.addActionListener(new ActionListener() { tabButton.addActionListener(e1 -> {
/* Add the Tab Panel again */
@Override // ToDo: Fix indexing problem
public void actionPerformed(ActionEvent e) { pane.insertTab(tabTitle, null, tabPane, "", tabPosition);
/* Add the Tab Panel again */ /* Set the tab component (closable) */
// ToDo: Fix indexing problem pane.setTabComponentAt(tabPosition, ClosableTabComponent.this);
pane.insertTab(tabTitle, null, tabPane, "", tabPosition); pane.setVisible(true);
/* Set the tab component (closable) */ /* Remove the Button */
pane.setTabComponentAt(tabPosition, ClosableTabComponent.this); toolBar.remove((Component) e1.getSource());
pane.setVisible(true); /* If the Button was the last one, hide ToolBar again */
/* Remove the Button */ if (toolBar.getComponentCount() == 0) {
toolBar.remove((Component) e.getSource()); toolBar.setVisible(false);
/* If the Button was the last one, hide ToolBar again */
if (toolBar.getComponentCount() == 0) {
toolBar.setVisible(false);
}
} }
}); });
/* Add it to the ToolBar */ /* Add it to the ToolBar */

View File

@ -413,9 +413,7 @@ public class ArrayEditor extends JPanel implements PropertyEditor {
// Upper Button Panel // Upper Button Panel
JPanel combiUpperPanel = new JPanel(getButtonLayout(0, upperButtonList)); JPanel combiUpperPanel = new JPanel(getButtonLayout(0, upperButtonList));
for (JButton but : upperButtonList) { upperButtonList.forEach(combiUpperPanel::add);
combiUpperPanel.add(but);
}
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
@ -443,9 +441,7 @@ public class ArrayEditor extends JPanel implements PropertyEditor {
lowerButtonList.add(deleteButton); lowerButtonList.add(deleteButton);
} }
JPanel combiLowerPanel = new JPanel(getButtonLayout(0, lowerButtonList)); JPanel combiLowerPanel = new JPanel(getButtonLayout(0, lowerButtonList));
for (JButton but : lowerButtonList) { lowerButtonList.forEach(combiLowerPanel::add);
combiLowerPanel.add(but);
}
gbConstraints.gridy++; gbConstraints.gridy++;
gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.weightx = 1.0; gbConstraints.weightx = 1.0;
@ -610,9 +606,7 @@ public class ArrayEditor extends JPanel implements PropertyEditor {
// do nothing // do nothing
} else { // right click released, so show popup } else { // right click released, so show popup
JPopupMenu popupMenu = new JPopupMenu(); JPopupMenu popupMenu = new JPopupMenu();
for (JMenuItem item : popupItemList) { popupItemList.forEach(popupMenu::add);
popupMenu.add(item);
}
popupMenu.show(ArrayEditor.this, e.getX(), e.getY()); popupMenu.show(ArrayEditor.this, e.getX(), e.getY());
} }
} }

View File

@ -60,12 +60,7 @@ public class BigStringEditor implements PropertyEditor {
panel.setBorder(BorderFactory.createTitledBorder("Sourcecode")); panel.setBorder(BorderFactory.createTitledBorder("Sourcecode"));
panel.setLayout(new BorderLayout()); panel.setLayout(new BorderLayout());
setButton = new JButton("SET"); setButton = new JButton("SET");
setButton.addActionListener(new ActionListener() { setButton.addActionListener(e -> setValue(textArea.getText()));
@Override
public void actionPerformed(ActionEvent e) {
setValue(textArea.getText());
}
});
panel.add(scrollPane, BorderLayout.CENTER); panel.add(scrollPane, BorderLayout.CENTER);
panel.add(setButton, BorderLayout.SOUTH); panel.add(setButton, BorderLayout.SOUTH);
} }

View File

@ -67,14 +67,11 @@ public class EpsilonConstraintEditor extends JPanel implements PropertyEditor {
this.buttonPanel = new JPanel(); this.buttonPanel = new JPanel();
this.okButton = new JButton("OK"); this.okButton = new JButton("OK");
this.okButton.setEnabled(true); this.okButton.setEnabled(true);
this.okButton.addActionListener(new ActionListener() { this.okButton.addActionListener(e -> {
@Override //backupObject = copyObject(object);
public void actionPerformed(ActionEvent e) { if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
//backupObject = copyObject(object); Window w = (Window) customEditor.getTopLevelAncestor();
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) { w.dispose();
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
} }
}); });
this.buttonPanel.add(this.okButton); this.buttonPanel.add(this.okButton);

View File

@ -63,14 +63,11 @@ public class EpsilonThresholdEditor extends JPanel implements PropertyEditor {
this.buttonPanel = new JPanel(); this.buttonPanel = new JPanel();
this.okButton = new JButton("OK"); this.okButton = new JButton("OK");
this.okButton.setEnabled(true); this.okButton.setEnabled(true);
this.okButton.addActionListener(new ActionListener() { this.okButton.addActionListener(e -> {
@Override //backupObject = copyObject(object);
public void actionPerformed(ActionEvent e) { if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
//backupObject = copyObject(object); Window w = (Window) customEditor.getTopLevelAncestor();
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) { w.dispose();
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
} }
}); });
this.buttonPanel.add(this.okButton); this.buttonPanel.add(this.okButton);

View File

@ -55,12 +55,9 @@ public class MultiLineStringEditor implements PropertyEditor {
public Component getCustomEditor() { public Component getCustomEditor() {
final TextArea t = new TextArea(value.string); final TextArea t = new TextArea(value.string);
t.setSize(300, 150); // TextArea doesn't have a preferred size, so set one t.setSize(300, 150); // TextArea doesn't have a preferred size, so set one
t.addTextListener(new TextListener() { t.addTextListener(e -> {
@Override value.setString(t.getText());
public void textValueChanged(TextEvent e) { listeners.firePropertyChange(null, null, null);
value.setString(t.getText());
listeners.firePropertyChange(null, null, null);
}
}); });
return t; return t;
} }

View File

@ -189,12 +189,7 @@ public class OptimizationObjectivesEditor extends JPanel implements PropertyEdit
/** /**
* This action listener,... * This action listener,...
*/ */
ActionListener updateTargets = new ActionListener() { ActionListener updateTargets = event -> updateTargetList();
@Override
public void actionPerformed(ActionEvent event) {
updateTargetList();
}
};
/** /**
* This action listener,... * This action listener,...

View File

@ -212,12 +212,7 @@ public class OptimizationObjectivesWithParamEditor extends JPanel implements Pro
/** /**
* This action listener,... * This action listener,...
*/ */
ActionListener updateTargets = new ActionListener() { ActionListener updateTargets = event -> updateTargetList();
@Override
public void actionPerformed(ActionEvent event) {
updateTargetList();
}
};
/** /**
* This action listener,... * This action listener,...

View File

@ -67,14 +67,11 @@ public class WeigthedLPTchebycheffEditor extends JPanel implements PropertyEdito
this.buttonPanel = new JPanel(); this.buttonPanel = new JPanel();
this.okButton = new JButton("OK"); this.okButton = new JButton("OK");
this.okButton.setEnabled(true); this.okButton.setEnabled(true);
this.okButton.addActionListener(new ActionListener() { this.okButton.addActionListener(e -> {
@Override //backupObject = copyObject(object);
public void actionPerformed(ActionEvent e) { if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
//backupObject = copyObject(object); Window w = (Window) customEditor.getTopLevelAncestor();
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) { w.dispose();
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
} }
}); });
this.buttonPanel.add(this.okButton); this.buttonPanel.add(this.okButton);

View File

@ -123,7 +123,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
// try to read constant // try to read constant
Pair<Double, String> nextState = readDouble(str, true); Pair<Double, String> nextState = readDouble(str, true);
if (nextState != null) { if (nextState != null) {
return new Pair<AbstractGPNode, String>(new GPNodeConst(nextState.head()), nextState.tail()); return new Pair<>(new GPNodeConst(nextState.head()), nextState.tail());
} else { } else {
System.err.println("String has unknown prefix: " + str); System.err.println("String has unknown prefix: " + str);
} }

View File

@ -147,49 +147,34 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
return this.moStrategy; return this.moStrategy;
} }
ActionListener choosenMOEA = new ActionListener() { ActionListener choosenMOEA = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.parameterPanel.removeAll();
mocco.controlPanel.removeAll(); moStrategy = STRATEGY_MOEA;
mocco.parameterPanel.removeAll(); hasFinished = true;
moStrategy = STRATEGY_MOEA;
hasFinished = true;
}
}; };
ActionListener choosenSTEP = new ActionListener() { ActionListener choosenSTEP = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.parameterPanel.removeAll();
mocco.controlPanel.removeAll(); moStrategy = STRATEGY_STEP;
mocco.parameterPanel.removeAll(); hasFinished = true;
moStrategy = STRATEGY_STEP;
hasFinished = true;
}
}; };
ActionListener choosenREFP = new ActionListener() { ActionListener choosenREFP = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.parameterPanel.removeAll();
mocco.controlPanel.removeAll(); moStrategy = STRATEGY_REFP;
mocco.parameterPanel.removeAll(); hasFinished = true;
moStrategy = STRATEGY_REFP;
hasFinished = true;
}
}; };
ActionListener choosenTBCH = new ActionListener() { ActionListener choosenTBCH = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.parameterPanel.removeAll();
mocco.controlPanel.removeAll(); moStrategy = STRATEGY_TBCH;
mocco.parameterPanel.removeAll(); hasFinished = true;
moStrategy = STRATEGY_TBCH;
hasFinished = true;
}
}; };
ActionListener choosenGDF = new ActionListener() { ActionListener choosenGDF = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.parameterPanel.removeAll();
mocco.controlPanel.removeAll(); moStrategy = STRATEGY_GDF;
mocco.parameterPanel.removeAll(); hasFinished = true;
moStrategy = STRATEGY_GDF;
hasFinished = true;
}
}; };
} }

View File

@ -110,21 +110,18 @@ public class MOCCOChooseReferenceSolution extends MOCCOPhase implements Interfac
this.selected.validate(); this.selected.validate();
} }
ActionListener continue2 = new ActionListener() { ActionListener continue2 = event -> {
@Override if (referenceSolution != null) {
public void actionPerformed(ActionEvent event) { mocco.view.setRefSolutionSelectable(false);
if (referenceSolution != null) { mocco.view.removeRefSolutionSelectionListeners();
mocco.view.setRefSolutionSelectable(false); mocco.controlPanel.removeAll();
mocco.view.removeRefSolutionSelectionListeners(); mocco.controlPanel.validate();
mocco.controlPanel.removeAll(); mocco.parameterPanel.removeAll();
mocco.controlPanel.validate(); hasFinished = true;
mocco.parameterPanel.removeAll(); } else {
hasFinished = true; JOptionPane.showMessageDialog(mocco.getMainFrame(),
} else { "No reference solution selected. Cannot proceed!",
JOptionPane.showMessageDialog(mocco.getMainFrame(), "Warning", JOptionPane.WARNING_MESSAGE);
"No reference solution selected. Cannot proceed!",
"Warning", JOptionPane.WARNING_MESSAGE);
}
} }
}; };

View File

@ -54,14 +54,11 @@ public class MOCCOInitialPopulationSize extends MOCCOPhase implements InterfaceP
} }
ActionListener continue2 = new ActionListener() { ActionListener continue2 = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.controlPanel.validate();
mocco.controlPanel.removeAll(); mocco.parameterPanel.removeAll();
mocco.controlPanel.validate(); hasFinished = true;
mocco.parameterPanel.removeAll();
hasFinished = true;
}
}; };
ActionListener popSizeEdited = new ActionListener() { ActionListener popSizeEdited = new ActionListener() {

View File

@ -136,26 +136,23 @@ public class MOCCOParameterizeMO extends MOCCOPhase implements InterfaceProcessE
"Please choose an appropriate multi-objecitve optimizer."), BorderLayout.NORTH); "Please choose an appropriate multi-objecitve optimizer."), BorderLayout.NORTH);
} }
ActionListener continue2 = new ActionListener() { ActionListener continue2 = event -> {
@Override //mocco.state.optimizer = (InterfaceOptimizer)optimizer.clone();
public void actionPerformed(ActionEvent event) { mocco.controlPanel.removeAll();
//mocco.state.optimizer = (InterfaceOptimizer)optimizer.clone(); mocco.parameterPanel.removeAll();
mocco.controlPanel.removeAll(); mocco.state.optimizer.setProblem(mocco.state.currentProblem);
mocco.parameterPanel.removeAll(); Population pop = mocco.state.optimizer.getPopulation();
mocco.state.optimizer.setProblem(mocco.state.currentProblem); pop.clear();
Population pop = mocco.state.optimizer.getPopulation(); if (pop.getArchive() != null) {
pop.clear(); pop.getArchive().clear();
if (pop.getArchive() != null) {
pop.getArchive().clear();
}
if (mocco.state.populationHistory.length > 0) {
pop = mocco.state.getSelectedPopulations();
mocco.state.optimizer.initializeByPopulation(pop, false);
if (pop.size() == 0) {
mocco.state.optimizer.initialize();
}
}
hasFinished = true;
} }
if (mocco.state.populationHistory.length > 0) {
pop = mocco.state.getSelectedPopulations();
mocco.state.optimizer.initializeByPopulation(pop, false);
if (pop.size() == 0) {
mocco.state.optimizer.initialize();
}
}
hasFinished = true;
}; };
} }

View File

@ -201,11 +201,8 @@ public class MOCCOParameterizeRefPoint extends MOCCOPhase implements InterfacePr
this.refPoint = point; this.refPoint = point;
} }
ActionListener satisfiedChanged = new ActionListener() { ActionListener satisfiedChanged = event -> {
@Override
public void actionPerformed(ActionEvent event) {
}
}; };
ActionListener continue2 = new ActionListener() { ActionListener continue2 = new ActionListener() {

View File

@ -129,12 +129,9 @@ public class MOCCOParameterizeSO extends MOCCOPhase implements InterfaceProcessE
} }
ActionListener continue2 = new ActionListener() { ActionListener continue2 = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.parameterPanel.removeAll();
mocco.controlPanel.removeAll(); hasFinished = true;
mocco.parameterPanel.removeAll();
hasFinished = true;
}
}; };
} }

View File

@ -34,11 +34,8 @@ public abstract class MOCCOPhase implements InterfaceProcessElement {
/** /**
* Save the stuff to *.ser file for offline optimization * Save the stuff to *.ser file for offline optimization
*/ */
ActionListener saveState2FileForOfflineOptimization = new ActionListener() { ActionListener saveState2FileForOfflineOptimization = event -> {
@Override // @todo
public void actionPerformed(ActionEvent event) {
// @todo
}
}; };
/** /**

View File

@ -76,14 +76,11 @@ public class MOCCOProblemInitialization extends MOCCOPhase implements InterfaceP
this.mocco.parameterPanel.add(paraPanel.makePanel(), BorderLayout.CENTER); this.mocco.parameterPanel.add(paraPanel.makePanel(), BorderLayout.CENTER);
} }
ActionListener continue2 = new ActionListener() { ActionListener continue2 = event -> {
@Override mocco.controlPanel.removeAll();
public void actionPerformed(ActionEvent event) { mocco.controlPanel.validate();
mocco.controlPanel.removeAll(); mocco.parameterPanel.removeAll();
mocco.controlPanel.validate(); hasFinished = true;
mocco.parameterPanel.removeAll();
hasFinished = true;
}
}; };
ActionListener problemChanged = new ActionListener() { ActionListener problemChanged = new ActionListener() {

View File

@ -74,19 +74,9 @@ public class ParetoFrontView2D extends JPanel implements InterfaceParetoFrontVie
this.updateView(); this.updateView();
} }
ActionListener jcomboboxListener = new ActionListener() { ActionListener jcomboboxListener = event -> updateView();
@Override
public void actionPerformed(ActionEvent event) {
updateView();
}
};
ActionListener jcombobox2Listener = new ActionListener() { ActionListener jcombobox2Listener = event -> updateObjectiveComboBoxes();
@Override
public void actionPerformed(ActionEvent event) {
updateObjectiveComboBoxes();
}
};
public void updateObjectiveComboBoxes() { public void updateObjectiveComboBoxes() {
objective1.removeActionListener(jcomboboxListener); objective1.removeActionListener(jcomboboxListener);

View File

@ -324,12 +324,7 @@ public class ParetoFrontViewScatterPlot extends JPanel implements InterfaceParet
this.updateView(); this.updateView();
} }
ActionListener jcomboboxListener = new ActionListener() { ActionListener jcomboboxListener = event -> updateView();
@Override
public void actionPerformed(ActionEvent event) {
updateView();
}
};
private void makeScatter() { private void makeScatter() {
InterfaceOptimizationObjective[] tmp = ((InterfaceMultiObjectiveDeNovoProblem) this.moccoViewer.moccoStandalone.state.currentProblem).getProblemObjectives(); InterfaceOptimizationObjective[] tmp = ((InterfaceMultiObjectiveDeNovoProblem) this.moccoViewer.moccoStandalone.state.currentProblem).getProblemObjectives();

View File

@ -106,9 +106,7 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab
*/ */
@Override @Override
public void performedStop() { public void performedStop() {
for (OptimizationStateListener listener : optimizationStateListeners) { optimizationStateListeners.forEach(OptimizationStateListener::performedStop);
listener.performedStop();
}
} }
@Override @Override

View File

@ -142,7 +142,7 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial
// lets assign them their squeeze factor // lets assign them their squeeze factor
for (int j = 0; j < coll.size(); j++) { for (int j = 0; j < coll.size(); j++) {
result[coll.get(j)] = coll.size(); result[coll.get(j)] = coll.size();
tmpIndy = pop.get(coll.get(j).intValue()); tmpIndy = pop.get(coll.get(j));
tmpIndy.putData("SqueezeFactor", coll.size()); tmpIndy.putData("SqueezeFactor", coll.size());
tmpIndy.putData("GridBox", curGrid); tmpIndy.putData("GridBox", curGrid);
} }

View File

@ -209,12 +209,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
/** /**
* This action listener,... * This action listener,...
*/ */
ActionListener updateTargets = new ActionListener() { ActionListener updateTargets = event -> updateTargetList();
@Override
public void actionPerformed(ActionEvent event) {
updateTargetList();
}
};
/** /**
* This action listener,... * This action listener,...

View File

@ -9,6 +9,7 @@ import eva2.tools.math.RNG;
import eva2.util.annotation.Description; import eva2.util.annotation.Description;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.stream.Collectors;
/** /**
@ -183,11 +184,7 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
if (indy1.getMutationOperator() instanceof MutateESCorrVector) { if (indy1.getMutationOperator() instanceof MutateESCorrVector) {
tmpList.add(((MutateESCorrVector) indy1.getMutationOperator()).scalingDev); tmpList.add(((MutateESCorrVector) indy1.getMutationOperator()).scalingDev);
} }
for (Object partner : partners) { tmpList.addAll(partners.stream().filter(partner -> ((AbstractEAIndividual) partner).getMutationOperator() instanceof MutateESCorrVector).map(partner -> ((MutateESCorrVector) ((AbstractEAIndividual) partner).getMutationOperator()).scalingDev).collect(Collectors.toList()));
if (((AbstractEAIndividual) partner).getMutationOperator() instanceof MutateESCorrVector) {
tmpList.add(((MutateESCorrVector) ((AbstractEAIndividual) partner).getMutationOperator()).scalingDev);
}
}
double[] list = new double[tmpList.size()]; double[] list = new double[tmpList.size()];
for (int i = 0; i < tmpList.size(); i++) { for (int i = 0; i < tmpList.size(); i++) {
list[i] = tmpList.get(i); list[i] = tmpList.get(i);

View File

@ -211,12 +211,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
/** /**
* This action listener,... * This action listener,...
*/ */
ActionListener updateTargets = new ActionListener() { ActionListener updateTargets = event -> updateTargetList();
@Override
public void actionPerformed(ActionEvent event) {
updateTargetList();
}
};
/** /**
* This action listener,... * This action listener,...

View File

@ -21,6 +21,7 @@ import eva2.util.annotation.Parameter;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
/** /**
@ -130,20 +131,16 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
public Population(Population population) { public Population(Population population) {
LOGGER.log(Level.FINER, "New population has been created."); LOGGER.log(Level.FINER, "New population has been created.");
setSameParams(population); setSameParams(population);
for (AbstractEAIndividual individual : population) { population.stream().filter(individual -> individual != null).forEach(individual -> {
if (individual != null) { this.add((AbstractEAIndividual) individual.clone());
this.add((AbstractEAIndividual) individual.clone()); });
}
}
copyHistAndArchive(population); copyHistAndArchive(population);
} }
public static Population makePopFromList(List<AbstractEAIndividual> indies) { public static Population makePopFromList(List<AbstractEAIndividual> indies) {
Population pop = new Population(indies.size()); Population pop = new Population(indies.size());
pop.setTargetSize(indies.size()); pop.setTargetSize(indies.size());
for (AbstractEAIndividual indy : indies) { pop.addAll(indies.stream().collect(Collectors.toList()));
pop.add(indy);
}
return pop; return pop;
} }
@ -1427,12 +1424,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
if (exclude.size() == 0) { if (exclude.size() == 0) {
return this; return this;
} }
Population pop = new Population(); Population pop = this.stream().filter(o -> !exclude.contains(o)).collect(Collectors.toCollection(Population::new));
for (AbstractEAIndividual o : this) {
if (!exclude.contains(o)) {
pop.add(o);
}
}
return pop; return pop;
} }

View File

@ -627,11 +627,9 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if ((resultOut != null)) { if ((resultOut != null)) {
resultOut.print(text); resultOut.print(text);
} }
for (InterfaceTextListener l : textListeners) { textListeners.stream().filter(l -> statisticsParameter.getOutputTo() != InterfaceStatisticsParameters.OutputTo.FILE).forEach(l -> {
if (statisticsParameter.getOutputTo() != InterfaceStatisticsParameters.OutputTo.FILE) { l.print(text);
l.print(text); });
}
}
} }
@Override @Override

View File

@ -200,9 +200,7 @@ public class OptimizationJobList extends PropertySelectableList<OptimizationJob>
private static ActionListener getClearSelectedActionListener(final Component parent, final OptimizationJobList jobList) { private static ActionListener getClearSelectedActionListener(final Component parent, final OptimizationJobList jobList) {
return e -> { return e -> {
List<OptimizationJob> jobs = jobList.getSelectedJobs(); List<OptimizationJob> jobs = jobList.getSelectedJobs();
for (OptimizationJob j : jobs) { jobs.forEach(OptimizationJob::resetJob);
j.resetJob();
}
}; };
} }

View File

@ -6,6 +6,7 @@ import eva2.problems.InterfaceAdditionalPopulationInformer;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* This simple statistics implementation can collect all Object data available during runs. * This simple statistics implementation can collect all Object data available during runs.
@ -54,11 +55,9 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac
resultData = new ArrayList<>(statisticsParameter.getMultiRuns()); resultData = new ArrayList<>(statisticsParameter.getMultiRuns());
List<String> description = getOutputHeaderFieldNames(informerList); List<String> description = getOutputHeaderFieldNames(informerList);
resultHeaderStrings = new ArrayList<>(); resultHeaderStrings = new ArrayList<>();
for (String str : description) { resultHeaderStrings.addAll(description.stream().collect(Collectors.toList()));
resultHeaderStrings.add(str);
}
for (int i = 0; i < statisticsParameter.getMultiRuns(); i++) { for (int i = 0; i < statisticsParameter.getMultiRuns(); i++) {
resultData.add(new ArrayList<Object[]>()); resultData.add(new ArrayList<>());
} }
} else { } else {
resultData = null; resultData = null;

View File

@ -561,9 +561,7 @@ public class ANPSO extends NichePSO implements InterfaceAdditionalPopulationInfo
} }
newMainPop.synchSize(); newMainPop.synchSize();
for (Population setOfSubswarm : setOfSubswarms) { setOfSubswarms.forEach(Population::synchSize);
setOfSubswarm.synchSize();
}
useAsSubSwarms(setOfSubswarms); useAsSubSwarms(setOfSubswarms);
useAsMainSwarm(newMainPop); useAsMainSwarm(newMainPop);
} }

View File

@ -30,6 +30,7 @@ import eva2.util.annotation.Description;
import eva2.util.annotation.Hidden; import eva2.util.annotation.Hidden;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* The infamous clustering based niching EA, still under construction. It should * The infamous clustering based niching EA, still under construction. It should
@ -761,7 +762,7 @@ public class ClusterBasedNichingEA extends AbstractOptimizer implements Interfac
newSp.setHistory((LinkedList<AbstractEAIndividual>) parentSp.getHistory().clone()); newSp.setHistory((LinkedList<AbstractEAIndividual>) parentSp.getHistory().clone());
} else { // start anew (from undiff) } else { // start anew (from undiff)
newSp.setGeneration(0); newSp.setGeneration(0);
newSp.setHistory(new LinkedList<AbstractEAIndividual>()); newSp.setHistory(new LinkedList<>());
} }
if (optimizer instanceof InterfaceSpeciesAware) { if (optimizer instanceof InterfaceSpeciesAware) {

View File

@ -241,9 +241,7 @@ public class MLTGA extends AbstractOptimizer implements java.io.Serializable, In
for (Set<Integer> mask : linkageTree) { for (Set<Integer> mask : linkageTree) {
BitSet gen = getBinaryData(indy); BitSet gen = getBinaryData(indy);
BitSet newGene = (BitSet) gen.clone(); BitSet newGene = (BitSet) gen.clone();
for (Integer flipID : mask) { mask.forEach(newGene::flip);
newGene.flip(flipID);
}
AbstractEAIndividual newIndy = (AbstractEAIndividual) this.template.clone(); AbstractEAIndividual newIndy = (AbstractEAIndividual) this.template.clone();
((InterfaceDataTypeBinary) newIndy).setBinaryGenotype(newGene); ((InterfaceDataTypeBinary) newIndy).setBinaryGenotype(newGene);
evaluate(newIndy); evaluate(newIndy);

View File

@ -48,7 +48,7 @@ public class NicheGraph implements java.io.Serializable {
*/ */
public void addVertex(String v) { public void addVertex(String v) {
if (!containsVertex(v)) { if (!containsVertex(v)) {
graphTable.put(v, new TreeSet<String>()); graphTable.put(v, new TreeSet<>());
} }
} }

View File

@ -294,7 +294,7 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
// initialize subswarms // initialize subswarms
//initSubswarmOptimizerTemplate(); //only in ctor, would change parameters for the next multirun //initSubswarmOptimizerTemplate(); //only in ctor, would change parameters for the next multirun
//subwarmOptimizerTemplate.initialize(); // dont initialize and evaluate individuals ! //subwarmOptimizerTemplate.initialize(); // dont initialize and evaluate individuals !
setSubSwarms(new Vector<ParticleSubSwarmOptimization>()); // dont want to use subswarms from old optimization run (especially not in multiruns)... setSubSwarms(new Vector<>()); // dont want to use subswarms from old optimization run (especially not in multiruns)...
indicesToReinit = null; indicesToReinit = null;
// show in plot // show in plot
//MainSwarm.setShow(true); //MainSwarm.setShow(true);

View File

@ -140,9 +140,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
} }
public void reinitIndividuals(Vector<int[]> indicesToReinit) { public void reinitIndividuals(Vector<int[]> indicesToReinit) {
for (int[] indices : indicesToReinit) { indicesToReinit.forEach(this::addNewParticlesToPopulation);
addNewParticlesToPopulation(indices);
}
} }
/** /**
@ -288,7 +286,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
//PBestImprovementsInARow //PBestImprovementsInARow
Integer counter = (Integer) currentindy.getData("PBestImprovementsInARow"); Integer counter = (Integer) currentindy.getData("PBestImprovementsInARow");
counter = counter.intValue() + 1; counter = counter + 1;
currentindy.putData("PBestImprovementsInARow", counter); currentindy.putData("PBestImprovementsInARow", counter);
} else { } else {
initPBestImprInARowOf(currentindy); initPBestImprInARowOf(currentindy);

View File

@ -175,12 +175,9 @@ public abstract class AbstractObjectEditor implements PropertyEditor, java.beans
helpText.append("SYNOPSIS\n").append(globalInfo).append("\n\n"); helpText.append("SYNOPSIS\n").append(globalInfo).append("\n\n");
helpButton = new JButton("Help"); helpButton = new JButton("Help");
helpButton.setToolTipText("More information about " + className); helpButton.setToolTipText("More information about " + className);
helpButton.addActionListener(new ActionListener() { helpButton.addActionListener(a -> {
@Override HtmlDemo temp = new HtmlDemo(StringTools.cutClassName(object.getClass().getName()) + ".html");
public void actionPerformed(ActionEvent a) { temp.show();
HtmlDemo temp = new HtmlDemo(StringTools.cutClassName(object.getClass().getName()) + ".html");
temp.show();
}
}); });
jt.setFont(new Font("SansSerif", Font.PLAIN, 12)); jt.setFont(new Font("SansSerif", Font.PLAIN, 12));
jt.setEditable(false); jt.setEditable(false);

View File

@ -31,30 +31,22 @@ public class GeneralGEOFaker extends JPanel {
openButton = new JButton("Open..."); openButton = new JButton("Open...");
openButton.setToolTipText("Load a configured object"); openButton.setToolTipText("Load a configured object");
openButton.setEnabled(true); openButton.setEnabled(true);
openButton.addActionListener(new ActionListener() { openButton.addActionListener(e -> {
@Override Object object = openObject();
public void actionPerformed(ActionEvent e) { if (object != null) {
Object object = openObject(); // setValue takes care of: Making sure obj is of right type,
if (object != null) { // and firing property change.
// setValue takes care of: Making sure obj is of right type, editor.setValue(object);
// and firing property change. // Need a second setValue to get property values filled in OK.
editor.setValue(object); // Not sure why.
// Need a second setValue to get property values filled in OK. editor.setValue(object); // <- Hannes ?!?!?
// Not sure why.
editor.setValue(object); // <- Hannes ?!?!?
}
} }
}); });
saveButton = new JButton("Save..."); saveButton = new JButton("Save...");
saveButton.setToolTipText("Save the current configured object"); saveButton.setToolTipText("Save the current configured object");
saveButton.setEnabled(true); saveButton.setEnabled(true);
saveButton.addActionListener(new ActionListener() { saveButton.addActionListener(e -> saveObject(editor.getValue()));
@Override
public void actionPerformed(ActionEvent e) {
saveObject(editor.getValue());
}
});
editButton = new JButton("Edit Source"); editButton = new JButton("Edit Source");
editButton.setToolTipText("Edit the Source"); editButton.setToolTipText("Edit the Source");
@ -62,13 +54,10 @@ public class GeneralGEOFaker extends JPanel {
okButton = new JButton("OK"); okButton = new JButton("OK");
okButton.setEnabled(true); okButton.setEnabled(true);
okButton.addActionListener(new ActionListener() { okButton.addActionListener(e -> {
@Override if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) {
public void actionPerformed(ActionEvent e) { Window w = (Window) getTopLevelAncestor();
if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { w.dispose();
Window w = (Window) getTopLevelAncestor();
w.dispose();
}
} }
}); });
setLayout(new BorderLayout()); setLayout(new BorderLayout());

View File

@ -72,66 +72,47 @@ public class GeneralGenericObjectEditorPanel extends JPanel implements ItemListe
objectChooser.setEditable(false); objectChooser.setEditable(false);
propertyPanelWrapper = new JPanel(); propertyPanelWrapper = new JPanel();
propertyPanel = this.objectEditor.getPropertyPanel(); propertyPanel = this.objectEditor.getPropertyPanel();
propertyPanel.addPropertyChangeListener(new PropertyChangeListener() { propertyPanel.addPropertyChangeListener(evt -> objectEditor.firePropertyChange("", null, objectEditor.getValue()));
@Override
public void propertyChange(PropertyChangeEvent evt) {
objectEditor.firePropertyChange("", null, objectEditor.getValue());
}
});
openButton = new JButton("Open..."); openButton = new JButton("Open...");
openButton.setToolTipText("Load a configured object"); openButton.setToolTipText("Load a configured object");
openButton.setEnabled(true); openButton.setEnabled(true);
openButton.addActionListener(new ActionListener() { openButton.addActionListener(e -> {
@Override Object object = openObject();
public void actionPerformed(ActionEvent e) { if (object != null) {
Object object = openObject(); // setValue takes care of: Making sure obj is of right type,
if (object != null) { // and firing property change.
// setValue takes care of: Making sure obj is of right type, objectEditor.setValue(object);
// and firing property change. // Need a second setValue to get property values filled in OK.
objectEditor.setValue(object); // Not sure why.
// Need a second setValue to get property values filled in OK. objectEditor.setValue(object); // <- Hannes ?!?!?
// Not sure why.
objectEditor.setValue(object); // <- Hannes ?!?!?
}
} }
}); });
saveButton = new JButton("Save..."); saveButton = new JButton("Save...");
saveButton.setToolTipText("Save the current configured object"); saveButton.setToolTipText("Save the current configured object");
saveButton.setEnabled(true); saveButton.setEnabled(true);
saveButton.addActionListener(new ActionListener() { saveButton.addActionListener(e -> saveObject(objectEditor.getValue()));
@Override
public void actionPerformed(ActionEvent e) {
saveObject(objectEditor.getValue());
}
});
okButton = new JButton("OK"); okButton = new JButton("OK");
okButton.setEnabled(true); okButton.setEnabled(true);
okButton.addActionListener(new ActionListener() { okButton.addActionListener(e -> {
@Override objectEditor.makeBackup();
public void actionPerformed(ActionEvent e) { if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) {
objectEditor.makeBackup(); Window w = (Window) getTopLevelAncestor();
if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { w.dispose();
Window w = (Window) getTopLevelAncestor();
w.dispose();
}
} }
}); });
cancelButton = new JButton("Cancel"); cancelButton = new JButton("Cancel");
cancelButton.setEnabled(false); cancelButton.setEnabled(false);
cancelButton.addActionListener(new ActionListener() { cancelButton.addActionListener(e -> {
@Override objectEditor.undoBackup();
public void actionPerformed(ActionEvent e) { updateClassType();
objectEditor.undoBackup(); updateChooser();
updateClassType(); updateChildPropertySheet();
updateChooser(); if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) {
updateChildPropertySheet(); Window w = (Window) getTopLevelAncestor();
if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { w.dispose();
Window w = (Window) getTopLevelAncestor();
w.dispose();
}
} }
}); });

View File

@ -16,6 +16,7 @@ import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* Use an external command as target function. * Use an external command as target function.
@ -294,9 +295,7 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem
List<String> res = runProcess(parameters, workingDir); List<String> res = runProcess(parameters, workingDir);
try { try {
for (String str : res) { fitList.addAll(res.stream().map(Double::new).collect(Collectors.toList()));
fitList.add(new Double(str));
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
System.err.println("Error: " + command + " delivered malformatted output for " + BeanInspector.toString(x)); System.err.println("Error: " + command + " delivered malformatted output for " + BeanInspector.toString(x));
e.printStackTrace(); e.printStackTrace();

View File

@ -67,28 +67,13 @@ public class MultirunRefiner {
this.fileMenu = new JMenu("File"); this.fileMenu = new JMenu("File");
this.loadMenuItem = new JMenuItem("Load"); this.loadMenuItem = new JMenuItem("Load");
this.loadMenuItem.setEnabled(true); this.loadMenuItem.setEnabled(true);
this.loadMenuItem.addActionListener(new ActionListener() { this.loadMenuItem.addActionListener(ev -> loadFile());
@Override
public void actionPerformed(ActionEvent ev) {
loadFile();
}
});
this.saveMenuItem = new JMenuItem("Save"); this.saveMenuItem = new JMenuItem("Save");
this.saveMenuItem.setEnabled(true); this.saveMenuItem.setEnabled(true);
this.saveMenuItem.addActionListener(new java.awt.event.ActionListener() { this.saveMenuItem.addActionListener(evt -> writeFile());
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
writeFile();
}
});
this.exitMenuItem = new JMenuItem("Exit"); this.exitMenuItem = new JMenuItem("Exit");
this.exitMenuItem.setEnabled(true); this.exitMenuItem.setEnabled(true);
this.exitMenuItem.addActionListener(new java.awt.event.ActionListener() { this.exitMenuItem.addActionListener(evt -> System.exit(0));
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
});
this.fileMenu.add(this.loadMenuItem); this.fileMenu.add(this.loadMenuItem);
this.fileMenu.add(this.saveMenuItem); this.fileMenu.add(this.saveMenuItem);

View File

@ -17,6 +17,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
/** /**
@ -127,12 +128,7 @@ public class ReflectPackage {
} }
public static ArrayList<Class> filterAssignableClasses(ArrayList<Class> classes, Class<?> reqSuperCls) { public static ArrayList<Class> filterAssignableClasses(ArrayList<Class> classes, Class<?> reqSuperCls) {
ArrayList<Class> assClasses = new ArrayList<>(); ArrayList<Class> assClasses = classes.stream().filter(aClass -> reqSuperCls.isAssignableFrom(aClass)).collect(Collectors.toCollection(ArrayList::new));
for (Class aClass : classes) {
if (reqSuperCls.isAssignableFrom(aClass)) {
assClasses.add(aClass);
}
}
return assClasses; return assClasses;
} }

View File

@ -242,7 +242,7 @@ public final class StringTools {
* @return * @return
*/ */
public static String wrapLine(String str, char[] breakChars, int len, double tolerancePerCent) { public static String wrapLine(String str, char[] breakChars, int len, double tolerancePerCent) {
StringBuffer res = new StringBuffer(); StringBuilder res = new StringBuilder();
String rest = str; String rest = str;
int minLen = (int) ((1. - tolerancePerCent) * (double) len); int minLen = (int) ((1. - tolerancePerCent) * (double) len);
int maxLen = (int) ((1. + tolerancePerCent) * (double) len); int maxLen = (int) ((1. + tolerancePerCent) * (double) len);

View File

@ -5,6 +5,7 @@ import eva2.gui.BeanInspector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* Collection of miscellaneous static helper methods. * Collection of miscellaneous static helper methods.
@ -65,10 +66,8 @@ public final class ToolBox {
* @return A double array containing the converted object values * @return A double array containing the converted object values
*/ */
public static Double[] parseDoubles(List<Object> l) { public static Double[] parseDoubles(List<Object> l) {
ArrayList<Double> values = new ArrayList<>(); ArrayList<Double> values = l.stream().map(ToolBox::toDouble).collect(Collectors.toCollection(ArrayList::new));
for (Object o : l) { // null if unsuccessful
values.add(toDouble(o)); // null if unsuccessful
}
return values.toArray(new Double[values.size()]); return values.toArray(new Double[values.size()]);
} }

View File

@ -9,6 +9,7 @@ import eva2.optimization.population.Population;
import eva2.tools.Pair; import eva2.tools.Pair;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public final class BayNet { public final class BayNet {
@ -37,9 +38,7 @@ public final class BayNet {
this.nodes[i] = (BayNode) b.nodes[i].clone(); this.nodes[i] = (BayNode) b.nodes[i].clone();
} }
this.rootNodes = new LinkedList<>(); this.rootNodes = new LinkedList<>();
for (Integer node : b.rootNodes) { this.rootNodes.addAll(b.rootNodes.stream().collect(Collectors.toList()));
this.rootNodes.add(node);
}
this.upperProbLimit = b.upperProbLimit; this.upperProbLimit = b.upperProbLimit;
this.lowerProbLimit = b.lowerProbLimit; this.lowerProbLimit = b.lowerProbLimit;
} }
@ -104,10 +103,7 @@ public final class BayNet {
// } // }
// } // }
// return result; // return result;
LinkedList<BayNode> result = new LinkedList<>(); LinkedList<BayNode> result = this.rootNodes.stream().map(i -> this.nodes[i]).collect(Collectors.toCollection(LinkedList::new));
for (Integer i : this.rootNodes) {
result.add(this.nodes[i]);
}
return result; return result;
} }
@ -137,10 +133,7 @@ public final class BayNet {
// } // }
// return result; // return result;
List<Integer> ids = n.getChildren(); List<Integer> ids = n.getChildren();
List<BayNode> result = new ArrayList<>(); List<BayNode> result = ids.stream().map(i -> this.nodes[i]).collect(Collectors.toList());
for (int i : ids) {
result.add(this.nodes[i]);
}
return result; return result;
} }
@ -163,10 +156,7 @@ public final class BayNet {
// } // }
// return result; // return result;
List<Integer> ids = n.getParents(); List<Integer> ids = n.getParents();
List<BayNode> result = new LinkedList<>(); List<BayNode> result = ids.stream().map(i -> this.nodes[i]).collect(Collectors.toCollection(LinkedList::new));
for (int i : ids) {
result.add(this.nodes[i]);
}
return result; return result;
} }
@ -180,11 +170,7 @@ public final class BayNet {
ArrayList<BayNode> result = new ArrayList<>(); ArrayList<BayNode> result = new ArrayList<>();
for (BayNode node : n) { for (BayNode node : n) {
List<BayNode> children = getChildren(node); List<BayNode> children = getChildren(node);
for (BayNode nod : children) { children.stream().filter(nod -> !result.contains(nod)).forEach(result::add);
if (!result.contains(nod)) {
result.add(nod);
}
}
} }
return result; return result;
} }

View File

@ -2,6 +2,7 @@ package eva2.tools.math;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public final class BayNode { public final class BayNode {
@ -22,12 +23,8 @@ public final class BayNode {
this.pTable = b.pTable.clone(); this.pTable = b.pTable.clone();
this.parents = new LinkedList<>(); this.parents = new LinkedList<>();
this.children = new LinkedList<>(); this.children = new LinkedList<>();
for (int i : b.parents) { this.parents.addAll(b.parents.stream().collect(Collectors.toList()));
this.parents.add(i); this.children.addAll(b.children.stream().collect(Collectors.toList()));
}
for (int i : b.children) {
this.children.add(i);
}
this.calculated = b.calculated; this.calculated = b.calculated;
} }

View File

@ -1,6 +1,5 @@
package eva2.optimization.population; package eva2.optimization.population;
import com.sun.org.apache.bcel.internal.generic.POP;
import eva2.optimization.individuals.AbstractEAIndividual; import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.ESIndividualDoubleData; import eva2.optimization.individuals.ESIndividualDoubleData;
import org.junit.Before; import org.junit.Before;
@ -442,4 +441,4 @@ public class PopulationTest {
public void testRemoveNIndividuals() throws Exception { public void testRemoveNIndividuals() throws Exception {
} }
} }