Ignore:
Timestamp:
2016-07-23T21:38:02+02:00 (8 years ago)
Author:
Don-vip
Message:

see #11390 - sonar - squid:S1604 - Java 8: Anonymous inner classes containing only one method should become lambdas

Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r9645 r10616  
    146146        File pluginJar = new File(pluginDir, info.name + ".jar");
    147147        final URL pluginJarUrl = Utils.fileToURL(pluginJar);
    148         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
    149               @Override
    150               public ClassLoader run() {
    151                   return new URLClassLoader(new URL[] {pluginJarUrl}, Main.class.getClassLoader());
    152               }
    153         });
     148        return AccessController.doPrivileged((PrivilegedAction<ClassLoader>)
     149                () -> new URLClassLoader(new URL[] {pluginJarUrl}, Main.class.getClassLoader()));
    154150    }
    155151}
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r10493 r10616  
    2424import java.util.Collection;
    2525import java.util.Collections;
    26 import java.util.Comparator;
    2726import java.util.HashMap;
    2827import java.util.HashSet;
     
    3534import java.util.Set;
    3635import java.util.TreeSet;
    37 import java.util.concurrent.Callable;
    3836import java.util.concurrent.ExecutionException;
    3937import java.util.concurrent.FutureTask;
     
    534532
    535533        // Continuation
    536         Main.worker.submit(new Runnable() {
    537             @Override
    538             public void run() {
    539                 // Build list of plugins to download
    540                 Set<PluginInformation> toDownload = new HashSet<>(pluginInfoDownloadTask.getAvailablePlugins());
    541                 for (Iterator<PluginInformation> it = toDownload.iterator(); it.hasNext();) {
    542                     PluginInformation info = it.next();
    543                     if (!missingRequiredPlugin.contains(info.getName())) {
    544                         it.remove();
     534        Main.worker.submit(() -> {
     535            // Build list of plugins to download
     536            Set<PluginInformation> toDownload = new HashSet<>(pluginInfoDownloadTask.getAvailablePlugins());
     537            for (Iterator<PluginInformation> it = toDownload.iterator(); it.hasNext();) {
     538                PluginInformation info = it.next();
     539                if (!missingRequiredPlugin.contains(info.getName())) {
     540                    it.remove();
     541                }
     542            }
     543            // Check if something has still to be downloaded
     544            if (!toDownload.isEmpty()) {
     545                // download plugins
     546                final PluginDownloadTask task = new PluginDownloadTask(parent, toDownload, tr("Download plugins"));
     547                Main.worker.submit(task);
     548                Main.worker.submit(() -> {
     549                    // restart if some plugins have been downloaded
     550                    if (!task.getDownloadedPlugins().isEmpty()) {
     551                        // update plugin list in preferences
     552                        Set<String> plugins = new HashSet<>(Main.pref.getCollection("plugins"));
     553                        for (PluginInformation plugin : task.getDownloadedPlugins()) {
     554                            plugins.add(plugin.name);
     555                        }
     556                        Main.pref.putCollection("plugins", plugins);
     557                        // restart
     558                        new RestartAction().actionPerformed(null);
     559                    } else {
     560                        Main.warn("No plugin downloaded, restart canceled");
    545561                    }
    546                 }
    547                 // Check if something has still to be downloaded
    548                 if (!toDownload.isEmpty()) {
    549                     // download plugins
    550                     final PluginDownloadTask task = new PluginDownloadTask(parent, toDownload, tr("Download plugins"));
    551                     Main.worker.submit(task);
    552                     Main.worker.submit(new Runnable() {
    553                         @Override
    554                         public void run() {
    555                             // restart if some plugins have been downloaded
    556                             if (!task.getDownloadedPlugins().isEmpty()) {
    557                                 // update plugin list in preferences
    558                                 Set<String> plugins = new HashSet<>(Main.pref.getCollection("plugins"));
    559                                 for (PluginInformation plugin : task.getDownloadedPlugins()) {
    560                                     plugins.add(plugin.name);
    561                                 }
    562                                 Main.pref.putCollection("plugins", plugins);
    563                                 // restart
    564                                 new RestartAction().actionPerformed(null);
    565                             } else {
    566                                 Main.warn("No plugin downloaded, restart canceled");
    567                             }
    568                         }
    569                     });
    570                 } else {
    571                     Main.warn("No plugin to download, operation canceled");
    572                 }
     562                });
     563            } else {
     564                Main.warn("No plugin to download, operation canceled");
    573565            }
    574566        });
     
    665657    public static synchronized DynamicURLClassLoader getPluginClassLoader() {
    666658        if (pluginClassLoader == null) {
    667             pluginClassLoader = AccessController.doPrivileged(new PrivilegedAction<DynamicURLClassLoader>() {
    668                 @Override
    669                 public DynamicURLClassLoader run() {
    670                     return new DynamicURLClassLoader(new URL[0], Main.class.getClassLoader());
    671                 }
    672             });
     659            pluginClassLoader = AccessController.doPrivileged((PrivilegedAction<DynamicURLClassLoader>)
     660                    () -> new DynamicURLClassLoader(new URL[0], Main.class.getClassLoader()));
    673661            sources.add(0, pluginClassLoader);
    674662        }
     
    760748            Collections.sort(
    761749                    toLoad,
    762                     new Comparator<PluginInformation>() {
    763                         @Override
    764                         public int compare(PluginInformation o1, PluginInformation o2) {
    765                             if (o1.stage < o2.stage) return -1;
    766                             if (o1.stage == o2.stage) return 0;
    767                             return 1;
    768                         }
     750                    (o1, o2) -> {
     751                        if (o1.stage < o2.stage) return -1;
     752                        if (o1.stage == o2.stage) return 0;
     753                        return 1;
    769754                    }
    770755            );
     
    11731158            return;
    11741159
    1175         final File[] files = pluginDir.listFiles(new FilenameFilter() {
    1176             @Override
    1177             public boolean accept(File dir, String name) {
    1178                 return name.endsWith(".jar.new");
    1179             }
    1180         });
     1160        final File[] files = pluginDir.listFiles((FilenameFilter) (dir, name) -> name.endsWith(".jar.new"));
    11811161        if (files == null)
    11821162            return;
     
    11981178            } catch (IOException e) {
    11991179                if (dowarn) {
    1200                     Main.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}",
     1180                    Main.warn(e, tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}",
    12011181                            plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage()));
    12021182                }
     
    13091289
    13101290        try {
    1311             FutureTask<Integer> task = new FutureTask<>(new Callable<Integer>() {
    1312                 @Override
    1313                 public Integer call() {
    1314                     return HelpAwareOptionPane.showOptionDialog(
    1315                             Main.parent,
    1316                             msg.toString(),
    1317                             tr("Update plugins"),
    1318                             JOptionPane.QUESTION_MESSAGE,
    1319                             null,
    1320                             options,
    1321                             options[0],
    1322                             ht("/ErrorMessages#ErrorInPlugin")
    1323                     );
    1324                 }
    1325             });
     1291            FutureTask<Integer> task = new FutureTask<>(() -> HelpAwareOptionPane.showOptionDialog(
     1292                    Main.parent,
     1293                    msg.toString(),
     1294                    tr("Update plugins"),
     1295                    JOptionPane.QUESTION_MESSAGE,
     1296                    null,
     1297                    options,
     1298                    options[0],
     1299                    ht("/ErrorMessages#ErrorInPlugin")
     1300            ));
    13261301            GuiHelper.runInEDT(task);
    13271302            return task.get();
     
    13941369            plugins.remove(plugin.getPluginInformation().name);
    13951370            Main.pref.putCollection("plugins", plugins);
    1396             GuiHelper.runInEDTAndWait(new Runnable() {
    1397                 @Override
    1398                 public void run() {
    1399                     JOptionPane.showMessageDialog(
    1400                             Main.parent,
    1401                             tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
    1402                             tr("Information"),
    1403                             JOptionPane.INFORMATION_MESSAGE
    1404                     );
    1405                 }
    1406             });
     1371            GuiHelper.runInEDTAndWait(() -> JOptionPane.showMessageDialog(
     1372                    Main.parent,
     1373                    tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
     1374                    tr("Information"),
     1375                    JOptionPane.INFORMATION_MESSAGE
     1376            ));
    14071377            return null;
    14081378        default:
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r10173 r10616  
    4747    }
    4848
     49    /**
     50     * Constructs a new {@code ReadLocalPluginInformationTask}.
     51     * @param monitor progress monitor
     52     */
    4953    public ReadLocalPluginInformationTask(ProgressMonitor monitor) {
    5054        super(tr("Reading local plugin information.."), monitor, false);
     
    7781
    7882    private static File[] listFiles(File pluginsDirectory, final String regex) {
    79         return pluginsDirectory.listFiles(
    80                 new FilenameFilter() {
    81                     @Override
    82                     public boolean accept(File dir, String name) {
    83                         return name.matches(regex);
    84                     }
    85                 }
    86         );
     83        return pluginsDirectory.listFiles((FilenameFilter) (dir, name) -> name.matches(regex));
    8784    }
    8885
     
    108105    protected void scanPluginFiles(ProgressMonitor monitor, File pluginsDirectory) {
    109106        File[] pluginFiles = pluginsDirectory.listFiles(
    110                 new FilenameFilter() {
    111                     @Override
    112                     public boolean accept(File dir, String name) {
    113                         return name.endsWith(".jar") || name.endsWith(".jar.new");
    114                     }
    115                 }
     107                (FilenameFilter) (dir, name) -> name.endsWith(".jar") || name.endsWith(".jar.new")
    116108        );
    117109        if (pluginFiles == null || pluginFiles.length == 0)
     
    131123                }
    132124            } catch (PluginException e) {
    133                 Main.warn("PluginException: "+e.getMessage());
     125                Main.warn(e, "PluginException: ");
    134126                Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
    135127            }
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r10173 r10616  
    200200    private static void displayErrorMessage(final ProgressMonitor monitor, final String msg, final String details, final String title,
    201201            final String firstMessage) {
    202         GuiHelper.runInEDTAndWait(new Runnable() {
    203             @Override public void run() {
    204                 JPanel panel = new JPanel(new GridBagLayout());
    205                 panel.add(new JLabel(firstMessage), GBC.eol().insets(0, 0, 0, 10));
    206                 StringBuilder b = new StringBuilder();
    207                 for (String part : msg.split("(?<=\\G.{200})")) {
    208                     b.append(part).append('\n');
    209                 }
    210                 panel.add(new JLabel("<html><body width=\"500\"><b>"+b.toString().trim()+"</b></body></html>"), GBC.eol().insets(0, 0, 0, 10));
    211                 if (details != null && !details.isEmpty()) {
    212                     panel.add(new JLabel(tr("Details:")), GBC.eol().insets(0, 0, 0, 10));
    213                     JosmTextArea area = new JosmTextArea(details);
    214                     area.setEditable(false);
    215                     area.setLineWrap(true);
    216                     area.setWrapStyleWord(true);
    217                     JScrollPane scrollPane = new JScrollPane(area);
    218                     scrollPane.setPreferredSize(new Dimension(500, 300));
    219                     panel.add(scrollPane, GBC.eol().fill());
    220                 }
    221                 JOptionPane.showMessageDialog(monitor.getWindowParent(), panel, title, JOptionPane.ERROR_MESSAGE);
    222             }
     202        GuiHelper.runInEDTAndWait(() -> {
     203            JPanel panel = new JPanel(new GridBagLayout());
     204            panel.add(new JLabel(firstMessage), GBC.eol().insets(0, 0, 0, 10));
     205            StringBuilder b = new StringBuilder();
     206            for (String part : msg.split("(?<=\\G.{200})")) {
     207                b.append(part).append('\n');
     208            }
     209            panel.add(new JLabel("<html><body width=\"500\"><b>"+b.toString().trim()+"</b></body></html>"), GBC.eol().insets(0, 0, 0, 10));
     210            if (details != null && !details.isEmpty()) {
     211                panel.add(new JLabel(tr("Details:")), GBC.eol().insets(0, 0, 0, 10));
     212                JosmTextArea area = new JosmTextArea(details);
     213                area.setEditable(false);
     214                area.setLineWrap(true);
     215                area.setWrapStyleWord(true);
     216                JScrollPane scrollPane = new JScrollPane(area);
     217                scrollPane.setPreferredSize(new Dimension(500, 300));
     218                panel.add(scrollPane, GBC.eol().fill());
     219            }
     220            JOptionPane.showMessageDialog(monitor.getWindowParent(), panel, title, JOptionPane.ERROR_MESSAGE);
    223221        });
    224222    }
     
    296294        for (String location : PluginInformation.getPluginLocations()) {
    297295            File[] f = new File(location).listFiles(
    298                     new FilenameFilter() {
    299                         @Override
    300                         public boolean accept(File dir, String name) {
    301                             return name.matches("^([0-9]+-)?site.*\\.txt$") ||
    302                             name.matches("^([0-9]+-)?site.*-icons\\.zip$");
    303                         }
    304                     }
     296                    (FilenameFilter) (dir, name) -> name.matches("^([0-9]+-)?site.*\\.txt$") ||
     297                                                    name.matches("^([0-9]+-)?site.*-icons\\.zip$")
    305298            );
    306299            if (f != null && f.length > 0) {
Note: See TracChangeset for help on using the changeset viewer.