Browse Source

Fix some singleton references.

Change-Id: I3246495eb2e40231177d4ae14faec70252409ec2
Reviewed-on: http://gerrit.dmdirc.com/2728
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
151dec3886

+ 21
- 15
src/com/dmdirc/Server.java View File

@@ -29,11 +29,11 @@ import com.dmdirc.commandparser.CommandType;
29 29
 import com.dmdirc.commandparser.parsers.CommandParser;
30 30
 import com.dmdirc.config.ConfigManager;
31 31
 import com.dmdirc.config.Identity;
32
-import com.dmdirc.config.IdentityManager;
33 32
 import com.dmdirc.interfaces.AwayStateListener;
34 33
 import com.dmdirc.interfaces.CommandController;
35 34
 import com.dmdirc.interfaces.ConfigChangeListener;
36 35
 import com.dmdirc.interfaces.Connection;
36
+import com.dmdirc.interfaces.IdentityFactory;
37 37
 import com.dmdirc.interfaces.InviteListener;
38 38
 import com.dmdirc.logger.ErrorLevel;
39 39
 import com.dmdirc.logger.Logger;
@@ -109,10 +109,10 @@ public class Server extends WritableFrameContainer
109 109
     // <editor-fold defaultstate="collapsed" desc="Instance">
110 110
 
111 111
     /** Open channels that currently exist on the server. */
112
-    private final Map<String, Channel> channels = new ConcurrentSkipListMap<String, Channel>();
112
+    private final Map<String, Channel> channels = new ConcurrentSkipListMap<>();
113 113
 
114 114
     /** Open query windows on the server. */
115
-    private final Map<String, Query> queries = new ConcurrentSkipListMap<String, Query>();
115
+    private final Map<String, Query> queries = new ConcurrentSkipListMap<>();
116 116
 
117 117
     /** The Parser instance handling this server. */
118 118
     private Parser parser;
@@ -163,10 +163,10 @@ public class Server extends WritableFrameContainer
163 163
     private final ServerEventHandler eventHandler = new ServerEventHandler(this);
164 164
 
165 165
     /** A list of outstanding invites. */
166
-    private final List<Invite> invites = new ArrayList<Invite>();
166
+    private final List<Invite> invites = new ArrayList<>();
167 167
 
168 168
     /** A set of channels we want to join without focusing. */
169
-    private final Set<String> backgroundChannels = new HashSet<String>();
169
+    private final Set<String> backgroundChannels = new HashSet<>();
170 170
 
171 171
     /** Our ignore list. */
172 172
     private final IgnoreList ignoreList = new IgnoreList();
@@ -183,6 +183,9 @@ public class Server extends WritableFrameContainer
183 183
     /** ServerManager that created us. */
184 184
     private final ServerManager manager;
185 185
 
186
+    /** Factory to use to create new identities. */
187
+    private final IdentityFactory identityFactory;
188
+
186 189
     // </editor-fold>
187 190
 
188 191
     // </editor-fold>
@@ -201,6 +204,7 @@ public class Server extends WritableFrameContainer
201 204
      * @param windowManager The window manager to register this server with.
202 205
      * @param aliasWrapper The actions wrapper to retrieve aliases from.
203 206
      * @param commandController The controller to use to retrieve commands.
207
+     * @param identityFactory The factory to use to create identities.
204 208
      * @param uri The address of the server to connect to
205 209
      * @param profile The profile to use
206 210
      */
@@ -212,6 +216,7 @@ public class Server extends WritableFrameContainer
212 216
             final WindowManager windowManager,
213 217
             final AliasWrapper aliasWrapper,
214 218
             final CommandController commandController,
219
+            final IdentityFactory identityFactory,
215 220
             final URI uri,
