Browse Source

Use forEach where possible.

pull/194/head
Chris Smith 9 years ago
parent
commit
e13dffc526

+ 3
- 5
calc/src/com/dmdirc/addons/calc/Parser.java View File

28
 import java.util.Collections;
28
 import java.util.Collections;
29
 import java.util.Comparator;
29
 import java.util.Comparator;
30
 import java.util.List;
30
 import java.util.List;
31
+import java.util.stream.Collectors;
31
 
32
 
32
 /**
33
 /**
33
  * The parser takes the output from a {@link Lexer} and applies precedence rules to build the tokens
34
  * The parser takes the output from a {@link Lexer} and applies precedence rules to build the tokens
62
      *                        involving a mis-matched bracket).
63
      *                        involving a mis-matched bracket).
63
      */
64
      */
64
     public TreeToken parse() throws ParseException {
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
         return parse(tokens);
69
         return parse(tokens);
72
     }
70
     }

+ 1
- 3
contactlist/src/com/dmdirc/addons/contactlist/ContactListListener.java View File

73
 
73
 
74
     @Override
74
     @Override
75
     public void clientListUpdated(final Collection<ChannelClientInfo> clients) {
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
     @Override
79
     @Override

+ 6
- 5
debug/src/com/dmdirc/addons/debug/Debug.java View File

39
 import java.util.List;
39
 import java.util.List;
40
 import java.util.Map;
40
 import java.util.Map;
41
 import java.util.Set;
41
 import java.util.Set;
42
+import java.util.stream.Collectors;
42
 
43
 
43
 import javax.annotation.Nonnull;
44
 import javax.annotation.Nonnull;
44
 import javax.inject.Inject;
45
 import javax.inject.Inject;
94
                 final CommandArguments newArgs = new CommandArguments(
95
                 final CommandArguments newArgs = new CommandArguments(
95
                         controller,
96
                         controller,
96
                         Arrays.asList((controller.getCommandChar()
97
                         Arrays.asList((controller.getCommandChar()
97
-                                + command.getName() + " "
98
+                                + command.getName() + ' '
98
                                 + args.getArgumentsAsString(1)).split(" ")));
99
                                 + args.getArgumentsAsString(1)).split(" ")));
99
                 command.execute(origin, newArgs, context);
100
                 command.execute(origin, newArgs, context);
100
             }
101
             }
124
      */
125
      */
125
     public void proxyShowUsage(final FrameContainer target,
126
     public void proxyShowUsage(final FrameContainer target,
126
             final boolean isSilent, final String name, final String args) {
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
     public List<String> getCommandNames() {
149
     public List<String> getCommandNames() {
149
         final List<String> names = new ArrayList<>(commands.size());
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
         return names;
156
         return names;
156
     }
157
     }

+ 4
- 6
debug/src/com/dmdirc/addons/debug/commands/FakeUpdates.java View File

45
 import java.util.HashMap;
45
 import java.util.HashMap;
46
 import java.util.Map;
46
 import java.util.Map;
47
 
47
 
48
+import javax.annotation.Nonnull;
48
 import javax.inject.Inject;
49
 import javax.inject.Inject;
49
 import javax.inject.Provider;
50
 import javax.inject.Provider;
50
 
51
 
82
     }
83
     }
83
 
84
 
84
     @Override
85
     @Override
85
-    public void execute(final FrameContainer origin,
86
+    public void execute(@Nonnull final FrameContainer origin,
86
             final CommandArguments args, final CommandContext context) {
87
             final CommandArguments args, final CommandContext context) {
87
         updateManager.addCheckStrategy(new FakeUpdateCheckStrategy());
88
         updateManager.addCheckStrategy(new FakeUpdateCheckStrategy());
88
         updateManager.addRetrievalStrategy(new FakeUpdateRetriever());
89
         updateManager.addRetrievalStrategy(new FakeUpdateRetriever());
100
                 final Collection<UpdateComponent> components) {
101
                 final Collection<UpdateComponent> components) {
101
             final Map<UpdateComponent, UpdateCheckResult> res = new HashMap<>();
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
             return res;
107
             return res;
110
         }
108
         }

+ 2
- 4
identd/src/com/dmdirc/addons/identd/IdentdServer.java View File

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

+ 15
- 23
nickcolours/src/com/dmdirc/addons/nickcolours/NickColourManager.java View File

