Browse Source

Parser tidying

Remove public non-final fields in favour of getters
Remove some unused and some useless methods

Change-Id: I3c0841494242da9a7c3a73f776b783965e6619fb
Reviewed-on: http://gerrit.dmdirc.com/2182
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith 12 years ago
parent
commit
43c5d3ee62

+ 23
- 75
src/com/dmdirc/parser/irc/IRCParser.java View File

@@ -109,9 +109,9 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
109 109
      * Nickname here is *not* always accurate.<br><br>
110 110
      * ClientInfo variable tParser.getMyself() should be used for accurate info.
111 111
      */
112
-    public MyInfo me = new MyInfo();
112
+    private MyInfo me = new MyInfo();
113 113
     /**    Server Info requested by user. */
114
-    public ServerInfo server;
114
+    private ServerInfo server;
115 115
     /** The proxy to use to connect. */
116 116
     private URI proxy;
117 117
     /** Should PINGs be sent to the server to check if its alive? */
@@ -258,12 +258,10 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
258 258
             public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
259 259
             }
260 260
         },};
261
-    /** Should fake (channel)clients be created for callbacks where they do not exist? */
262
-    private boolean createFake = true;
263 261
     /** Should channels automatically request list modes? */
264 262
     private boolean autoListMode = true;
265 263
     /** Should part/quit/kick callbacks be fired before removing the user internally? */
266
-    boolean removeAfterCallback = true;
264
+    private boolean removeAfterCallback = true;
267 265
     /** This is the TrustManager used for SSL Sockets. */
268 266
     private TrustManager[] myTrustManager = trustAllCerts;
269 267
     /** The KeyManagers used for client certificates for SSL sockets. */
@@ -423,24 +421,6 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
423 421
         return myMap;
424 422
     }
425 423
 
426
-    /**
427
-     * Get the current Value of createFake.
428
-     *
429
-     * @return Value of createFake (true if fake clients will be added for callbacks, else false)
430
-     */
431
-    public boolean getCreateFake() {
432
-        return createFake;
433
-    }
434
-
435
-    /**
436
-     * Set the current Value of createFake.
437
-     *
438
-     * @param newValue New value to set createFake
439
-     */
440
-    public void setCreateFake(final boolean newValue) {
441
-        createFake = newValue;
442
-    }
443
-
444 424
     /**
445 425
      * Get the current Value of autoListMode.
446 426
      *
@@ -1191,6 +1171,16 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1191 1171
         return serverName;
1192 1172
     }
1193 1173
 
1174
+    /**
1175
+     * Gets the ServerInfo object that corresponds to the server that this
1176
+     * parser is configured to connect to.
1177
+     *
1178
+     * @return This parser's configured server info.
1179
+     */
1180
+    public ServerInfo getServerInfo() {
1181
+        return server;
1182
+    }
1183
+
1194 1184
     /** {@inheritDoc} */
1195 1185
     @Override
1196 1186
     public String getLastLine() {
@@ -1360,33 +1350,6 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1360 1350
         stringConverter = new IRCStringConverter(encoding);
1361 1351
     }
1362 1352
 
1363
-    /**
1364
-     * Get the known boolean chanmodes in 005 order.
1365
-     * Modes are returned in the order that the ircd specifies the modes in 005
1366
-     * with any newly-found modes (mode being set that wasn't specified in 005)
1367
-     * being added at the end.
1368
-     *
1369
-     * @return All the currently known boolean modes
1370
-     */
1371
-    public String getBoolChanModes005() {
1372
-        // This code isn't the nicest, as Hashtable's don't lend themselves to being
1373
-        // ordered.
1374
-        // Order isn't really important, and this code only takes 3 lines of we
1375
-        // don't care about it but ordered guarentees that on a specific ircd this
1376
-        // method will ALWAYs return the same value.
1377
-        final char[] modes = new char[chanModesBool.size()];
1378
-
1379
-        for (Map.Entry<Character, Long> entry : chanModesBool.entrySet()) {
1380
-            // nTemp should never be less than 0
1381
-            if (entry.getValue() > 0) {
1382
-                final double pos = Math.log(entry.getValue()) / Math.log(2);
1383
-                modes[(int) pos] = entry.getKey();
1384
-            }
1385
-        }
1386
-
1387
-        return new String(modes);
1388
-    }
1389
-
1390 1353
     /**
1391 1354
      * Process CHANMODES from 005.
1392 1355
      */
@@ -1662,15 +1625,6 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1662 1625
         h005Info.put("PREFIXSTRING", bits[0]);
1663 1626
     }
1664 1627
 
1665
-    /**
1666
-     * Check if server is ready.
1667
-     *
1668
-     * @return true if 001 has been recieved, false otherwise.
1669
-     */
1670
-    public boolean isReady() {
1671
-        return got001;
1672
-    }
1673
-
1674 1628
     /** {@inheritDoc} */
