Browse Source

Tidy up some more getConnection calls.

pull/163/head
Chris Smith 9 years ago
parent
commit
bd7182d434

+ 2
- 1
logging/src/com/dmdirc/addons/logging/HistoryWindow.java View File

@@ -76,13 +76,14 @@ public class HistoryWindow extends FrameContainer {
76 76
     }
77 77
 
78 78
     @Override
79
+    @Deprecated
79 80
     public Connection getConnection() {
80 81
         return getParent().map(FrameContainer::getConnection).orElse(null);
81 82
     }
82 83
 
83 84
     @Override
84 85
     public Optional<Connection> getOptionalConnection() {
85
-        return getParent().map(FrameContainer::getConnection);
86
+        return getParent().flatMap(FrameContainer::getOptionalConnection);
86 87
     }
87 88
 
88 89
 }

+ 3
- 3
logging/src/com/dmdirc/addons/logging/LoggingManager.java View File

@@ -218,7 +218,7 @@ public class LoggingManager implements ConfigChangeListener {
218 218
 
219 219
     @Handler
220 220
     public void handleQueryOpened(final QueryOpenedEvent event) {
221
-        final Parser parser = event.getQuery().getConnection().getParser();
221
+        final Parser parser = event.getQuery().getOptionalConnection().get().getParser();
222 222
         final ClientInfo client = parser.getClient(event.getQuery().getHost());
223 223
         final String filename = getLogFile(client);
224 224
         if (autobackbuffer) {
@@ -234,7 +234,7 @@ public class LoggingManager implements ConfigChangeListener {
234 234
 
235 235
     @Handler
236 236
     public void handleQueryClosed(final QueryClosedEvent event) {
237
-        final Parser parser = event.getQuery().getConnection().getParser();
237
+        final Parser parser = event.getQuery().getOptionalConnection().get().getParser();
238 238
         final ClientInfo client = parser.getClient(event.getQuery().getHost());
239 239
         final String filename = getLogFile(client);
240 240
 
@@ -764,7 +764,7 @@ public class LoggingManager implements ConfigChangeListener {
764 764
         if (target instanceof Channel) {
765 765
             descriptor = target.getName();
766 766
         } else if (target instanceof Query) {
767
-            final Parser parser = target.getConnection().getParser();
767
+            final Parser parser = target.getOptionalConnection().get().getParser();
768 768
             descriptor = parser.getClient(((PrivateChat) target).getHost()).getNickname();
769 769
         } else {
770 770
             // Unknown component

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

@@ -60,7 +60,7 @@ public class NickColourManager implements ConfigChangeListener {
60 60
     /** Event bus to subscribe to events on . */
61 61
     private final DMDircMBassador eventBus;
62 62
     /** "Random" colours to use to colour nicknames. */
63
-    private String[] randColours = new String[]{
63
+    private String[] randColours = {
64 64
         "E90E7F", "8E55E9", "B30E0E", "18B33C", "58ADB3", "9E54B3", "B39875", "3176B3",};
65 65
     private boolean useowncolour;
66 66
     private String owncolour;
@@ -81,7 +81,7 @@ public class NickColourManager implements ConfigChangeListener {
81 81
     @Handler
82 82
     public void handleChannelNames(final ChannelGotnamesEvent event) {
83 83
         final ChannelInfo chanInfo = event.getChannel().getChannelInfo();
84
-        final String network = event.getChannel().getConnection().getNetwork();
84
+        final String network = event.getChannel().getOptionalConnection().get().getNetwork();
85 85
 
86 86
         for (ChannelClientInfo client : chanInfo.getChannelClients()) {
87 87
             colourClient(network, client);
@@ -90,7 +90,7 @@ public class NickColourManager implements ConfigChangeListener {
90 90
 
91 91
     @Handler
92 92
     public void handleChannelJoin(final ChannelJoinEvent event) {
93
-        final String network = event.getChannel().getConnection().getNetwork();
93
+        final String network = event.getChannel().getOptionalConnection().get().getNetwork();
94 94
         colourClient(network, event.getClient());
95 95
     }
96 96
 

+ 4
- 2
parserdebug/src/com/dmdirc/addons/parserdebug/ParserDebugCommand.java View File

@@ -31,6 +31,7 @@ import com.dmdirc.commandparser.commands.CommandOptions;
31 31
 import com.dmdirc.commandparser.commands.context.CommandContext;
32 32
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
33 33
 import com.dmdirc.interfaces.CommandController;
34
+import com.dmdirc.interfaces.Connection;
34 35
 import com.dmdirc.parser.interfaces.Parser;
35 36
 
36 37
 import javax.annotation.Nonnull;
@@ -76,7 +77,8 @@ public final class ParserDebugCommand extends Command {
76 77
             final CommandContext context) {
77 78
         final boolean isSilent = commandArgs.isSilent();
78 79
 
79
-        final Parser parser = ((ServerCommandContext) context).getConnection().getParser();
80
+        final Connection connection = ((ServerCommandContext) context).getConnection();
81
+        final Parser parser = connection.getParser();
80 82
 
81 83
         if (parser == null) {
82 84
             sendLine(origin, isSilent, FORMAT_ERROR, "Unable to get a parser for this window.");
@@ -89,7 +91,7 @@ public final class ParserDebugCommand extends Command {
89 91
                 sendLine(origin, isSilent, FORMAT_ERROR, "Removing callback failed");
90 92
             }
91 93
         } else {
92
-            if (parserDebugManager.addParser(parser, origin.getConnection())) {
94
+            if (parserDebugManager.addParser(parser, connection)) {
93 95
                 sendLine(origin, isSilent, FORMAT_OUTPUT, "Adding callback ok");
94 96
             } else {
95 97
                 sendLine(origin, isSilent, FORMAT_ERROR, "Adding callback failed");

+ 5
- 3
windowstatus/src/com/dmdirc/addons/windowstatus/WindowStatusManager.java View File

@@ -41,6 +41,8 @@ import com.dmdirc.parser.interfaces.ChannelInfo;
41 41
 import com.dmdirc.parser.interfaces.ClientInfo;
42 42
 import com.dmdirc.plugins.PluginDomain;
43 43
 
44
+import java.util.Optional;
45
+
44 46
 import javax.inject.Inject;
45 47
 
46 48
 import net.engio.mbassy.listener.Handler;
@@ -192,9 +194,9 @@ public class WindowStatusManager implements ConfigChangeListener {
192 194
     private String updateStatusQuery(final Query frame) {
193 195
         final StringBuilder textString = new StringBuilder();
194 196
         textString.append(frame.getHost());
195
-        if (showname && frame.getConnection().getParser() != null) {
196
-            final ClientInfo client = frame.getConnection().getParser()
197
-                    .getClient(frame.getHost());
197
+        final Optional<Connection> connection = frame.getOptionalConnection();
198
+        if (showname && connection.isPresent()) {
199
+            final ClientInfo client = connection.get().getParser().getClient(frame.getHost());
198 200
             final String realname = client.getRealname();
199 201
             if (realname != null && !realname.isEmpty()) {
200 202
                 textString.append(" - ");

Loading…
Cancel
Save