Переглянути джерело

Merge pull request #194 from csmith/master

Use forEach where possible.
pull/195/head
Greg Holmes 9 роки тому
джерело
коміт
097a18b377
18 змінених файлів з 100 додано та 137 видалено
  1. 3
    5
      calc/src/com/dmdirc/addons/calc/Parser.java
  2. 1
    3
      contactlist/src/com/dmdirc/addons/contactlist/ContactListListener.java
  3. 6
    5
      debug/src/com/dmdirc/addons/debug/Debug.java
  4. 4
    6
      debug/src/com/dmdirc/addons/debug/commands/FakeUpdates.java
  5. 2
    4
      identd/src/com/dmdirc/addons/identd/IdentdServer.java
  6. 15
    23
      nickcolours/src/com/dmdirc/addons/nickcolours/NickColourManager.java
  7. 9
    9
      notifications/src/com/dmdirc/addons/notifications/NotificationCommand.java
  8. 5
    6
      notifications/src/com/dmdirc/addons/notifications/NotificationsManager.java
  9. 9
    10
      nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java
  10. 7
    10
      nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingManager.java
  11. 5
    6
      parser_xmpp/src/com/dmdirc/addons/parser_xmpp/FixedXmppConnection.java
  12. 3
    8
      parser_xmpp/src/com/dmdirc/addons/parser_xmpp/XmppParser.java
  13. 15
    17
      scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptCommand.java
  14. 2
    4
      scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptManager.java
  15. 6
    8
      scriptplugin/src/com/dmdirc/addons/scriptplugin/TypedProperties.java
  16. 1
    3
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupSettingsPanel.java
  17. 3
    4
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelListModesPane.java
  18. 4
    6
      ui_swing/src/com/dmdirc/addons/ui_swing/wizard/WizardPanel.java

+ 3
- 5
calc/src/com/dmdirc/addons/calc/Parser.java Переглянути файл

@@ -28,6 +28,7 @@ import java.util.Arrays;
28 28
 import java.util.Collections;
29 29
 import java.util.Comparator;
30 30
 import java.util.List;
31
+import java.util.stream.Collectors;
31 32
 
32 33
 /**
33 34
  * The parser takes the output from a {@link Lexer} and applies precedence rules to build the tokens
@@ -62,11 +63,8 @@ public class Parser {
62 63
      *                        involving a mis-matched bracket).
63 64
      */
64 65
     public TreeToken parse() throws ParseException {
65
-        final List<TreeToken> tokens = new ArrayList<>();
66
-
67
-        for (Token token : lexer.tokenise()) {
68
-            tokens.add(new TreeToken(token));
69
-        }
66
+        final List<TreeToken> tokens = lexer.tokenise().stream()
67
+                .map(TreeToken::new).collect(Collectors.toList());
70 68
 
71 69
         return parse(tokens);
72 70
     }

+ 1
- 3
contactlist/src/com/dmdirc/addons/contactlist/ContactListListener.java Переглянути файл

