Commit 2a48844d authored by Fabian Becker's avatar Fabian Becker

Code cleanup to use Java 8 features

parent ed563d48
......@@ -1053,12 +1053,10 @@ public class OptimizerFactory {
OptimizerRunnable runnable, InterfacePostProcessParams ppp) {
Population resPop = postProcess(runnable, ppp);
List<double[]> ret = new ArrayList<>(resPop.size());
for (Object o : resPop) {
if (o instanceof InterfaceDataTypeDouble) {
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) o;
ret.add(indy.getDoubleData());
}
}
resPop.stream().filter(o -> o instanceof InterfaceDataTypeDouble).forEach(o -> {
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) o;
ret.add(indy.getDoubleData());
});
return ret;
}
......@@ -1094,17 +1092,10 @@ public class OptimizerFactory {
Population resPop = postProcess(runnable, ppp);
List<AbstractEAIndividual> ret = new ArrayList<>(
resPop.size());
for (Object o : resPop) {
if (o instanceof AbstractEAIndividual) {
AbstractEAIndividual indy = (AbstractEAIndividual) o;
ret.add(indy);
}
}
resPop.stream().filter(o -> o != null).forEach(ret::add);
return ret;
}
///////////////////////////// termination management
/**
* Replace the current user-defined terminator by the given one.
*
......
......@@ -93,19 +93,16 @@ public class HtmlDemo {
*
*/
public HyperlinkListener createHyperLinkListener() {
return new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (e instanceof HTMLFrameHyperlinkEvent) {
((HTMLDocument) htmlEditorPane.getDocument()).processHTMLFrameHyperlinkEvent(
(HTMLFrameHyperlinkEvent) e);
} else {
try {
htmlEditorPane.setPage(e.getURL());
} catch (IOException ioe) {
System.out.println("IOE: " + ioe);
}
return e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (e instanceof HTMLFrameHyperlinkEvent) {
((HTMLDocument) htmlEditorPane.getDocument()).processHTMLFrameHyperlinkEvent(
(HTMLFrameHyperlinkEvent) e);
} else {
try {
htmlEditorPane.setPage(e.getURL());
} catch (IOException ioe) {
System.out.println("IOE: " + ioe);
}
}
}
......
......@@ -87,9 +87,7 @@ public class JEFrame extends JInternalFrame {
@Override
public void actionPerformed(ActionEvent actionEvent) {
java.util.List<JEFrame> frameList = JEFrameRegister.getInstance().getFrameList();
for (JEFrame frame : frameList) {
frame.toFront();
}
frameList.forEach(JEFrame::toFront);
}
}
);
......
......@@ -512,12 +512,7 @@ public class MOCCOStandalone implements InterfaceStandaloneOptimization, Interfa
*/
void updateStatus(final String t, final int i) {
if (this.progressBar != null) {
Runnable doSetProgressBarValue = new Runnable() {
@Override
public void run() {
progressBar.setValue(i);
}
};
Runnable doSetProgressBarValue = () -> progressBar.setValue(i);
SwingUtilities.invokeLater(doSetProgressBarValue);
}
this.currentState.setText(t);
......
......@@ -838,9 +838,7 @@ public class MainFrame extends JFrame implements OptimizationStateListener {
@Override
public void performedStop() {
if (superListenerList != null) {
for (OptimizationStateListener l : superListenerList) {
l.performedStop();
}
superListenerList.forEach(OptimizationStateListener::performedStop);
}
long t = (System.currentTimeMillis() - startTime);
LOGGER.info(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000)));
......
......@@ -50,13 +50,9 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
runButton = ToolBoxGui.createIconifiedButton("images/Play24.gif", "Start", true);
runButton.setToolTipText("Start the current optimization run.");
runButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
//Run Opt pressed !
onUserStart();
}
runButton.addActionListener(event -> {
//Run Opt pressed !
onUserStart();
});
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.setToolTipText("Stop the current optimization run.");
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
try {
// this means user break
moduleAdapter.stopOptimization();
} catch (Exception ee) {
LOGGER.log(Level.WARNING, "Error while stopping job.", ee);
}
stopButton.addActionListener(event -> {
try {
// this means user break
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.setToolTipText("Start post processing according to available parameters.");
//postProcessButton.setBorderPainted(false);
postProcessButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
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);
postProcessButton.addActionListener(event -> {
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);
}
});
postProcessButton.setEnabled(runningState && moduleAdapter.hasPostProcessing());
......@@ -102,14 +90,10 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
scheduleButton = ToolBoxGui.createIconifiedButton("images/Server24.gif", "Schedule", true);
scheduleButton.setToolTipText("Schedule the currently configured optimization as a job.");
scheduleButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
OptimizationJob job = moduleAdapter.scheduleJob();
if (job == null) {
LOGGER.log(Level.WARNING, "There was an error on scheduling your job");
}
scheduleButton.addActionListener(event -> {
OptimizationJob job = moduleAdapter.scheduleJob();
if (job == null) {
LOGGER.log(Level.WARNING, "There was an error on scheduling your job");
}
});
scheduleButton.setEnabled(true);
......@@ -136,20 +120,16 @@ public class ModuleButtonPanelMaker implements OptimizationStateListener, Serial
if (helpFileName != null && (!helpFileName.equals(""))) {
helpButton = new JButton("Description");
helpButton.setToolTipText("Description of the current optimization algorithm.");
helpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
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.addActionListener(e -> {
try {
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());
}
});
toolBar.add(helpButton);
......
......@@ -38,13 +38,7 @@ class PropertySlider extends JPanel {
slider.setMinorTickSpacing(5);
slider.setPaintLabels(true);
this.add(slider);
propertyEditor.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
updateUs();
}
});
propertyEditor.addPropertyChangeListener(evt -> updateUs());
addKeyListener(new KeyAdapter() {
@Override
......
......@@ -509,12 +509,7 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization,
*/
void updateStatus(final int i) {
if (this.progressBar != null) {
Runnable doSetProgressBarValue = new Runnable() {
@Override
public void run() {
progressBar.setValue(i);
}
};
Runnable doSetProgressBarValue = () -> progressBar.setValue(i);
SwingUtilities.invokeLater(doSetProgressBarValue);
}
}
......@@ -580,9 +575,9 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization,
tmpData[1] = this.optimizationParameters.getProblem().getDoublePlotValue(population);
if (this.plot != null) {
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 {
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);
......
......@@ -97,24 +97,16 @@ public abstract class SwingWorker {
* and then exit.
*/
public SwingWorker() {
final Runnable doFinished = new Runnable() {
@Override
public void run() {
finished();
}
};
Runnable doConstruct = new Runnable() {
@Override
public void run() {
try {
setValue(construct());
} finally {
threadVar.clear();
}
final Runnable doFinished = () -> finished();
SwingUtilities.invokeLater(doFinished);
Runnable doConstruct = () -> {
try {
setValue(construct());
} finally {
threadVar.clear();
}
SwingUtilities.invokeLater(doFinished);
};
Thread t = new Thread(doConstruct);
......
......@@ -101,11 +101,9 @@ public class TabbedFrameMaker implements Serializable, PanelMaker, InterfaceNoti
}
public void refreshPanels() {
for (PanelMaker jpp : pmContainer) {
if (jpp instanceof JParaPanel) {
((JParaPanel) jpp).propertyEditor.setValue(((JParaPanel) jpp).propertyEditor.getValue());
}
}
pmContainer.stream().filter(jpp -> jpp instanceof JParaPanel).forEach(jpp -> {
((JParaPanel) jpp).propertyEditor.setValue(((JParaPanel) jpp).propertyEditor.getValue());
});
}
@Override
......@@ -225,22 +223,18 @@ class ClosableTabComponent extends JPanel {
JButton tabButton = new JButton(tabTitle);
/* Rotate it by -90° */
tabButton.setUI(new eva2.gui.utils.VerticalButtonUI(-90));
tabButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
/* Add the Tab Panel again */
// ToDo: Fix indexing problem
pane.insertTab(tabTitle, null, tabPane, "", tabPosition);
/* Set the tab component (closable) */
pane.setTabComponentAt(tabPosition, ClosableTabComponent.this);
pane.setVisible(true);
/* Remove the Button */
toolBar.remove((Component) e.getSource());
/* If the Button was the last one, hide ToolBar again */
if (toolBar.getComponentCount() == 0) {
toolBar.setVisible(false);
}
tabButton.addActionListener(e1 -> {
/* Add the Tab Panel again */
// ToDo: Fix indexing problem
pane.insertTab(tabTitle, null, tabPane, "", tabPosition);
/* Set the tab component (closable) */
pane.setTabComponentAt(tabPosition, ClosableTabComponent.this);
pane.setVisible(true);
/* Remove the Button */
toolBar.remove((Component) e1.getSource());
/* If the Button was the last one, hide ToolBar again */
if (toolBar.getComponentCount() == 0) {
toolBar.setVisible(false);
}
});
/* Add it to the ToolBar */
......
......@@ -413,9 +413,7 @@ public class ArrayEditor extends JPanel implements PropertyEditor {
// Upper Button Panel
JPanel combiUpperPanel = new JPanel(getButtonLayout(0, upperButtonList));
for (JButton but : upperButtonList) {
combiUpperPanel.add(but);
}
upperButtonList.forEach(combiUpperPanel::add);
setLayout(new GridBagLayout());
......@@ -443,9 +441,7 @@ public class ArrayEditor extends JPanel implements PropertyEditor {
lowerButtonList.add(deleteButton);
}
JPanel combiLowerPanel = new JPanel(getButtonLayout(0, lowerButtonList));
for (JButton but : lowerButtonList) {
combiLowerPanel.add(but);
}
lowerButtonList.forEach(combiLowerPanel::add);
gbConstraints.gridy++;
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.weightx = 1.0;
......@@ -610,9 +606,7 @@ public class ArrayEditor extends JPanel implements PropertyEditor {
// do nothing
} else { // right click released, so show popup
JPopupMenu popupMenu = new JPopupMenu();
for (JMenuItem item : popupItemList) {
popupMenu.add(item);
}
popupItemList.forEach(popupMenu::add);
popupMenu.show(ArrayEditor.this, e.getX(), e.getY());
}
}
......
......@@ -60,12 +60,7 @@ public class BigStringEditor implements PropertyEditor {
panel.setBorder(BorderFactory.createTitledBorder("Sourcecode"));
panel.setLayout(new BorderLayout());
setButton = new JButton("SET");
setButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setValue(textArea.getText());
}
});
setButton.addActionListener(e -> setValue(textArea.getText()));
panel.add(scrollPane, BorderLayout.CENTER);
panel.add(setButton, BorderLayout.SOUTH);
}
......
......@@ -67,14 +67,11 @@ public class EpsilonConstraintEditor extends JPanel implements PropertyEditor {
this.buttonPanel = new JPanel();
this.okButton = new JButton("OK");
this.okButton.setEnabled(true);
this.okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//backupObject = copyObject(object);
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
this.okButton.addActionListener(e -> {
//backupObject = copyObject(object);
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
});
this.buttonPanel.add(this.okButton);
......
......@@ -63,14 +63,11 @@ public class EpsilonThresholdEditor extends JPanel implements PropertyEditor {
this.buttonPanel = new JPanel();
this.okButton = new JButton("OK");
this.okButton.setEnabled(true);
this.okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//backupObject = copyObject(object);
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
this.okButton.addActionListener(e -> {
//backupObject = copyObject(object);
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
});
this.buttonPanel.add(this.okButton);
......
......@@ -55,12 +55,9 @@ public class MultiLineStringEditor implements PropertyEditor {
public Component getCustomEditor() {
final TextArea t = new TextArea(value.string);
t.setSize(300, 150); // TextArea doesn't have a preferred size, so set one
t.addTextListener(new TextListener() {
@Override
public void textValueChanged(TextEvent e) {
value.setString(t.getText());
listeners.firePropertyChange(null, null, null);
}
t.addTextListener(e -> {
value.setString(t.getText());
listeners.firePropertyChange(null, null, null);
});
return t;
}
......
......@@ -189,12 +189,7 @@ public class OptimizationObjectivesEditor extends JPanel implements PropertyEdit
/**
* This action listener,...
*/
ActionListener updateTargets = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
updateTargetList();
}
};
ActionListener updateTargets = event -> updateTargetList();
/**
* This action listener,...
......
......@@ -212,12 +212,7 @@ public class OptimizationObjectivesWithParamEditor extends JPanel implements Pro
/**
* This action listener,...
*/
ActionListener updateTargets = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
updateTargetList();
}
};
ActionListener updateTargets = event -> updateTargetList();
/**
* This action listener,...
......
......@@ -67,14 +67,11 @@ public class WeigthedLPTchebycheffEditor extends JPanel implements PropertyEdito
this.buttonPanel = new JPanel();
this.okButton = new JButton("OK");
this.okButton.setEnabled(true);
this.okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//backupObject = copyObject(object);
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
this.okButton.addActionListener(e -> {
//backupObject = copyObject(object);
if ((customEditor.getTopLevelAncestor() != null) && (customEditor.getTopLevelAncestor() instanceof Window)) {
Window w = (Window) customEditor.getTopLevelAncestor();
w.dispose();
}
});
this.buttonPanel.add(this.okButton);
......
......@@ -123,7 +123,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
// try to read constant
Pair<Double, String> nextState = readDouble(str, true);
if (nextState != null) {
return new Pair<AbstractGPNode, String>(new GPNodeConst(nextState.head()), nextState.tail());
return new Pair<>(new GPNodeConst(nextState.head()), nextState.tail());
} else {
System.err.println("String has unknown prefix: " + str);
}
......
......@@ -147,49 +147,34 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
return this.moStrategy;
}
ActionListener choosenMOEA = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_MOEA;
hasFinished = true;
}
ActionListener choosenMOEA = event -> {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_MOEA;
hasFinished = true;
};
ActionListener choosenSTEP = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_STEP;
hasFinished = true;
}
ActionListener choosenSTEP = event -> {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_STEP;
hasFinished = true;
};
ActionListener choosenREFP = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_REFP;
hasFinished = true;
}
ActionListener choosenREFP = event -> {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_REFP;
hasFinished = true;
};
ActionListener choosenTBCH = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_TBCH;
hasFinished = true;
}
ActionListener choosenTBCH = event -> {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_TBCH;
hasFinished = true;
};
ActionListener choosenGDF = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_GDF;
hasFinished = true;
}
ActionListener choosenGDF = event -> {
mocco.controlPanel.removeAll();
mocco.parameterPanel.removeAll();
moStrategy = STRATEGY_GDF;
hasFinished = true;
};
}
\ No newline at end of file
......@@ -110,21 +110,18 @@ public class MOCCOChooseReferenceSolution extends MOCCOPhase implements Interfac
this.selected.validate();
}
ActionListener continue2 = new ActionListener()