29
 import com.dmdirc.events.ChannelJoinEvent;
29
 import com.dmdirc.events.ChannelJoinEvent;
30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
32
+import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
32
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
33
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
33
 import com.dmdirc.parser.interfaces.ChannelInfo;
34
 import com.dmdirc.parser.interfaces.ChannelInfo;
34
 import com.dmdirc.parser.interfaces.ClientInfo;
35
 import com.dmdirc.parser.interfaces.ClientInfo;
37
 import com.dmdirc.ui.messages.ColourManager;
38
 import com.dmdirc.ui.messages.ColourManager;
38
 
39
 
39
 import java.util.ArrayList;
40
 import java.util.ArrayList;
41
+import java.util.Collection;
40
 import java.util.List;
42
 import java.util.List;
41
 import java.util.Map;
43
 import java.util.Map;
42
 
44
 
106
         final ClientInfo myself = client.getClient().getParser().getLocalClient();
108
         final ClientInfo myself = client.getClient().getParser().getLocalClient();
107
         final String nickOption1 = "color:"
109
         final String nickOption1 = "color:"
108
                 + client.getClient().getParser().getStringConverter().
110
                 + client.getClient().getParser().getStringConverter().
109
-                toLowerCase(network + ":" + client.getClient().getNickname());
111
+                toLowerCase(network + ':' + client.getClient().getNickname());
110
         final String nickOption2 = "color:"
112
         final String nickOption2 = "color:"
111
                 + client.getClient().getParser().getStringConverter().
113
                 + client.getClient().getParser().getStringConverter().
112
                 toLowerCase("*:" + client.getClient().getNickname());
114
                 toLowerCase("*:" + client.getClient().getNickname());
129
 
131
 