1675 1629
     @Override
1676 1630
     public void joinChannel(final String channel) {
@@ -2017,22 +1971,6 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
2017 1971
         return ServerType.findServerType(h005Info.get("004IRCD"), networkName, h005Info.get("003IRCD"), h005Info.get("002IRCD"));
2018 1972
     }
2019 1973
 
2020
-    /**
2021
-     * Get the name of the ircd.
2022
-     *
2023
-     * @param getType if this is false the string from 004 is returned. Else a guess of the type (ircu, hybrid, ircnet)
2024
-     * @return IRCD Version or Type
2025
-     * @deprecated Use getServerSoftware() or getServerSoftwareType() instead.
2026
-     */
2027
-    @Deprecated
2028
-    public String getIRCD(final boolean getType) {
2029
-        if (getType) {
2030
-            return getServerSoftwareType();
2031
-        } else {
2032
-            return getServerSoftware();
2033
-        }
2034
-    }
2035
-
2036 1974
     /** {@inheritDoc} */
2037 1975
     @Override
2038 1976
     public String getServerSoftware() {
@@ -2241,6 +2179,16 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
2241 2179
         }
2242 2180
     }
2243 2181
 
2182
+    /**
2183
+     * Retrieves the local user information that this parser was configured
2184
+     * with.
2185
+     *
2186
+     * @return This parser's local user configuration
2187
+     */
2188
+    public MyInfo getMyInfo() {
2189
+        return me;
2190
+    }
2191
+
2244 2192
     /**
2245 2193
      * Get the current username (Specified in MyInfo on construction).
2246 2194
      * Get the username given in MyInfo

+ 1
- 1
src/com/dmdirc/parser/irc/Process001.java View File

@@ -78,7 +78,7 @@ public class Process001 extends IRCProcessor {
78 78
 
79 79
         parser.startPingTimer();
80 80
 
81
-        final String channels = parser.server.getChannels();
81
+        final String channels = parser.getServerInfo().getChannels();
82 82
         if (channels != null) {
83 83
             parser.joinChannel(channels);
84 84
         }

+ 2
- 2
src/com/dmdirc/parser/irc/ProcessKick.java View File

@@ -89,14 +89,14 @@ public class ProcessKick extends IRCProcessor {
89 89
                 return;
90 90
             }
91 91
             iChannelKicker = iChannel.getChannelClient(token[0]);
92
-            if (parser.removeAfterCallback) {
92
+            if (parser.getRemoveAfterCallback()) {
93 93
                 callDebugInfo(IRCParser.DEBUG_INFO, "processKick: calling kick before. {%s | %s | %s | %s | %s}", iChannel, iChannelClient, iChannelKicker, sReason, token[0]);
94 94
                 callChannelKick(iChannel, iChannelClient, iChannelKicker, sReason, token[0]);
95 95
             }
96 96
             callDebugInfo(IRCParser.DEBUG_INFO, "processKick: removing client from channel { %s | %s }", iChannel, iClient);
97 97
             iChannel.delClient(iClient);
98 98
             callDebugInfo(IRCParser.DEBUG_INFO, "processKick: removed client from channel { %s | %s }", iChannel, iClient);
99
-            if (!parser.removeAfterCallback) {
99
+            if (!parser.getRemoveAfterCallback()) {
100 100
                 callDebugInfo(IRCParser.DEBUG_INFO, "processKick: calling kick after. {%s | %s | %s | %s | %s}", iChannel, iChannelClient, iChannelKicker, sReason, token[0]);
101 101
                 callChannelKick(iChannel, iChannelClient, iChannelKicker, sReason, token[0]);
102 102
             }

+ 4
- 4
src/com/dmdirc/parser/irc/ProcessNickInUse.java View File

@@ -66,12 +66,12 @@ public class ProcessNickInUse extends IRCProcessor {
66 66
                 callDebugInfo(IRCParser.DEBUG_INFO, "Using inbuilt handler");
67 67
                 // If this is before 001 we will try and get a nickname, else we will leave the nick as-is
68 68
                 if (parser.triedAlt) {
69
-                    if (parser.getStringConverter().equalsIgnoreCase(parser.thinkNickname, parser.me.getAltNickname())) {
70
-                        parser.thinkNickname = parser.me.getNickname();
69
+                    if (parser.getStringConverter().equalsIgnoreCase(parser.thinkNickname, parser.getMyInfo().getAltNickname())) {
70
+                        parser.thinkNickname = parser.getMyInfo().getNickname();
71 71
                     }
72
-                    parser.getLocalClient().setNickname(parser.me.getPrependChar() + parser.thinkNickname);
72
+                    parser.getLocalClient().setNickname(parser.getMyInfo().getPrependChar() + parser.thinkNickname);
73 73
                 } else {
74
-                    parser.getLocalClient().setNickname(parser.me.getAltNickname());
74
+                    parser.getLocalClient().setNickname(parser.getMyInfo().getAltNickname());
75 75
                     parser.triedAlt = true;
76 76
                 }
77 77
             }

+ 2
- 2
src/com/dmdirc/parser/irc/ProcessPart.java View File

@@ -84,12 +84,12 @@ public class ProcessPart extends IRCProcessor {
84 84
                 // callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Got part for channel ("+token[2]+") for a non-existant user. [User: "+token[0]+"]", parser.getLastLine()));
85 85
                 return;
86 86
             }
87
-            if (parser.removeAfterCallback) {
87
+            if (parser.getRemoveAfterCallback()) {
88 88
                 callChannelPart(iChannel, iChannelClient, sReason);
89 89
             }
90 90
             callDebugInfo(IRCParser.DEBUG_INFO, "Removing %s from %s", iClient.getNickname(), iChannel.getName());
91 91
             iChannel.delClient(iClient);
92
-            if (!parser.removeAfterCallback) {
92
+            if (!parser.getRemoveAfterCallback()) {
93 93
                 callChannelPart(iChannel, iChannelClient, sReason);
94 94
             }
95 95
             if (iClient == parser.getLocalClient()) {

+ 4
- 4
src/com/dmdirc/parser/irc/ProcessQuit.java View File

@@ -80,7 +80,7 @@ public class ProcessQuit extends IRCProcessor {
80 80
         for (IRCChannelInfo iChannel : channelList) {
81 81
             iChannelClient = iChannel.getChannelClient(iClient);
82 82
             if (iChannelClient != null) {
83
-                if (parser.removeAfterCallback) {
83
+                if (parser.getRemoveAfterCallback()) {
84 84
                     callChannelQuit(iChannel, iChannelClient, sReason);
85 85
                 }
86 86
                 if (iClient == parser.getLocalClient()) {
@@ -89,13 +89,13 @@ public class ProcessQuit extends IRCProcessor {
89 89
                 } else {
90 90
                     iChannel.delClient(iClient);
91 91
                 }
92
-                if (!parser.removeAfterCallback) {
92
+                if (!parser.getRemoveAfterCallback()) {
93 93
                     callChannelQuit(iChannel, iChannelClient, sReason);
94 94
                 }
95 95
             }
96 96
         }
97 97
 
98
-        if (parser.removeAfterCallback) {
98
+        if (parser.getRemoveAfterCallback()) {
99 99
             callQuit(iClient, sReason);
100 100
         }
101 101
         if (iClient == parser.getLocalClient()) {
@@ -103,7 +103,7 @@ public class ProcessQuit extends IRCProcessor {
103 103
         } else {
104 104
             parser.removeClient(iClient);
105 105
         }
106
-        if (!parser.removeAfterCallback) {
106
+        if (!parser.getRemoveAfterCallback()) {
107 107
             callQuit(iClient, sReason);
108 108
         }
109 109
     }

+ 2
- 12
test/com/dmdirc/parser/irc/IRCParserTest.java View File

@@ -262,16 +262,6 @@ public class IRCParserTest {
262 262
         assertEquals("abc.def.ghi.123", parser.getBindIP());
263 263
     }
264 264
 
265
-    @Test
266
-    public void testCreateFake() {
267
-        final TestParser parser = new TestParser();
268
-
269
-        parser.setCreateFake(false);
270
-        assertFalse(parser.getCreateFake());
271
-        parser.setCreateFake(true);
272
-        assertTrue(parser.getCreateFake());
273
-    }
274
-
275 265
     @Test
276 266
     public void testAutoListMode() {
277 267
         final TestParser parser = new TestParser();
@@ -329,7 +319,7 @@ public class IRCParserTest {
329 319
         assertEquals("bar :abc def", TestParser.getParam("foo :bar :abc def"));
330 320
         assertEquals("abc def", TestParser.getParam("abc def"));
331 321
     }
332
-    
322
+
333 323
     @Test
334 324
     public void testKick() throws CallbackNotFoundException {
335 325
         final TestParser parser = new TestParser();
@@ -344,7 +334,7 @@ public class IRCParserTest {
344 334
                 (IRCChannelClientInfo) anyObject(), (IRCChannelClientInfo) anyObject(),
345 335
                 anyString(), anyString());
346 336
     }
347
-    
337
+
348 338
     @Test
349 339
     public void testIllegalPort2() throws URISyntaxException {
350 340
         final TestParser tp = new TestParser(new MyInfo(), new URI("irc://127.0.0.1:65570/"));

Loading…
Cancel
Save