216 221
             final Identity profile) {
217 222
         super("server-disconnected",
@@ -225,6 +230,7 @@ public class Server extends WritableFrameContainer
225 230
 
226 231
         this.manager = manager;
227 232
         this.parserFactory = parserFactory;
233
+        this.identityFactory = identityFactory;
228 234
         setConnectionDetails(uri, profile);
229 235
 
230 236
         manager.registerServer(this);
@@ -517,7 +523,7 @@ public class Server extends WritableFrameContainer
517 523
     /** {@inheritDoc} */
518 524
     @Override
519 525
     public List<String> getChannels() {
520
-        return new ArrayList<String>(channels.keySet());
526
+        return new ArrayList<>(channels.keySet());
521 527
     }
522 528
 
523 529
     /** {@inheritDoc} */
@@ -651,7 +657,7 @@ public class Server extends WritableFrameContainer
651 657
      * Closes all open channel windows associated with this server.
652 658
      */
653 659
     private void closeChannels() {
654
-        for (Channel channel : new ArrayList<Channel>(channels.values())) {
660
+        for (Channel channel : new ArrayList<>(channels.values())) {
655 661
             channel.close();
656 662
         }
657 663
     }
@@ -669,7 +675,7 @@ public class Server extends WritableFrameContainer
669 675
      * Closes all open query windows associated with this server.
670 676
      */
671 677
     private void closeQueries() {
672
-        for (Query query : new ArrayList<Query>(queries.values())) {
678
+        for (Query query : new ArrayList<>(queries.values())) {
673 679
             query.close();
674 680
         }
675 681
     }
@@ -858,7 +864,7 @@ public class Server extends WritableFrameContainer
858 864
     public void join(final boolean focus, final ChannelJoinRequest ... requests) {
859 865
         synchronized (myStateLock) {
860 866
             if (myState.getState() == ServerState.CONNECTED) {
861
-                final List<ChannelJoinRequest> pending = new ArrayList<ChannelJoinRequest>();
867
+                final List<ChannelJoinRequest> pending = new ArrayList<>();
862 868
 
863 869
                 for (ChannelJoinRequest request : requests) {
864 870
                     removeInvites(request.getName());
@@ -1453,7 +1459,7 @@ public class Server extends WritableFrameContainer
1453 1459
 
1454 1460
             converter = parser.getStringConverter();
1455 1461
 
1456
-            final List<ChannelJoinRequest> requests = new ArrayList<ChannelJoinRequest>();
1462
+            final List<ChannelJoinRequest> requests = new ArrayList<>();
1457 1463
             if (getConfigManager().getOptionBool(DOMAIN_GENERAL, "rejoinchannels")) {
1458 1464
                 for (Channel chan : channels.values()) {
1459 1465
                     requests.add(new ChannelJoinRequest(chan.getName()));
@@ -1547,13 +1553,13 @@ public class Server extends WritableFrameContainer
1547 1553
     /** {@inheritDoc} */
1548 1554
     @Override
1549 1555
     public Identity getServerIdentity() {
1550
-        return IdentityManager.getIdentityManager().createServerConfig(parser.getServerName());
1556
+        return identityFactory.createServerConfig(parser.getServerName());
1551 1557
     }
1552 1558
 
1553 1559
     /** {@inheritDoc} */
1554 1560
     @Override
1555 1561
     public Identity getNetworkIdentity() {
1556
-        return IdentityManager.getIdentityManager().createNetworkConfig(getNetwork());
1562
+        return identityFactory.createNetworkConfig(getNetwork());
1557 1563
     }
1558 1564
 
1559 1565
     // </editor-fold>
@@ -1580,7 +1586,7 @@ public class Server extends WritableFrameContainer
1580 1586
     @Override
1581 1587
     public void addInvite(final Invite invite) {
1582 1588
         synchronized (invites) {
1583
-            for (Invite oldInvite : new ArrayList<Invite>(invites)) {
1589
+            for (Invite oldInvite : new ArrayList<>(invites)) {
1584 1590
                 if (oldInvite.getChannel().equals(invite.getChannel())) {
1585 1591
                     removeInvite(oldInvite);
1586 1592
                 }
@@ -1619,7 +1625,7 @@ public class Server extends WritableFrameContainer
1619 1625
     /** {@inheritDoc} */
1620 1626
     @Override
1621 1627
     public void removeInvites(final String channel) {
1622
-        for (Invite invite : new ArrayList<Invite>(invites)) {
1628
+        for (Invite invite : new ArrayList<>(invites)) {
1623 1629
             if (invite.getChannel().equals(channel)) {
1624 1630
                 removeInvite(invite);
1625 1631
             }
@@ -1629,7 +1635,7 @@ public class Server extends WritableFrameContainer
1629 1635
     /** {@inheritDoc} */
1630 1636
     @Override
1631 1637
     public void removeInvites() {
1632
-        for (Invite invite : new ArrayList<Invite>(invites)) {
1638
+        for (Invite invite : new ArrayList<>(invites)) {
1633 1639
             removeInvite(invite);
1634 1640
         }
1635 1641
     }

+ 7
- 0
src/com/dmdirc/ServerManager.java View File

@@ -28,6 +28,7 @@ import com.dmdirc.config.ConfigManager;
28 28
 import com.dmdirc.config.Identity;
29 29
 import com.dmdirc.interfaces.CommandController;
30 30
 import com.dmdirc.interfaces.IdentityController;
31
+import com.dmdirc.interfaces.IdentityFactory;
31 32
 import com.dmdirc.interfaces.ServerFactory;
32 33
 import com.dmdirc.logger.ErrorLevel;
33 34
 import com.dmdirc.logger.Logger;
@@ -64,6 +65,9 @@ public class ServerManager implements ServerFactory {
64 65
     /** A provider of {@link CommandController}s to pass to servers. */
65 66
     private final Provider<CommandController> commandController;
66 67
 
68
+    /** The identity factory to give to servers. */
69
+    private final IdentityFactory identityFactory;
70
+
67 71
     /**
68 72
      * Creates a new instance of ServerManager.
69 73
      *
@@ -75,9 +79,11 @@ public class ServerManager implements ServerFactory {
75 79
     public ServerManager(
76 80
             final Provider<ParserFactory> parserFactoryProvider,
77 81
             final IdentityController identityController,
82
+            final IdentityFactory identityFactory,
78 83
             final Provider<CommandController> commandController) {
79 84
         this.parserFactoryProvider = parserFactoryProvider;
80 85
         this.identityController = identityController;
86
+        this.identityFactory = identityFactory;
81 87
         this.commandController = commandController;
82 88
     }
83 89
 
@@ -94,6 +100,7 @@ public class ServerManager implements ServerFactory {
94 100
                 WindowManager.getWindowManager(),
95 101
                 AliasWrapper.getAliasWrapper(),
96 102
                 commandController.get(),
103
+                identityFactory,
97 104
                 uri,
98 105
                 profile);
99 106
     }

+ 3
- 1
src/com/dmdirc/config/IdentityManager.java View File

@@ -605,6 +605,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
605 605
      *
606 606
      * @return A singleton instance of the IdentityManager.
607 607
      */
608
+    @Deprecated
608 609
     public static IdentityManager getIdentityManager() {
609 610
         return instance;
610 611
     }
@@ -614,7 +615,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
614 615
      *
615 616
      * @param identityManager The identity manager to use.
616 617
      */
617
-    public static void setIdentityManager(IdentityManager identityManager) {
618
+    @Deprecated
619
+    public static void setIdentityManager(final IdentityManager identityManager) {
618 620
         instance = identityManager;
619 621
     }
620 622
 

+ 3
- 1
test/com/dmdirc/ServerManagerTest.java View File

@@ -24,6 +24,7 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.interfaces.CommandController;
26 26
 import com.dmdirc.interfaces.IdentityController;
27
+import com.dmdirc.interfaces.IdentityFactory;
27 28
 import com.dmdirc.parser.common.ChannelJoinRequest;
28 29
 
29 30
 import javax.inject.Provider;
@@ -43,6 +44,7 @@ import static org.mockito.Mockito.*;
43 44
 public class ServerManagerTest {
44 45
 
45 46
     @Mock private IdentityController identityController;
47
+    @Mock private IdentityFactory identityFactory;
46 48
     @Mock private Provider<ParserFactory> parserFactoryProvider;
47 49
     @Mock private Provider<CommandController> commandControllerProvider;
48 50
     private ServerManager serverManager;
@@ -50,7 +52,7 @@ public class ServerManagerTest {
50 52
     @Before
51 53
     public void setUp() throws Exception {
52 54
         serverManager = new ServerManager(parserFactoryProvider,
53
-                identityController, commandControllerProvider);
55
+                identityController, identityFactory, commandControllerProvider);
54 56
     }
55 57
 
56 58
     @After

+ 3
- 1
test/com/dmdirc/ServerTest.java View File

@@ -27,6 +27,7 @@ import com.dmdirc.commandparser.parsers.CommandParser;
27 27
 import com.dmdirc.config.ConfigManager;
28 28
 import com.dmdirc.config.Identity;
29 29
 import com.dmdirc.interfaces.CommandController;
30
+import com.dmdirc.interfaces.IdentityFactory;
30 31
 import com.dmdirc.ui.WindowManager;
31 32
 
32 33
 import java.net.URI;
@@ -34,7 +35,6 @@ import java.net.URI;
34 35
 import org.junit.Before;
35 36
 import org.junit.Test;
36 37
 import org.mockito.Mock;
37
-import org.mockito.Mockito;
38 38
 import org.mockito.MockitoAnnotations;
39 39
 
40 40
 import static org.mockito.Mockito.*;
@@ -47,6 +47,7 @@ public class ServerTest {
47 47
     @Mock private ConfigManager configManager;
48 48
     @Mock private CommandParser commandParser;
49 49
     @Mock private ParserFactory parserFactory;
50
+    @Mock private IdentityFactory identityFactory;
50 51
     @Mock private WindowManager windowManager;
51 52
     @Mock private AliasWrapper aliasWrapper;
52 53
     @Mock private CommandController commandController;
@@ -67,6 +68,7 @@ public class ServerTest {
67 68
                 windowManager,
68 69
                 aliasWrapper,
69 70
                 commandController,
71
+                identityFactory,
70 72
                 new URI("irc-test://255.255.255.255"),
71 73
                 profile);
72 74
     }

Loading…
Cancel
Save