130
         if (parts != null) {
132
         if (parts != null) {
131
             Colour textColor = null;
133
             Colour textColor = null;
132
-            Colour nickColor = null;
133
 
134
 
134
             if (parts[0] != null) {
135
             if (parts[0] != null) {
135
                 textColor = colourManager.getColourFromString(parts[0], null);
136
                 textColor = colourManager.getColourFromString(parts[0], null);
136
             }
137
             }
138
+            Colour nickColor = null;
137
             if (parts[1] != null) {
139
             if (parts[1] != null) {
138
                 nickColor = colourManager.getColourFromString(parts[1], null);
140
                 nickColor = colourManager.getColourFromString(parts[1], null);
139
             }
141
             }
167
      *
169
      *
168
      * @return Colour of the specified nickname
170
      * @return Colour of the specified nickname
169
      */
171
      */
170
-    private Colour getColour(final String nick) {
172
+    private Colour getColour(final CharSequence nick) {
171
         int count = 0;
173
         int count = 0;
172
 
174
 
173
         for (int i = 0; i < nick.length(); i++) {
175
         for (int i = 0; i < nick.length(); i++) {
187
      *
189
      *
188
      * @return A multi-dimensional array of nick colour info.
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
         final Object[][] res = new Object[data.size()][4];
204
         final Object[][] res = new Object[data.size()][4];
204
 
205
 
222
      *
223
      *
223
      * @return The colours specified by the given key
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
             final String key) {
227
             final String key) {
227
         String[] parts = config.getOption(domain, key).split(":");
228
         String[] parts = config.getOption(domain, key).split(":");
228
 
229
 
270
         setCachedSettings();
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 View File

35
 import com.dmdirc.ui.input.AdditionalTabTargets;
35
 import com.dmdirc.ui.input.AdditionalTabTargets;
36
 
36
 
37
 import java.util.List;
37
 import java.util.List;
38
+import java.util.stream.Collectors;
38
 
39
 
39
 import javax.annotation.Nonnull;
40
 import javax.annotation.Nonnull;
40
 
41
 
70
     @Override
71
     @Override
71
     public void execute(@Nonnull final FrameContainer origin,
72
     public void execute(@Nonnull final FrameContainer origin,
72
             final CommandArguments args, final CommandContext context) {
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
             doMethodList(origin, args.isSilent());
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
             if (args.getArguments().length > 1) {
79
             if (args.getArguments().length > 1) {
79
                 final String sourceName = args.getArguments()[1];
80
                 final String sourceName = args.getArguments()[1];
80
                 final ExportedService source = manager.getMethod(sourceName)
81
                 final ExportedService source = manager.getMethod(sourceName)
134
             res.add("--methods");
135
             res.add("--methods");
135
             res.add("--method");
136
             res.add("--method");
136
             return res;
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
             return res;
142
             return res;
143
         }
143
         }
144
         return res;
144
         return res;

+ 5
- 6
notifications/src/com/dmdirc/addons/notifications/NotificationsManager.java View File

32
 import com.dmdirc.plugins.PluginManager;
32
 import com.dmdirc.plugins.PluginManager;
33
 
33
 
34
 import java.util.ArrayList;
34
 import java.util.ArrayList;
35
+import java.util.Collection;
35
 import java.util.List;
36
 import java.util.List;
36
 
37
 
37
 import javax.inject.Inject;
38
 import javax.inject.Inject;
41
 public class NotificationsManager {
42
 public class NotificationsManager {
42
 
43
 
43
     /** The notification methods that we know of. */
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
     /** The user's preferred order for method usage. */
46
     /** The user's preferred order for method usage. */
46
     private List<String> order;
47
     private List<String> order;
47
     /** This plugin's settings domain. */
48
     /** This plugin's settings domain. */
67
         methods.clear();
68
         methods.clear();
68
         loadSettings();
69
         loadSettings();
69
         eventBus.subscribe(this);
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
     public void onUnload() {
76
     public void onUnload() {

+ 9
- 10
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java View File

39
 
39
 
40
 import java.util.Arrays;
40
 import java.util.Arrays;
41
 import java.util.List;
41
 import java.util.List;
42
+import java.util.stream.Collectors;
42
 
43
 
43
 import javax.annotation.Nonnull;
44
 import javax.annotation.Nonnull;
44
 import javax.inject.Inject;
45
 import javax.inject.Inject;
89
             final CommandArguments args, final CommandContext context) {
90
             final CommandArguments args, final CommandContext context) {
90
         final FrameContainer target = ((ChatCommandContext) context).getChat();
91
         final FrameContainer target = ((ChatCommandContext) context).getChat();
91
         if (args.getArguments().length > 0
92
         if (args.getArguments().length > 0
92
-                && args.getArguments()[0].equalsIgnoreCase("--sources")) {
93
+                && "--sources".equalsIgnoreCase(args.getArguments()[0])) {
93
             doSourceList(origin, args.isSilent(), args.getArgumentsAsString(1));
94
             doSourceList(origin, args.isSilent(), args.getArgumentsAsString(1));
94
         } else if (args.getArguments().length > 0
95
         } else if (args.getArguments().length > 0
95
-                && args.getArguments()[0].equalsIgnoreCase("--source")) {
96
+                && "--source".equalsIgnoreCase(args.getArguments()[0])) {
96
             if (args.getArguments().length > 1) {
97
             if (args.getArguments().length > 1) {
97
                 final String sourceName = args.getArguments()[1];
98
                 final String sourceName = args.getArguments()[1];
98
                 final MediaSource source = manager.getSource(sourceName);
99
                 final MediaSource source = manager.getSource(sourceName);
189
             res.add("--source");
190
             res.add("--source");
190
             res.addAll(subsList);
191
             res.addAll(subsList);
191
             return res;
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
             final AdditionalTabTargets res = new AdditionalTabTargets();
194
             final AdditionalTabTargets res = new AdditionalTabTargets();
194
             res.excludeAll();
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
             return res;
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
             final AdditionalTabTargets res = tabCompleterUtils
201
             final AdditionalTabTargets res = tabCompleterUtils
203
                     .getIntelligentResults(arg, context, 2);
202
                     .getIntelligentResults(arg, context, 2);
204
             res.addAll(subsList);
203
             res.addAll(subsList);
206
         } else {
205
         } else {
207
             final AdditionalTabTargets res = tabCompleterUtils
206
             final AdditionalTabTargets res = tabCompleterUtils
208
                     .getIntelligentResults(arg, context,
207
                     .getIntelligentResults(arg, context,
209
-                            context.getPreviousArgs().get(0).equalsIgnoreCase("--sources") ? 1 : 0);
208
+                            "--sources".equalsIgnoreCase(context.getPreviousArgs().get(0)) ? 1 : 0);
210
             res.addAll(subsList);
209
             res.addAll(subsList);
211
             return res;
210
             return res;
212
         }
211
         }

+ 7
- 10
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingManager.java View File

33
 import com.dmdirc.plugins.PluginManager;
33
 import com.dmdirc.plugins.PluginManager;
34
 
34
 
35
 import java.util.ArrayList;
35
 import java.util.ArrayList;
36
+import java.util.Collection;
36
 import java.util.Collections;
37
 import java.util.Collections;
37
 import java.util.List;
38
 import java.util.List;
38
 
39
 
53
     /** The sources that we know of. */
54
     /** The sources that we know of. */
54
     private final List<MediaSource> sources = new ArrayList<>();
55
     private final List<MediaSource> sources = new ArrayList<>();
55
     /** The managers that we know of. */
56
     /** The managers that we know of. */
56
-    private final List<MediaSourceManager> managers = new ArrayList<>();
57
+    private final Collection<MediaSourceManager> managers = new ArrayList<>();
57
     /** The user's preferred order for source usage. */
58
     /** The user's preferred order for source usage. */
58
     private List<String> order;
59
     private List<String> order;
59
 
60
 
75
         managers.clear();
76
         managers.clear();
76
         order = getSettings();
77
         order = getSettings();
77
         eventBus.subscribe(this);
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
             managers.add((MediaSourceManager) targetPlugin);
130
             managers.add((MediaSourceManager) targetPlugin);
132
 
131
 
133
             if (((MediaSourceManager) targetPlugin).getSources() != null) {
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
      * @return The best source to use for media info
188
      * @return The best source to use for media info
192
      */
189
      */
193
     public MediaSource getBestSource() {
190
     public MediaSource getBestSource() {
194
-        MediaSource paused = null;
195
         final List<MediaSource> possibleSources = getSources();
191
         final List<MediaSource> possibleSources = getSources();
196
 
192
 
197
         Collections.sort(possibleSources, new MediaSourceComparator(order));
193
         Collections.sort(possibleSources, new MediaSourceComparator(order));
198
 
194
 
195
+        MediaSource paused = null;
199
         for (final MediaSource source : possibleSources) {
196
         for (final MediaSource source : possibleSources) {
200
             if (source.getState() != MediaSourceState.CLOSED) {
197
             if (source.getState() != MediaSourceState.CLOSED) {
201
                 if (source.getState() == MediaSourceState.PLAYING) {
198
                 if (source.getState() == MediaSourceState.PLAYING) {

+ 5
- 6
parser_xmpp/src/com/dmdirc/addons/parser_xmpp/FixedXmppConnection.java View File

87
         new ServiceDiscoveryManager(xmppc);
87
         new ServiceDiscoveryManager(xmppc);
88
 
88
 
89
         // Now execute our real listeners
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 View File

460
                         onChannelSelfJoin(null, null, fakeChannel);
460
                         onChannelSelfJoin(null, null, fakeChannel);
461
                 fakeChannel.updateContacts(contacts.values());
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
         } catch (XMPPException ex) {
467
         } catch (XMPPException ex) {
473
             LOG.debug("Go an XMPP exception", ex);
468
             LOG.debug("Go an XMPP exception", ex);

+ 15
- 17
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptCommand.java View File

43
 import java.io.FileWriter;
43
 import java.io.FileWriter;
44
 import java.io.IOException;
44
 import java.io.IOException;
45
 import java.util.Map;
45
 import java.util.Map;
46
+import java.util.stream.Collectors;
46
 
47
 
47
 import javax.annotation.Nonnull;
48
 import javax.annotation.Nonnull;
48
 import javax.inject.Inject;
49
 import javax.inject.Inject;
103
             final CommandContext context) {
104
             final CommandContext context) {
104
         final String[] sargs = args.getArguments();
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
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Reloading scripts");
109
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Reloading scripts");
109
             scriptManager.rehash();
110
             scriptManager.rehash();
110
-        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("load")) {
111
+        } else if (sargs.length > 0 && "load".equalsIgnoreCase(sargs[0])) {
111
             if (sargs.length > 1) {
112
             if (sargs.length > 1) {
112
                 final String filename = args.getArgumentsAsString(1);
113
                 final String filename = args.getArgumentsAsString(1);
113
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Loading: " + filename + " ["
114
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Loading: " + filename + " ["
114
-                        + scriptManager.loadScript(scriptDirectory + filename) + "]");
115
+                        + scriptManager.loadScript(scriptDirectory + filename) + ']');
115
             } else {
116
             } else {
116
                 sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify a script to load");
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
             if (sargs.length > 1) {
120
             if (sargs.length > 1) {
120
                 final String filename = args.getArgumentsAsString(1);
121
                 final String filename = args.getArgumentsAsString(1);
121
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Unloading: " + filename + " ["
122
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Unloading: " + filename + " ["
122
-                        + scriptManager.loadScript(scriptDirectory + filename) + "]");
123
+                        + scriptManager.loadScript(scriptDirectory + filename) + ']');
123
             } else {
124
             } else {
124
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
125
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
125
                         "You must specify a script to unload");
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
             if (sargs.length > 1) {
129
             if (sargs.length > 1) {
129
                 final String script = args.getArgumentsAsString(1);
130
                 final String script = args.getArgumentsAsString(1);
130
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Evaluating: " + script);
131
                 sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Evaluating: " + script);
163
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
164
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
164
                         "You must specify some script to eval.");
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
             if (sargs.length > 2) {
168
             if (sargs.length > 2) {
168
                 final String[] bits = sargs[1].split("/");
169
                 final String[] bits = sargs[1].split("/");
169
                 final String functionName = bits[0];
170
                 final String functionName = bits[0];
203
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
204
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
204
                         "You must specify a function name and some script to save.");
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
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
208
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
208
                     "This command allows you to interact with the script plugin");
209
                     "This command allows you to interact with the script plugin");
209
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
210
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
244
             res.add("savetobasefile");
245
             res.add("savetobasefile");
245
         } else if (arg == 1) {
246
         } else if (arg == 1) {
246
             final Map<String, ScriptEngineWrapper> scripts = scriptManager.getScripts();
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 View File

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

+ 6
- 8
scriptplugin/src/com/dmdirc/addons/scriptplugin/TypedProperties.java View File

62
     public void setCaseSensitivity(final boolean value) {
62
     public void setCaseSensitivity(final boolean value) {
63
         // Set all existing values to lowercase.
63
         // Set all existing values to lowercase.
64
         if (!value) {
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
         caseSensitive = value;
73
         caseSensitive = value;
76
     }
74
     }

+ 1
- 3
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupSettingsPanel.java View File

163
      * Saves the changes to the settings.
163
      * Saves the changes to the settings.
164
      */
164
      */
165
     public void save() {
165
     public void save() {
166
-        for (PreferencesSetting setting : settings) {
167
-            setting.save();
168
-        }
166
+        settings.forEach(PreferencesSetting::save);
169
     }
167
     }
170
 
168
 
171
     @Override
169
     @Override

+ 3
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelListModesPane.java View File

126
         this.iconManager = checkNotNull(iconManager);
126
         this.iconManager = checkNotNull(iconManager);
127
         this.channel = checkNotNull(channel);
127
         this.channel = checkNotNull(channel);
128
         this.parentWindow = checkNotNull(parentWindow);
128
         this.parentWindow = checkNotNull(parentWindow);
129
-        this.setOpaque(UIUtilities.getTabbedPaneOpaque());
129
+        setOpaque(UIUtilities.getTabbedPaneOpaque());
130
 
130
 
131
         list = new JList<>();
131
         list = new JList<>();
132
         nativeRenderer = list.getCellRenderer();
132
         nativeRenderer = list.getCellRenderer();
304
     private void removeListMode() {
304
     private void removeListMode() {
305
         final int selectedIndex = listModesMenu.getSelectedIndex();
305
         final int selectedIndex = listModesMenu.getSelectedIndex();
306
         final JList<ChannelListModeItem> removeList = listModesPanels.get(selectedIndex);
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
         updateModeCount();
309
         updateModeCount();
311
     }
310
     }
312
 
311
 

+ 4
- 6
ui_swing/src/com/dmdirc/addons/ui_swing/wizard/WizardPanel.java View File

309
      * Fires wizard finished events.
309
      * Fires wizard finished events.
310
      */
310
      */
311
     private void fireWizardFinished() {
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
      * Fires wizard cancelled events.
317
      * Fires wizard cancelled events.
319
      */
318
      */
320
     protected void fireWizardCancelled() {
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
 }

Loading…
Cancel
Save