@@ -73,9 +73,7 @@ public class ContactListListener implements NicklistListener {
73 73
 
74 74
     @Override
75 75
     public void clientListUpdated(final Collection<ChannelClientInfo> clients) {
76
-        for (ChannelClientInfo client : clients) {
77
-            clientAdded(client);
78
-        }
76
+        clients.forEach(this::clientAdded);
79 77
     }
80 78
 
81 79
     @Override

+ 6
- 5
debug/src/com/dmdirc/addons/debug/Debug.java Переглянути файл

@@ -39,6 +39,7 @@ import java.util.HashMap;
39 39
 import java.util.List;
40 40
 import java.util.Map;
41 41
 import java.util.Set;
42
+import java.util.stream.Collectors;
42 43
 
43 44
 import javax.annotation.Nonnull;
44 45
 import javax.inject.Inject;
@@ -94,7 +95,7 @@ public class Debug extends Command implements IntelligentCommand {
94 95
                 final CommandArguments newArgs = new CommandArguments(
95 96
                         controller,
96 97
                         Arrays.asList((controller.getCommandChar()
97
-                                + command.getName() + " "
98
+                                + command.getName() + ' '
98 99
                                 + args.getArgumentsAsString(1)).split(" ")));
99 100
                 command.execute(origin, newArgs, context);
100 101
             }
@@ -124,7 +125,7 @@ public class Debug extends Command implements IntelligentCommand {
124 125
      */
125 126
     public void proxyShowUsage(final FrameContainer target,
126 127
             final boolean isSilent, final String name, final String args) {
127
-        showUsage(target, isSilent, INFO.getName(), name + " " + args);
128
+        showUsage(target, isSilent, INFO.getName(), name + ' ' + args);
128 129
     }
129 130
 
130 131
     /**
@@ -148,9 +149,9 @@ public class Debug extends Command implements IntelligentCommand {
148 149
     public List<String> getCommandNames() {
149 150
         final List<String> names = new ArrayList<>(commands.size());
150 151
 
151
-        for (DebugCommand command : commands.values()) {
152
-            names.add(command.getName());
153
-        }
152
+        names.addAll(commands.values().stream()
153
+                .map(DebugCommand::getName)
154
+                .collect(Collectors.toList()));
154 155
 
155 156
         return names;
156 157
     }

+ 4
- 6
debug/src/com/dmdirc/addons/debug/commands/FakeUpdates.java Переглянути файл

@@ -45,6 +45,7 @@ import java.util.Collection;
45 45
 import java.util.HashMap;
46 46
 import java.util.Map;
47 47
 
48
+import javax.annotation.Nonnull;
48 49
 import javax.inject.Inject;
49 50
 import javax.inject.Provider;
50 51
 
@@ -82,7 +83,7 @@ public class FakeUpdates extends DebugCommand {
82 83
     }
83 84
 
84 85
     @Override
85
-    public void execute(final FrameContainer origin,
86
+    public void execute(@Nonnull final FrameContainer origin,
86 87
             final CommandArguments args, final CommandContext context) {
87 88
         updateManager.addCheckStrategy(new FakeUpdateCheckStrategy());
88 89
         updateManager.addRetrievalStrategy(new FakeUpdateRetriever());
@@ -100,11 +101,8 @@ public class FakeUpdates extends DebugCommand {
100 101
                 final Collection<UpdateComponent> components) {
101 102
             final Map<UpdateComponent, UpdateCheckResult> res = new HashMap<>();
102 103
 
103
-            for (UpdateComponent component : components) {
104
-                if (Math.random() * components.size() < 10) {
105
-                    res.put(component, new FakeUpdateCheckResult(component));
106
-                }
107
-            }
104
+            components.stream().filter(component -> Math.random() * components.size() < 10)
105
+                    .forEach(component -> res.put(component, new FakeUpdateCheckResult(component)));
108 106
 
109 107
             return res;
110 108
         }

+ 2
- 4
identd/src/com/dmdirc/addons/identd/IdentdServer.java Переглянути файл

@@ -46,7 +46,7 @@ public final class IdentdServer implements Runnable {
46 46
     /** The event bus to post errors on. */
47 47
     private final DMDircMBassador eventBus;
48 48
     /** The Thread in use for this server */
49
-    private volatile Thread myThread = null;
49
+    private volatile Thread myThread;
50 50
     /** The current socket in use for this server */
51 51
     private ServerSocket serverSocket;
52 52
     /** Arraylist of all the clients we have */
@@ -173,9 +173,7 @@ public final class IdentdServer implements Runnable {
173 173
             }
174 174
 
175 175
             synchronized (clientList) {
176
-                for (IdentClient aClientList : clientList) {
177
-                    aClientList.close();
178
-                }
176
+                clientList.forEach(IdentClient::close);
179 177
                 clientList.clear();
180 178
             }
181 179
         }

+ 15
- 23
nickcolours/src/com/dmdirc/addons/nickcolours/NickColourManager.java Переглянути файл

@@ -29,6 +29,7 @@ import com.dmdirc.events.ChannelGotnamesEvent;
29 29
 import com.dmdirc.events.ChannelJoinEvent;
30 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31 31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
32
+import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
32 33
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
33 34
 import com.dmdirc.parser.interfaces.ChannelInfo;
34 35
 import com.dmdirc.parser.interfaces.ClientInfo;
@@ -37,6 +38,7 @@ import com.dmdirc.util.colours.Colour;
37 38
 import com.dmdirc.ui.messages.ColourManager;
38 39
 
39 40
 import java.util.ArrayList;
41
+import java.util.Collection;
40 42
 import java.util.List;
41 43
 import java.util.Map;
42 44
 
@@ -106,7 +108,7 @@ public class NickColourManager implements ConfigChangeListener {
106 108
         final ClientInfo myself = client.getClient().getParser().getLocalClient();
107 109
         final String nickOption1 = "color:"
108 110
                 + client.getClient().getParser().getStringConverter().
109
-                toLowerCase(network + ":" + client.getClient().getNickname());
111
+                toLowerCase(network + ':' + client.getClient().getNickname());
110 112
         final String nickOption2 = "color:"
111 113
                 + client.getClient().getParser().getStringConverter().
112 114
                 toLowerCase("*:" + client.getClient().getNickname());
@@ -129,11 +131,11 @@ public class NickColourManager implements ConfigChangeListener {
129 131
 
130 132
         if (parts != null) {
131 133
             Colour textColor = null;
132
-            Colour nickColor = null;
133 134
 
134 135
             if (parts[0] != null) {
135 136
                 textColor = colourManager.getColourFromString(parts[0], null);
136 137
             }
138
+            Colour nickColor = null;
137 139
             if (parts[1] != null) {
138 140
                 nickColor = colourManager.getColourFromString(parts[1], null);
139 141
             }
@@ -167,7 +169,7 @@ public class NickColourManager implements ConfigChangeListener {
167 169
      *
168 170
      * @return Colour of the specified nickname
169 171
      */
170
-    private Colour getColour(final String nick) {
172
+    private Colour getColour(final CharSequence nick) {
171 173
         int count = 0;
172 174
 
173 175
         for (int i = 0; i < nick.length(); i++) {
@@ -187,18 +189,17 @@ public class NickColourManager implements ConfigChangeListener {
187 189
      *
188 190
      * @return A multi-dimensional array of nick colour info.
189 191
      */
190
-    public static Object[][] getData(final AggregateConfigProvider config, final String domain) {
191
-        final List<Object[]> data = new ArrayList<>();
192
+    public static Object[][] getData(final ReadOnlyConfigProvider config, final String domain) {
193
+        final Collection<Object[]> data = new ArrayList<>();
192 194
 
193
-        for (String key : config.getOptions(domain).keySet()) {
194
-            if (key.startsWith("color:")) {
195
-                final String network = key.substring(6, key.indexOf(':', 6));
196
-                final String user = key.substring(1 + key.indexOf(':', 6));
197
-                final String[] parts = getParts(config, domain, key);
195
+        config.getOptions(domain).keySet().stream().filter(key -> key.startsWith("color:"))
196
+                .forEach(key -> {
197
+                    final String network = key.substring(6, key.indexOf(':', 6));
198
+                    final String user = key.substring(1 + key.indexOf(':', 6));
199
+                    final String[] parts = getParts(config, domain, key);
198 200
 
199
-                data.add(new Object[]{network, user, parts[0], parts[1]});
200
-            }
201
-        }
201
+                    data.add(new Object[]{network, user, parts[0], parts[1]});
202
+                });
202 203
 
203 204
         final Object[][] res = new Object[data.size()][4];
204 205
 
@@ -222,7 +223,7 @@ public class NickColourManager implements ConfigChangeListener {
222 223
      *
223 224
      * @return The colours specified by the given key
224 225
      */
225
-    private static String[] getParts(final AggregateConfigProvider config, final String domain,
226
+    private static String[] getParts(final ReadOnlyConfigProvider config, final String domain,
226 227
             final String key) {
227 228
         String[] parts = config.getOption(domain, key).split(":");
228 229
 
@@ -270,13 +271,4 @@ public class NickColourManager implements ConfigChangeListener {
270 271
         setCachedSettings();
271 272
     }
272 273
 
273
-    /**
274
-     * Returns this plugin's settings domain.
275
-     *
276
-     * @return Settings domain
277
-     */
278
-    public String getDomain() {
279
-        return domain;
280
-    }
281
-
282 274
 }

+ 9
- 9
notifications/src/com/dmdirc/addons/notifications/NotificationCommand.java Переглянути файл

@@ -35,6 +35,7 @@ import com.dmdirc.plugins.PluginInfo;
35 35
 import com.dmdirc.ui.input.AdditionalTabTargets;
36 36
 
37 37
 import java.util.List;
38
+import java.util.stream.Collectors;
38 39
 
39 40
 import javax.annotation.Nonnull;
40 41
 
@@ -70,11 +71,11 @@ public class NotificationCommand extends Command implements
70 71
     @Override
71 72
     public void execute(@Nonnull final FrameContainer origin,
72 73
             final CommandArguments args, final CommandContext context) {
73
-        if (args.getArguments().length > 0 && args.getArguments()[0]
74
-                .equalsIgnoreCase("--methods")) {
74
+        if (args.getArguments().length > 0 &&
75
+                "--methods".equalsIgnoreCase(args.getArguments()[0])) {
75 76
             doMethodList(origin, args.isSilent());
76
-        } else if (args.getArguments().length > 0 && args.getArguments()[0]
77
-                .equalsIgnoreCase("--method")) {
77
+        } else if (args.getArguments().length > 0 &&
78
+                "--method".equalsIgnoreCase(args.getArguments()[0])) {
78 79
             if (args.getArguments().length > 1) {
79 80
                 final String sourceName = args.getArguments()[1];
80 81
                 final ExportedService source = manager.getMethod(sourceName)
@@ -134,11 +135,10 @@ public class NotificationCommand extends Command implements
134 135
             res.add("--methods");
135 136
             res.add("--method");
136 137
             return res;
137
-        } else if (arg == 1 && context.getPreviousArgs().get(0)
138
-                .equalsIgnoreCase("--method")) {
139
-            for (PluginInfo source : manager.getMethods()) {
140
-                res.add(source.getMetaData().getName());
141
-            }
138
+        } else if (arg == 1 && "--method".equalsIgnoreCase(context.getPreviousArgs().get(0))) {
139
+            res.addAll(manager.getMethods().stream()
140
+                    .map(source -> source.getMetaData().getName())
141
+                    .collect(Collectors.toList()));
142 142
             return res;
143 143
         }
144 144
         return res;

+ 5
- 6
notifications/src/com/dmdirc/addons/notifications/NotificationsManager.java Переглянути файл

@@ -32,6 +32,7 @@ import com.dmdirc.plugins.PluginInfo;
32 32
 import com.dmdirc.plugins.PluginManager;
33 33
 
34 34
 import java.util.ArrayList;
35
+import java.util.Collection;
35 36
 import java.util.List;
36 37
 
37 38
 import javax.inject.Inject;
@@ -41,7 +42,7 @@ import net.engio.mbassy.listener.Handler;
41 42
 public class NotificationsManager {
42 43
 
43 44
     /** The notification methods that we know of. */
44
-    private final List<String> methods = new ArrayList<>();
45
+    private final Collection<String> methods = new ArrayList<>();
45 46
     /** The user's preferred order for method usage. */
46 47
     private List<String> order;
47 48
     /** This plugin's settings domain. */
@@ -67,11 +68,9 @@ public class NotificationsManager {
67 68
         methods.clear();
68 69
         loadSettings();
69 70
         eventBus.subscribe(this);
70
-        for (PluginInfo target : pluginManager.getPluginInfos()) {
71
-            if (target.isLoaded()) {
72
-                addPlugin(target);
73
-            }
74
-        }
71
+        pluginManager.getPluginInfos().stream()
72
+                .filter(PluginInfo::isLoaded)
73
+                .forEach(this::addPlugin);
75 74
     }
76 75
 
77 76
     public void onUnload() {

+ 9
- 10
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java Переглянути файл

@@ -39,6 +39,7 @@ import com.dmdirc.ui.input.TabCompleterUtils;
39 39
 
40 40
 import java.util.Arrays;
41 41
 import java.util.List;
42
+import java.util.stream.Collectors;
42 43
 
43 44
 import javax.annotation.Nonnull;
44 45
 import javax.inject.Inject;
@@ -89,10 +90,10 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
89 90
             final CommandArguments args, final CommandContext context) {
90 91
         final FrameContainer target = ((ChatCommandContext) context).getChat();
91 92
         if (args.getArguments().length > 0
92
-                && args.getArguments()[0].equalsIgnoreCase("--sources")) {
93
+                && "--sources".equalsIgnoreCase(args.getArguments()[0])) {
93 94
             doSourceList(origin, args.isSilent(), args.getArgumentsAsString(1));
94 95
         } else if (args.getArguments().length > 0
95
-                && args.getArguments()[0].equalsIgnoreCase("--source")) {
96
+                && "--source".equalsIgnoreCase(args.getArguments()[0])) {
96 97
             if (args.getArguments().length > 1) {
97 98
                 final String sourceName = args.getArguments()[1];
98 99
                 final MediaSource source = manager.getSource(sourceName);
@@ -189,16 +190,14 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
189 190
             res.add("--source");
190 191
             res.addAll(subsList);
191 192
             return res;
192
-        } else if (arg == 1 && context.getPreviousArgs().get(0).equalsIgnoreCase("--source")) {
193
+        } else if (arg == 1 && "--source".equalsIgnoreCase(context.getPreviousArgs().get(0))) {
193 194
             final AdditionalTabTargets res = new AdditionalTabTargets();
194 195
             res.excludeAll();
195
-            for (MediaSource source : manager.getSources()) {
196
-                if (source.getState() != MediaSourceState.CLOSED) {
197
-                    res.add(source.getAppName());
198
-                }
199
-            }
196
+            res.addAll(manager.getSources().stream()
197
+                    .filter(source -> source.getState() != MediaSourceState.CLOSED)
198
+                    .map(MediaSource::getAppName).collect(Collectors.toList()));
200 199
             return res;
201
-        } else if (arg > 1 && context.getPreviousArgs().get(0).equalsIgnoreCase("--source")) {
200
+        } else if (arg > 1 && "--source".equalsIgnoreCase(context.getPreviousArgs().get(0))) {
202 201
             final AdditionalTabTargets res = tabCompleterUtils
203 202
                     .getIntelligentResults(arg, context, 2);
204 203
             res.addAll(subsList);
@@ -206,7 +205,7 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
206 205
         } else {
207 206
             final AdditionalTabTargets res = tabCompleterUtils
208 207
                     .getIntelligentResults(arg, context,
209
-                            context.getPreviousArgs().get(0).equalsIgnoreCase("--sources") ? 1 : 0);
208
+                            "--sources".equalsIgnoreCase(context.getPreviousArgs().get(0)) ? 1 : 0);
210 209
             res.addAll(subsList);
211 210
             return res;
212 211
         }

+ 7
- 10
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingManager.java Переглянути файл

@@ -33,6 +33,7 @@ import com.dmdirc.plugins.PluginInfo;
33 33
 import com.dmdirc.plugins.PluginManager;
34 34
 
35 35
 import java.util.ArrayList;
36
+import java.util.Collection;
36 37
 import java.util.Collections;
37 38
 import java.util.List;
38 39
 
@@ -53,7 +54,7 @@ public class NowPlayingManager {
53 54
     /** The sources that we know of. */
54 55
     private final List<MediaSource> sources = new ArrayList<>();
55 56
     /** The managers that we know of. */
56
-    private final List<MediaSourceManager> managers = new ArrayList<>();
57
+    private final Collection<MediaSourceManager> managers = new ArrayList<>();
57 58
     /** The user's preferred order for source usage. */
58 59
     private List<String> order;
59 60
 
@@ -75,11 +76,9 @@ public class NowPlayingManager {
75 76
         managers.clear();
76 77
         order = getSettings();
77 78
         eventBus.subscribe(this);
78
-        for (PluginInfo target : pluginManager.getPluginInfos()) {
79
-            if (target.isLoaded()) {
80
-                addPlugin(target);
81
-            }
82
-        }
79
+        pluginManager.getPluginInfos().stream()
80
+                .filter(PluginInfo::isLoaded)
81
+                .forEach(this::addPlugin);
83 82
     }
84 83
 
85 84
     /**
@@ -131,9 +130,7 @@ public class NowPlayingManager {
131 130
             managers.add((MediaSourceManager) targetPlugin);
132 131
 
133 132
             if (((MediaSourceManager) targetPlugin).getSources() != null) {
134
-                for (MediaSource source : ((MediaSourceManager) targetPlugin).getSources()) {
135
-                    addSourceToOrder(source);
136
-                }
133
+                ((MediaSourceManager) targetPlugin).getSources().forEach(this::addSourceToOrder);
137 134
             }
138 135
         }
139 136
     }
@@ -191,11 +188,11 @@ public class NowPlayingManager {
191 188
      * @return The best source to use for media info
192 189
      */
193 190
     public MediaSource getBestSource() {
194
-        MediaSource paused = null;
195 191
         final List<MediaSource> possibleSources = getSources();
196 192
 
197 193
         Collections.sort(possibleSources, new MediaSourceComparator(order));
198 194
 
195
+        MediaSource paused = null;
199 196
         for (final MediaSource source : possibleSources) {
200 197
             if (source.getState() != MediaSourceState.CLOSED) {
201 198
                 if (source.getState() == MediaSourceState.PLAYING) {

+ 5
- 6
parser_xmpp/src/com/dmdirc/addons/parser_xmpp/FixedXmppConnection.java Переглянути файл

@@ -87,12 +87,11 @@ public class FixedXmppConnection extends XMPPConnection
87 87
         new ServiceDiscoveryManager(xmppc);
88 88
 
89 89
         // Now execute our real listeners
90
-        for (ConnectionCreationListener listener : oldListeners) {
91
-            // We've already created a discovery manager, don't make another...
92
-            if (!ServiceDiscoveryManager.class.equals(listener.getClass().getEnclosingClass())) {
93
-                listener.connectionCreated(xmppc);
94
-            }
95
-        }
90
+        // We've already created a discovery manager, don't make another...
91
+        oldListeners.stream()
92
+                .filter(listener -> !ServiceDiscoveryManager.class
93
+                        .equals(listener.getClass().getEnclosingClass()))
94
+                .forEach(listener -> listener.connectionCreated(xmppc));
96 95
     }
97 96
 
98 97
     /**

+ 3
- 8
parser_xmpp/src/com/dmdirc/addons/parser_xmpp/XmppParser.java Переглянути файл

@@ -460,14 +460,9 @@ public class XmppParser extends BaseSocketAwareParser {
460 460
                         onChannelSelfJoin(null, null, fakeChannel);
461 461
                 fakeChannel.updateContacts(contacts.values());
462 462
 
463
-                for (XmppClientInfo client : contacts.values()) {
464
-                    if (client.isAway()) {
465
-                        getCallback(OtherAwayStateListener.class)
466
-                                .onAwayStateOther(null, null, client,
467
-                                        AwayState.UNKNOWN,
468
-                                        AwayState.AWAY);
469
-                    }
470
-                }
463
+                contacts.values().stream().filter(XmppClientInfo::isAway).forEach(client ->
464
+                        getCallback(OtherAwayStateListener.class).onAwayStateOther(null, null,
465
+                                client, AwayState.UNKNOWN, AwayState.AWAY));
471 466
             }
472 467
         } catch (XMPPException ex) {
473 468
             LOG.debug("Go an XMPP exception", ex);

+ 15
- 17
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptCommand.java Переглянути файл

@@ -43,6 +43,7 @@ import java.io.FileNotFoundException;
43 43
 import java.io.FileWriter;
44 44
 import java.io.IOException;
45 45
 import java.util.Map;
46
+import java.util.stream.Collectors;
46 47
 
47 48
 import javax.annotation.Nonnull;
48 49
 import javax.inject.Inject;
@@ -103,28 +104,28 @@ public class ScriptCommand extends Command implements IntelligentCommand {
103 104
             final CommandContext context) {
104 105
         final String[] sargs = args.getArguments();
105 106
 
106
-        if (sargs.length > 0 && (sargs[0].equalsIgnoreCase("rehash") || sargs[0].equalsIgnoreCase(
107
-                "reload"))) {
107
+        if (sargs.length > 0 && ("rehash".equalsIgnoreCase(sargs[0]) ||
108
+                "reload".equalsIgnoreCase(sargs[0]))) {
108 109
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Reloading scripts");
109 110
             scriptManager.rehash();
110
-        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("load")) {
111
+        } else if (sargs.length > 0 && "load".equalsIgnoreCase(sargs[0])) {
111 112
             if (sargs.length > 1) {
112 113
                 final String filename = args.getArgumentsAsString(1);
113 114
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Loading: " + filename + " ["
114
-                        + scriptManager.loadScript(scriptDirectory + filename) + "]");
115
+                        + scriptManager.loadScript(scriptDirectory + filename) + ']');
115 116
             } else {
116 117
                 sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify a script to load");
117 118
             }
118
-        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("unload")) {
119
+        } else if (sargs.length > 0 && "unload".equalsIgnoreCase(sargs[0])) {
119 120
             if (sargs.length > 1) {
120 121
                 final String filename = args.getArgumentsAsString(1);
121 122
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Unloading: " + filename + " ["
122
-                        + scriptManager.loadScript(scriptDirectory + filename) + "]");
123
+                        + scriptManager.loadScript(scriptDirectory + filename) + ']');
123 124
             } else {
124 125
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
125 126
                         "You must specify a script to unload");
126 127
             }
127
-        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("eval")) {
128
+        } else if (sargs.length > 0 && "eval".equalsIgnoreCase(sargs[0])) {
128 129
             if (sargs.length > 1) {
129 130
                 final String script = args.getArgumentsAsString(1);
130 131
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Evaluating: " + script);
@@ -163,7 +164,7 @@ public class ScriptCommand extends Command implements IntelligentCommand {
163 164
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
164 165
                         "You must specify some script to eval.");
165 166
             }
166
-        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("savetobasefile")) {
167
+        } else if (sargs.length > 0 && "savetobasefile".equalsIgnoreCase(sargs[0])) {
167 168
             if (sargs.length > 2) {
168 169
                 final String[] bits = sargs[1].split("/");
169 170
                 final String functionName = bits[0];
@@ -203,7 +204,7 @@ public class ScriptCommand extends Command implements IntelligentCommand {
203 204
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
204 205
                         "You must specify a function name and some script to save.");
205 206
             }
206
-        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("help")) {
207
+        } else if (sargs.length > 0 && "help".equalsIgnoreCase(sargs[0])) {
207 208
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
208 209
                     "This command allows you to interact with the script plugin");
209 210
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
@@ -244,14 +245,11 @@ public class ScriptCommand extends Command implements IntelligentCommand {
244 245
             res.add("savetobasefile");
245 246
         } else if (arg == 1) {
246 247
             final Map<String, ScriptEngineWrapper> scripts = scriptManager.getScripts();
247
-            if (context.getPreviousArgs().get(0).equalsIgnoreCase("load")) {
248
-                for (String filename : scriptManager.getPossibleScripts()) {
249
-                    res.add(filename);
250
-                }
251
-            } else if (context.getPreviousArgs().get(0).equalsIgnoreCase("unload")) {
252
-                for (String filename : scripts.keySet()) {
253
-                    res.add(filename);
254
-                }
248
+            if ("load".equalsIgnoreCase(context.getPreviousArgs().get(0))) {
249
+                res.addAll(scriptManager.getPossibleScripts().stream()
250
+                        .collect(Collectors.toList()));
251
+            } else if ("unload".equalsIgnoreCase(context.getPreviousArgs().get(0))) {
252
+                res.addAll(scripts.keySet().stream().collect(Collectors.toList()));
255 253
             }
256 254
         }
257 255
 

+ 2
- 4
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptManager.java Переглянути файл

@@ -70,9 +70,7 @@ public class ScriptManager {
70 70
 
71 71
     /** Reload all scripts */
72 72
     public void rehash() {
73
-        for (final ScriptEngineWrapper engine : scripts.values()) {
74
-            engine.reload();
75
-        }
73
+        scripts.values().forEach(ScriptEngineWrapper::reload);
76 74
         // Advise the Garbage collector that now would be a good time to run
77 75
         System.gc();
78 76
     }
@@ -120,7 +118,7 @@ public class ScriptManager {
120 118
     public void unloadScript(final String scriptFilename) {
121 119
         if (scripts.containsKey(scriptFilename)) {
122 120
             // Tell it that its about to be unloaded.
123
-            (scripts.get(scriptFilename)).callFunction("onUnload");
121
+            scripts.get(scriptFilename).callFunction("onUnload");
124 122
             // Remove the script
125 123
             scripts.remove(scriptFilename);
126 124
             // Advise the Garbage collector that now would be a good time to run

+ 6
- 8
scriptplugin/src/com/dmdirc/addons/scriptplugin/TypedProperties.java Переглянути файл

@@ -62,15 +62,13 @@ public class TypedProperties extends Properties {
62 62
     public void setCaseSensitivity(final boolean value) {
63 63
         // Set all existing values to lowercase.
64 64
         if (!value) {
65
-            for (final Object property : keySet()) {
66
-                if (property instanceof String) {
67
-                    final String propertyName = (String) property;
68
-                    if (!propertyName.equals(propertyName.toLowerCase())) {
69
-                        super.setProperty(propertyName.toLowerCase(), getProperty(propertyName));
70
-                        super.remove(propertyName);
71
-                    }
65
+            keySet().stream().filter(property -> property instanceof String).forEach(property -> {
66
+                final String propertyName = (String) property;
67
+                if (!propertyName.equals(propertyName.toLowerCase())) {
68
+                    super.setProperty(propertyName.toLowerCase(), getProperty(propertyName));
69
+                    remove(propertyName);
72 70
                 }
73
-            }
71
+            });
74 72
         }
75 73
         caseSensitive = value;
76 74
     }

+ 1
- 3
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupSettingsPanel.java Переглянути файл

@@ -163,9 +163,7 @@ public final class ActionGroupSettingsPanel extends JPanel implements ActionList
163 163
      * Saves the changes to the settings.
164 164
      */
165 165
     public void save() {
166
-        for (PreferencesSetting setting : settings) {
167
-            setting.save();
168
-        }
166
+        settings.forEach(PreferencesSetting::save);
169 167
     }
170 168
 
171 169
     @Override

+ 3
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelListModesPane.java Переглянути файл

@@ -126,7 +126,7 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
126 126
         this.iconManager = checkNotNull(iconManager);
127 127
         this.channel = checkNotNull(channel);
128 128
         this.parentWindow = checkNotNull(parentWindow);
129
-        this.setOpaque(UIUtilities.getTabbedPaneOpaque());
129
+        setOpaque(UIUtilities.getTabbedPaneOpaque());
130 130
 
131 131
         list = new JList<>();
132 132
         nativeRenderer = list.getCellRenderer();
@@ -304,9 +304,8 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
304 304
     private void removeListMode() {
305 305
         final int selectedIndex = listModesMenu.getSelectedIndex();
306 306
         final JList<ChannelListModeItem> removeList = listModesPanels.get(selectedIndex);
307
-        for (ChannelListModeItem mode : removeList.getSelectedValuesList()) {
308
-            ((DefaultListModel<ChannelListModeItem>) removeList.getModel()).removeElement(mode);
309
-        }
307
+        removeList.getSelectedValuesList().forEach(
308
+                ((DefaultListModel<ChannelListModeItem>) removeList.getModel())::removeElement);
310 309
         updateModeCount();
311 310
     }
312 311
 

+ 4
- 6
ui_swing/src/com/dmdirc/addons/ui_swing/wizard/WizardPanel.java Переглянути файл

@@ -309,18 +309,16 @@ public class WizardPanel extends JPanel implements ActionListener {
309 309
      * Fires wizard finished events.
310 310
      */
311 311
     private void fireWizardFinished() {
312
-        for (WizardListener listener : stepListeners.get(WizardListener.class)) {
313
-            listener.wizardFinished();
314
-        }
312
+        stepListeners.get(WizardListener.class)
313
+                .forEach(WizardListener::wizardFinished);
315 314
     }
316 315
 
317 316
     /**
318 317
      * Fires wizard cancelled events.
319 318
      */
320 319
     protected void fireWizardCancelled() {
321
-        for (WizardListener listener : stepListeners.get(WizardListener.class)) {
322
-            listener.wizardCancelled();
323
-        }
320
+        stepListeners.get(WizardListener.class)
321
+                .forEach(WizardListener::wizardCancelled);
324 322
     }
325 323
 
326 324
 }

Завантаження…
Відмінити
Зберегти