Code cleanup to use Java 8 features
This commit is contained in:
		| @@ -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(); | ||||
|             } | ||||
|         }; | ||||
|         final Runnable doFinished = () -> finished(); | ||||
|  | ||||
|         Runnable doConstruct = new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 try { | ||||
|                     setValue(construct()); | ||||
|                 } finally { | ||||
|                     threadVar.clear(); | ||||
|                 } | ||||
|  | ||||
|                 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; | ||||
|     }; | ||||
| } | ||||
| @@ -110,21 +110,18 @@ public class MOCCOChooseReferenceSolution extends MOCCOPhase implements Interfac | ||||
|         this.selected.validate(); | ||||
|     } | ||||
|  | ||||
|     ActionListener continue2 = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             if (referenceSolution != null) { | ||||
|                 mocco.view.setRefSolutionSelectable(false); | ||||
|                 mocco.view.removeRefSolutionSelectionListeners(); | ||||
|                 mocco.controlPanel.removeAll(); | ||||
|                 mocco.controlPanel.validate(); | ||||
|                 mocco.parameterPanel.removeAll(); | ||||
|                 hasFinished = true; | ||||
|             } else { | ||||
|                 JOptionPane.showMessageDialog(mocco.getMainFrame(), | ||||
|                         "No reference solution selected. Cannot proceed!", | ||||
|                         "Warning", JOptionPane.WARNING_MESSAGE); | ||||
|             } | ||||
|     ActionListener continue2 = event -> { | ||||
|         if (referenceSolution != null) { | ||||
|             mocco.view.setRefSolutionSelectable(false); | ||||
|             mocco.view.removeRefSolutionSelectionListeners(); | ||||
|             mocco.controlPanel.removeAll(); | ||||
|             mocco.controlPanel.validate(); | ||||
|             mocco.parameterPanel.removeAll(); | ||||
|             hasFinished = true; | ||||
|         } else { | ||||
|             JOptionPane.showMessageDialog(mocco.getMainFrame(), | ||||
|                     "No reference solution selected. Cannot proceed!", | ||||
|                     "Warning", JOptionPane.WARNING_MESSAGE); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|   | ||||
| @@ -54,14 +54,11 @@ public class MOCCOInitialPopulationSize extends MOCCOPhase implements InterfaceP | ||||
|     } | ||||
|  | ||||
|  | ||||
|     ActionListener continue2 = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             mocco.controlPanel.removeAll(); | ||||
|             mocco.controlPanel.validate(); | ||||
|             mocco.parameterPanel.removeAll(); | ||||
|             hasFinished = true; | ||||
|         } | ||||
|     ActionListener continue2 = event -> { | ||||
|         mocco.controlPanel.removeAll(); | ||||
|         mocco.controlPanel.validate(); | ||||
|         mocco.parameterPanel.removeAll(); | ||||
|         hasFinished = true; | ||||
|     }; | ||||
|  | ||||
|     ActionListener popSizeEdited = new ActionListener() { | ||||
|   | ||||
| @@ -136,26 +136,23 @@ public class MOCCOParameterizeMO extends MOCCOPhase implements InterfaceProcessE | ||||
|                 "Please choose an appropriate multi-objecitve optimizer."), BorderLayout.NORTH); | ||||
|     } | ||||
|  | ||||
|     ActionListener continue2 = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             //mocco.state.optimizer = (InterfaceOptimizer)optimizer.clone(); | ||||
|             mocco.controlPanel.removeAll(); | ||||
|             mocco.parameterPanel.removeAll(); | ||||
|             mocco.state.optimizer.setProblem(mocco.state.currentProblem); | ||||
|             Population pop = mocco.state.optimizer.getPopulation(); | ||||
|             pop.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; | ||||
|     ActionListener continue2 = event -> { | ||||
|         //mocco.state.optimizer = (InterfaceOptimizer)optimizer.clone(); | ||||
|         mocco.controlPanel.removeAll(); | ||||
|         mocco.parameterPanel.removeAll(); | ||||
|         mocco.state.optimizer.setProblem(mocco.state.currentProblem); | ||||
|         Population pop = mocco.state.optimizer.getPopulation(); | ||||
|         pop.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; | ||||
|     }; | ||||
| } | ||||
|   | ||||
| @@ -201,11 +201,8 @@ public class MOCCOParameterizeRefPoint extends MOCCOPhase implements InterfacePr | ||||
|         this.refPoint = point; | ||||
|     } | ||||
|  | ||||
|     ActionListener satisfiedChanged = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|     ActionListener satisfiedChanged = event -> { | ||||
|  | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     ActionListener continue2 = new ActionListener() { | ||||
|   | ||||
| @@ -129,12 +129,9 @@ public class MOCCOParameterizeSO extends MOCCOPhase implements InterfaceProcessE | ||||
|  | ||||
|     } | ||||
|  | ||||
|     ActionListener continue2 = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             mocco.controlPanel.removeAll(); | ||||
|             mocco.parameterPanel.removeAll(); | ||||
|             hasFinished = true; | ||||
|         } | ||||
|     ActionListener continue2 = event -> { | ||||
|         mocco.controlPanel.removeAll(); | ||||
|         mocco.parameterPanel.removeAll(); | ||||
|         hasFinished = true; | ||||
|     }; | ||||
| } | ||||
|   | ||||
| @@ -34,11 +34,8 @@ public abstract class MOCCOPhase implements InterfaceProcessElement { | ||||
|     /** | ||||
|      * Save the stuff to *.ser file for offline optimization | ||||
|      */ | ||||
|     ActionListener saveState2FileForOfflineOptimization = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             // @todo | ||||
|         } | ||||
|     ActionListener saveState2FileForOfflineOptimization = event -> { | ||||
|         // @todo | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -76,14 +76,11 @@ public class MOCCOProblemInitialization extends MOCCOPhase implements InterfaceP | ||||
|         this.mocco.parameterPanel.add(paraPanel.makePanel(), BorderLayout.CENTER); | ||||
|     } | ||||
|  | ||||
|     ActionListener continue2 = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             mocco.controlPanel.removeAll(); | ||||
|             mocco.controlPanel.validate(); | ||||
|             mocco.parameterPanel.removeAll(); | ||||
|             hasFinished = true; | ||||
|         } | ||||
|     ActionListener continue2 = event -> { | ||||
|         mocco.controlPanel.removeAll(); | ||||
|         mocco.controlPanel.validate(); | ||||
|         mocco.parameterPanel.removeAll(); | ||||
|         hasFinished = true; | ||||
|     }; | ||||
|  | ||||
|     ActionListener problemChanged = new ActionListener() { | ||||
|   | ||||
| @@ -74,19 +74,9 @@ public class ParetoFrontView2D extends JPanel implements InterfaceParetoFrontVie | ||||
|         this.updateView(); | ||||
|     } | ||||
|  | ||||
|     ActionListener jcomboboxListener = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             updateView(); | ||||
|         } | ||||
|     }; | ||||
|     ActionListener jcomboboxListener = event -> updateView(); | ||||
|  | ||||
|     ActionListener jcombobox2Listener = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             updateObjectiveComboBoxes(); | ||||
|         } | ||||
|     }; | ||||
|     ActionListener jcombobox2Listener = event -> updateObjectiveComboBoxes(); | ||||
|  | ||||
|     public void updateObjectiveComboBoxes() { | ||||
|         objective1.removeActionListener(jcomboboxListener); | ||||
|   | ||||
| @@ -324,12 +324,7 @@ public class ParetoFrontViewScatterPlot extends JPanel implements InterfaceParet | ||||
|         this.updateView(); | ||||
|     } | ||||
|  | ||||
|     ActionListener jcomboboxListener = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             updateView(); | ||||
|         } | ||||
|     }; | ||||
|     ActionListener jcomboboxListener = event -> updateView(); | ||||
|  | ||||
|     private void makeScatter() { | ||||
|         InterfaceOptimizationObjective[] tmp = ((InterfaceMultiObjectiveDeNovoProblem) this.moccoViewer.moccoStandalone.state.currentProblem).getProblemObjectives(); | ||||
|   | ||||
| @@ -106,9 +106,7 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab | ||||
|      */ | ||||
|     @Override | ||||
|     public void performedStop() { | ||||
|         for (OptimizationStateListener listener : optimizationStateListeners) { | ||||
|             listener.performedStop(); | ||||
|         } | ||||
|         optimizationStateListeners.forEach(OptimizationStateListener::performedStop); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -142,7 +142,7 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial | ||||
|                 // lets assign them their squeeze factor | ||||
|                 for (int j = 0; j < coll.size(); j++) { | ||||
|                     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("GridBox", curGrid); | ||||
|                 } | ||||
|   | ||||
| @@ -209,12 +209,7 @@ public class PropertyCrossoverMixerEditor 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,... | ||||
|   | ||||
| @@ -9,6 +9,7 @@ import eva2.tools.math.RNG; | ||||
| import eva2.util.annotation.Description; | ||||
|  | ||||
| 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) { | ||||
|             tmpList.add(((MutateESCorrVector) indy1.getMutationOperator()).scalingDev); | ||||
|         } | ||||
|         for (Object partner : partners) { | ||||
|             if (((AbstractEAIndividual) partner).getMutationOperator() instanceof MutateESCorrVector) { | ||||
|                 tmpList.add(((MutateESCorrVector) ((AbstractEAIndividual) partner).getMutationOperator()).scalingDev); | ||||
|             } | ||||
|         } | ||||
|         tmpList.addAll(partners.stream().filter(partner -> ((AbstractEAIndividual) partner).getMutationOperator() instanceof MutateESCorrVector).map(partner -> ((MutateESCorrVector) ((AbstractEAIndividual) partner).getMutationOperator()).scalingDev).collect(Collectors.toList())); | ||||
|         double[] list = new double[tmpList.size()]; | ||||
|         for (int i = 0; i < tmpList.size(); i++) { | ||||
|             list[i] = tmpList.get(i); | ||||
|   | ||||
| @@ -211,12 +211,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito | ||||
|     /** | ||||
|      * This action listener,... | ||||
|      */ | ||||
|     ActionListener updateTargets = new ActionListener() { | ||||
|         @Override | ||||
|         public void actionPerformed(ActionEvent event) { | ||||
|             updateTargetList(); | ||||
|         } | ||||
|     }; | ||||
|     ActionListener updateTargets = event -> updateTargetList(); | ||||
|  | ||||
|     /** | ||||
|      * This action listener,... | ||||
|   | ||||
| @@ -21,6 +21,7 @@ import eva2.util.annotation.Parameter; | ||||
| import java.util.*; | ||||
| import java.util.logging.Level; | ||||
| 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) { | ||||
|         LOGGER.log(Level.FINER, "New population has been created."); | ||||
|         setSameParams(population); | ||||
|         for (AbstractEAIndividual individual : population) { | ||||
|             if (individual != null) { | ||||
|                 this.add((AbstractEAIndividual) individual.clone()); | ||||
|             } | ||||
|         } | ||||
|         population.stream().filter(individual -> individual != null).forEach(individual -> { | ||||
|             this.add((AbstractEAIndividual) individual.clone()); | ||||
|         }); | ||||
|         copyHistAndArchive(population); | ||||
|     } | ||||
|  | ||||
|     public static Population makePopFromList(List<AbstractEAIndividual> indies) { | ||||
|         Population pop = new Population(indies.size()); | ||||
|         pop.setTargetSize(indies.size()); | ||||
|         for (AbstractEAIndividual indy : indies) { | ||||
|             pop.add(indy); | ||||
|         } | ||||
|         pop.addAll(indies.stream().collect(Collectors.toList())); | ||||
|         return pop; | ||||
|     } | ||||
|  | ||||
| @@ -1427,12 +1424,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul | ||||
|         if (exclude.size() == 0) { | ||||
|             return this; | ||||
|         } | ||||
|         Population pop = new Population(); | ||||
|         for (AbstractEAIndividual o : this) { | ||||
|             if (!exclude.contains(o)) { | ||||
|                 pop.add(o); | ||||
|             } | ||||
|         } | ||||
|         Population pop = this.stream().filter(o -> !exclude.contains(o)).collect(Collectors.toCollection(Population::new)); | ||||
|         return pop; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -627,11 +627,9 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter | ||||
|         if ((resultOut != null)) { | ||||
|             resultOut.print(text); | ||||
|         } | ||||
|         for (InterfaceTextListener l : textListeners) { | ||||
|             if (statisticsParameter.getOutputTo() != InterfaceStatisticsParameters.OutputTo.FILE) { | ||||
|                 l.print(text); | ||||
|             } | ||||
|         } | ||||
|         textListeners.stream().filter(l -> statisticsParameter.getOutputTo() != InterfaceStatisticsParameters.OutputTo.FILE).forEach(l -> { | ||||
|             l.print(text); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -200,9 +200,7 @@ public class OptimizationJobList extends PropertySelectableList<OptimizationJob> | ||||
|     private static ActionListener getClearSelectedActionListener(final Component parent, final OptimizationJobList jobList) { | ||||
|         return e -> { | ||||
|             List<OptimizationJob> jobs = jobList.getSelectedJobs(); | ||||
|             for (OptimizationJob j : jobs) { | ||||
|                 j.resetJob(); | ||||
|             } | ||||
|             jobs.forEach(OptimizationJob::resetJob); | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import eva2.problems.InterfaceAdditionalPopulationInformer; | ||||
| import java.io.Serializable; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| /** | ||||
|  * 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()); | ||||
|             List<String> description = getOutputHeaderFieldNames(informerList); | ||||
|             resultHeaderStrings = new ArrayList<>(); | ||||
|             for (String str : description) { | ||||
|                 resultHeaderStrings.add(str); | ||||
|             } | ||||
|             resultHeaderStrings.addAll(description.stream().collect(Collectors.toList())); | ||||
|             for (int i = 0; i < statisticsParameter.getMultiRuns(); i++) { | ||||
|                 resultData.add(new ArrayList<Object[]>()); | ||||
|                 resultData.add(new ArrayList<>()); | ||||
|             } | ||||
|         } else { | ||||
|             resultData = null; | ||||
|   | ||||
| @@ -561,9 +561,7 @@ public class ANPSO extends NichePSO implements InterfaceAdditionalPopulationInfo | ||||
|         } | ||||
|  | ||||
|         newMainPop.synchSize(); | ||||
|         for (Population setOfSubswarm : setOfSubswarms) { | ||||
|             setOfSubswarm.synchSize(); | ||||
|         } | ||||
|         setOfSubswarms.forEach(Population::synchSize); | ||||
|         useAsSubSwarms(setOfSubswarms); | ||||
|         useAsMainSwarm(newMainPop); | ||||
|     } | ||||
|   | ||||
| @@ -30,6 +30,7 @@ import eva2.util.annotation.Description; | ||||
| import eva2.util.annotation.Hidden; | ||||
|  | ||||
| import java.util.*; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| /** | ||||
|  * 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()); | ||||
|         } else { // start anew (from undiff) | ||||
|             newSp.setGeneration(0); | ||||
|             newSp.setHistory(new LinkedList<AbstractEAIndividual>()); | ||||
|             newSp.setHistory(new LinkedList<>()); | ||||
|         } | ||||
|  | ||||
|         if (optimizer instanceof InterfaceSpeciesAware) { | ||||
|   | ||||
| @@ -241,9 +241,7 @@ public class MLTGA extends AbstractOptimizer implements java.io.Serializable, In | ||||
|         for (Set<Integer> mask : linkageTree) { | ||||
|             BitSet gen = getBinaryData(indy); | ||||
|             BitSet newGene = (BitSet) gen.clone(); | ||||
|             for (Integer flipID : mask) { | ||||
|                 newGene.flip(flipID); | ||||
|             } | ||||
|             mask.forEach(newGene::flip); | ||||
|             AbstractEAIndividual newIndy = (AbstractEAIndividual) this.template.clone(); | ||||
|             ((InterfaceDataTypeBinary) newIndy).setBinaryGenotype(newGene); | ||||
|             evaluate(newIndy); | ||||
|   | ||||
| @@ -48,7 +48,7 @@ public class NicheGraph implements java.io.Serializable { | ||||
|      */ | ||||
|     public void addVertex(String v) { | ||||
|         if (!containsVertex(v)) { | ||||
|             graphTable.put(v, new TreeSet<String>()); | ||||
|             graphTable.put(v, new TreeSet<>()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -294,7 +294,7 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo | ||||
|         // initialize subswarms | ||||
|         //initSubswarmOptimizerTemplate(); //only in ctor, would change parameters for the next multirun  | ||||
|         //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; | ||||
|         // show in plot | ||||
|         //MainSwarm.setShow(true); | ||||
|   | ||||
| @@ -140,9 +140,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO | ||||
|     } | ||||
|  | ||||
|     public void reinitIndividuals(Vector<int[]> indicesToReinit) { | ||||
|         for (int[] indices : indicesToReinit) { | ||||
|             addNewParticlesToPopulation(indices); | ||||
|         } | ||||
|         indicesToReinit.forEach(this::addNewParticlesToPopulation); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -288,7 +286,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO | ||||
|  | ||||
|                 //PBestImprovementsInARow | ||||
|                 Integer counter = (Integer) currentindy.getData("PBestImprovementsInARow"); | ||||
|                 counter = counter.intValue() + 1; | ||||
|                 counter = counter + 1; | ||||
|                 currentindy.putData("PBestImprovementsInARow", counter); | ||||
|             } else { | ||||
|                 initPBestImprInARowOf(currentindy); | ||||
|   | ||||
| @@ -175,12 +175,9 @@ public abstract class AbstractObjectEditor implements PropertyEditor, java.beans | ||||
|         helpText.append("SYNOPSIS\n").append(globalInfo).append("\n\n"); | ||||
|         helpButton = new JButton("Help"); | ||||
|         helpButton.setToolTipText("More information about " + className); | ||||
|         helpButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent a) { | ||||
|                 HtmlDemo temp = new HtmlDemo(StringTools.cutClassName(object.getClass().getName()) + ".html"); | ||||
|                 temp.show(); | ||||
|             } | ||||
|         helpButton.addActionListener(a -> { | ||||
|             HtmlDemo temp = new HtmlDemo(StringTools.cutClassName(object.getClass().getName()) + ".html"); | ||||
|             temp.show(); | ||||
|         }); | ||||
|         jt.setFont(new Font("SansSerif", Font.PLAIN, 12)); | ||||
|         jt.setEditable(false); | ||||
|   | ||||
| @@ -31,30 +31,22 @@ public class GeneralGEOFaker extends JPanel { | ||||
|         openButton = new JButton("Open..."); | ||||
|         openButton.setToolTipText("Load a configured object"); | ||||
|         openButton.setEnabled(true); | ||||
|         openButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 Object object = openObject(); | ||||
|                 if (object != null) { | ||||
|                     // setValue takes care of: Making sure obj is of right type, | ||||
|                     // and firing property change. | ||||
|                     editor.setValue(object); | ||||
|                     // Need a second setValue to get property values filled in OK. | ||||
|                     // Not sure why. | ||||
|                     editor.setValue(object); // <- Hannes ?!?!? | ||||
|                 } | ||||
|         openButton.addActionListener(e -> { | ||||
|             Object object = openObject(); | ||||
|             if (object != null) { | ||||
|                 // setValue takes care of: Making sure obj is of right type, | ||||
|                 // and firing property change. | ||||
|                 editor.setValue(object); | ||||
|                 // Need a second setValue to get property values filled in OK. | ||||
|                 // Not sure why. | ||||
|                 editor.setValue(object); // <- Hannes ?!?!? | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         saveButton = new JButton("Save..."); | ||||
|         saveButton.setToolTipText("Save the current configured object"); | ||||
|         saveButton.setEnabled(true); | ||||
|         saveButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 saveObject(editor.getValue()); | ||||
|             } | ||||
|         }); | ||||
|         saveButton.addActionListener(e -> saveObject(editor.getValue())); | ||||
|  | ||||
|         editButton = new JButton("Edit Source"); | ||||
|         editButton.setToolTipText("Edit the Source"); | ||||
| @@ -62,13 +54,10 @@ public class GeneralGEOFaker extends JPanel { | ||||
|  | ||||
|         okButton = new JButton("OK"); | ||||
|         okButton.setEnabled(true); | ||||
|         okButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { | ||||
|                     Window w = (Window) getTopLevelAncestor(); | ||||
|                     w.dispose(); | ||||
|                 } | ||||
|         okButton.addActionListener(e -> { | ||||
|             if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { | ||||
|                 Window w = (Window) getTopLevelAncestor(); | ||||
|                 w.dispose(); | ||||
|             } | ||||
|         }); | ||||
|         setLayout(new BorderLayout()); | ||||
|   | ||||
| @@ -72,66 +72,47 @@ public class GeneralGenericObjectEditorPanel extends JPanel implements ItemListe | ||||
|         objectChooser.setEditable(false); | ||||
|         propertyPanelWrapper = new JPanel(); | ||||
|         propertyPanel = this.objectEditor.getPropertyPanel(); | ||||
|         propertyPanel.addPropertyChangeListener(new PropertyChangeListener() { | ||||
|             @Override | ||||
|             public void propertyChange(PropertyChangeEvent evt) { | ||||
|                 objectEditor.firePropertyChange("", null, objectEditor.getValue()); | ||||
|             } | ||||
|         }); | ||||
|         propertyPanel.addPropertyChangeListener(evt -> objectEditor.firePropertyChange("", null, objectEditor.getValue())); | ||||
|         openButton = new JButton("Open..."); | ||||
|         openButton.setToolTipText("Load a configured object"); | ||||
|         openButton.setEnabled(true); | ||||
|         openButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 Object object = openObject(); | ||||
|                 if (object != null) { | ||||
|                     // setValue takes care of: Making sure obj is of right type, | ||||
|                     // and firing property change. | ||||
|                     objectEditor.setValue(object); | ||||
|                     // Need a second setValue to get property values filled in OK. | ||||
|                     // Not sure why. | ||||
|                     objectEditor.setValue(object); // <- Hannes ?!?!? | ||||
|                 } | ||||
|         openButton.addActionListener(e -> { | ||||
|             Object object = openObject(); | ||||
|             if (object != null) { | ||||
|                 // setValue takes care of: Making sure obj is of right type, | ||||
|                 // and firing property change. | ||||
|                 objectEditor.setValue(object); | ||||
|                 // Need a second setValue to get property values filled in OK. | ||||
|                 // Not sure why. | ||||
|                 objectEditor.setValue(object); // <- Hannes ?!?!? | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         saveButton = new JButton("Save..."); | ||||
|         saveButton.setToolTipText("Save the current configured object"); | ||||
|         saveButton.setEnabled(true); | ||||
|         saveButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 saveObject(objectEditor.getValue()); | ||||
|             } | ||||
|         }); | ||||
|         saveButton.addActionListener(e -> saveObject(objectEditor.getValue())); | ||||
|  | ||||
|         okButton = new JButton("OK"); | ||||
|         okButton.setEnabled(true); | ||||
|         okButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 objectEditor.makeBackup(); | ||||
|                 if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { | ||||
|                     Window w = (Window) getTopLevelAncestor(); | ||||
|                     w.dispose(); | ||||
|                 } | ||||
|         okButton.addActionListener(e -> { | ||||
|             objectEditor.makeBackup(); | ||||
|             if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { | ||||
|                 Window w = (Window) getTopLevelAncestor(); | ||||
|                 w.dispose(); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         cancelButton = new JButton("Cancel"); | ||||
|         cancelButton.setEnabled(false); | ||||
|         cancelButton.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 objectEditor.undoBackup(); | ||||
|                 updateClassType(); | ||||
|                 updateChooser(); | ||||
|                 updateChildPropertySheet(); | ||||
|                 if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { | ||||
|                     Window w = (Window) getTopLevelAncestor(); | ||||
|                     w.dispose(); | ||||
|                 } | ||||
|         cancelButton.addActionListener(e -> { | ||||
|             objectEditor.undoBackup(); | ||||
|             updateClassType(); | ||||
|             updateChooser(); | ||||
|             updateChildPropertySheet(); | ||||
|             if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) { | ||||
|                 Window w = (Window) getTopLevelAncestor(); | ||||
|                 w.dispose(); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|   | ||||
| @@ -16,6 +16,7 @@ import java.io.*; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| /** | ||||
|  * Use an external command as target function. | ||||
| @@ -294,9 +295,7 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem | ||||
|  | ||||
|         List<String> res = runProcess(parameters, workingDir); | ||||
|         try { | ||||
|             for (String str : res) { | ||||
|                 fitList.add(new Double(str)); | ||||
|             } | ||||
|             fitList.addAll(res.stream().map(Double::new).collect(Collectors.toList())); | ||||
|         } catch (NumberFormatException e) { | ||||
|             System.err.println("Error: " + command + " delivered malformatted output for " + BeanInspector.toString(x)); | ||||
|             e.printStackTrace(); | ||||
|   | ||||
| @@ -67,28 +67,13 @@ public class MultirunRefiner { | ||||
|         this.fileMenu = new JMenu("File"); | ||||
|         this.loadMenuItem = new JMenuItem("Load"); | ||||
|         this.loadMenuItem.setEnabled(true); | ||||
|         this.loadMenuItem.addActionListener(new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent ev) { | ||||
|                 loadFile(); | ||||
|             } | ||||
|         }); | ||||
|         this.loadMenuItem.addActionListener(ev -> loadFile()); | ||||
|         this.saveMenuItem = new JMenuItem("Save"); | ||||
|         this.saveMenuItem.setEnabled(true); | ||||
|         this.saveMenuItem.addActionListener(new java.awt.event.ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(java.awt.event.ActionEvent evt) { | ||||
|                 writeFile(); | ||||
|             } | ||||
|         }); | ||||
|         this.saveMenuItem.addActionListener(evt -> writeFile()); | ||||
|         this.exitMenuItem = new JMenuItem("Exit"); | ||||
|         this.exitMenuItem.setEnabled(true); | ||||
|         this.exitMenuItem.addActionListener(new java.awt.event.ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(java.awt.event.ActionEvent evt) { | ||||
|                 System.exit(0); | ||||
|             } | ||||
|         }); | ||||
|         this.exitMenuItem.addActionListener(evt -> System.exit(0)); | ||||
|  | ||||
|         this.fileMenu.add(this.loadMenuItem); | ||||
|         this.fileMenu.add(this.saveMenuItem); | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import java.util.jar.JarEntry; | ||||
| import java.util.jar.JarInputStream; | ||||
| import java.util.logging.Level; | ||||
| 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) { | ||||
|         ArrayList<Class> assClasses = new ArrayList<>(); | ||||
|         for (Class aClass : classes) { | ||||
|             if (reqSuperCls.isAssignableFrom(aClass)) { | ||||
|                 assClasses.add(aClass); | ||||
|             } | ||||
|         } | ||||
|         ArrayList<Class> assClasses = classes.stream().filter(aClass -> reqSuperCls.isAssignableFrom(aClass)).collect(Collectors.toCollection(ArrayList::new)); | ||||
|         return assClasses; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -242,7 +242,7 @@ public final class StringTools { | ||||
|      * @return | ||||
|      */ | ||||
|     public static String wrapLine(String str, char[] breakChars, int len, double tolerancePerCent) { | ||||
|         StringBuffer res = new StringBuffer(); | ||||
|         StringBuilder res = new StringBuilder(); | ||||
|         String rest = str; | ||||
|         int minLen = (int) ((1. - tolerancePerCent) * (double) len); | ||||
|         int maxLen = (int) ((1. + tolerancePerCent) * (double) len); | ||||
|   | ||||
| @@ -5,6 +5,7 @@ import eva2.gui.BeanInspector; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| /** | ||||
|  * Collection of miscellaneous static helper methods. | ||||
| @@ -65,10 +66,8 @@ public final class ToolBox { | ||||
|      * @return A double array containing the converted object values | ||||
|      */ | ||||
|     public static Double[] parseDoubles(List<Object> l) { | ||||
|         ArrayList<Double> values = new ArrayList<>(); | ||||
|         for (Object o : l) { | ||||
|             values.add(toDouble(o)); // null if unsuccessful | ||||
|         } | ||||
|         ArrayList<Double> values = l.stream().map(ToolBox::toDouble).collect(Collectors.toCollection(ArrayList::new)); | ||||
|         // null if unsuccessful | ||||
|         return values.toArray(new Double[values.size()]); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -9,6 +9,7 @@ import eva2.optimization.population.Population; | ||||
| import eva2.tools.Pair; | ||||
|  | ||||
| import java.util.*; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| public final class BayNet { | ||||
|  | ||||
| @@ -37,9 +38,7 @@ public final class BayNet { | ||||
|             this.nodes[i] = (BayNode) b.nodes[i].clone(); | ||||
|         } | ||||
|         this.rootNodes = new LinkedList<>(); | ||||
|         for (Integer node : b.rootNodes) { | ||||
|             this.rootNodes.add(node); | ||||
|         } | ||||
|         this.rootNodes.addAll(b.rootNodes.stream().collect(Collectors.toList())); | ||||
|         this.upperProbLimit = b.upperProbLimit; | ||||
|         this.lowerProbLimit = b.lowerProbLimit; | ||||
|     } | ||||
| @@ -104,10 +103,7 @@ public final class BayNet { | ||||
| //			} | ||||
| //		} | ||||
| //		return result; | ||||
|         LinkedList<BayNode> result = new LinkedList<>(); | ||||
|         for (Integer i : this.rootNodes) { | ||||
|             result.add(this.nodes[i]); | ||||
|         } | ||||
|         LinkedList<BayNode> result = this.rootNodes.stream().map(i -> this.nodes[i]).collect(Collectors.toCollection(LinkedList::new)); | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
| @@ -137,10 +133,7 @@ public final class BayNet { | ||||
| //		} | ||||
| //		return result; | ||||
|         List<Integer> ids = n.getChildren(); | ||||
|         List<BayNode> result = new ArrayList<>(); | ||||
|         for (int i : ids) { | ||||
|             result.add(this.nodes[i]); | ||||
|         } | ||||
|         List<BayNode> result = ids.stream().map(i -> this.nodes[i]).collect(Collectors.toList()); | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
| @@ -163,10 +156,7 @@ public final class BayNet { | ||||
| //		} | ||||
| //		return result; | ||||
|         List<Integer> ids = n.getParents(); | ||||
|         List<BayNode> result = new LinkedList<>(); | ||||
|         for (int i : ids) { | ||||
|             result.add(this.nodes[i]); | ||||
|         } | ||||
|         List<BayNode> result = ids.stream().map(i -> this.nodes[i]).collect(Collectors.toCollection(LinkedList::new)); | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
| @@ -180,11 +170,7 @@ public final class BayNet { | ||||
|         ArrayList<BayNode> result = new ArrayList<>(); | ||||
|         for (BayNode node : n) { | ||||
|             List<BayNode> children = getChildren(node); | ||||
|             for (BayNode nod : children) { | ||||
|                 if (!result.contains(nod)) { | ||||
|                     result.add(nod); | ||||
|                 } | ||||
|             } | ||||
|             children.stream().filter(nod -> !result.contains(nod)).forEach(result::add); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package eva2.tools.math; | ||||
|  | ||||
| import java.util.LinkedList; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| public final class BayNode { | ||||
|  | ||||
| @@ -22,12 +23,8 @@ public final class BayNode { | ||||
|         this.pTable = b.pTable.clone(); | ||||
|         this.parents = new LinkedList<>(); | ||||
|         this.children = new LinkedList<>(); | ||||
|         for (int i : b.parents) { | ||||
|             this.parents.add(i); | ||||
|         } | ||||
|         for (int i : b.children) { | ||||
|             this.children.add(i); | ||||
|         } | ||||
|         this.parents.addAll(b.parents.stream().collect(Collectors.toList())); | ||||
|         this.children.addAll(b.children.stream().collect(Collectors.toList())); | ||||
|         this.calculated = b.calculated; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| package eva2.optimization.population; | ||||
|  | ||||
| import com.sun.org.apache.bcel.internal.generic.POP; | ||||
| import eva2.optimization.individuals.AbstractEAIndividual; | ||||
| import eva2.optimization.individuals.ESIndividualDoubleData; | ||||
| import org.junit.Before; | ||||
| @@ -442,4 +441,4 @@ public class PopulationTest { | ||||
|     public void testRemoveNIndividuals() throws Exception { | ||||
|  | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user