Browse Source

Fix some crimes against humanity

Change-Id: I916e72384d318ab304565a5123ab82f9d2096de5
Reviewed-on: http://gerrit.dmdirc.com/1507
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.5
Chris Smith 13 years ago
parent
commit
9e6834de99
1 changed files with 42 additions and 61 deletions
  1. 42
    61
      src/com/dmdirc/parser/irc/IRCParser.java

+ 42
- 61
src/com/dmdirc/parser/irc/IRCParser.java View File

@@ -109,11 +109,11 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
109 109
     /** Timer for server ping. */
110 110
     private Timer pingTimer = null;
111 111
     /** Semaphore for access to pingTimer. */
112
-    private Semaphore pingTimerSem = new Semaphore(1);
112
+    private final Semaphore pingTimerSem = new Semaphore(1);
113 113
     /** Length of time to wait between ping stuff. */
114 114
     private long pingTimerLength = 10000;
115 115
     /** Is a ping needed? */
116
-    private volatile AtomicBoolean pingNeeded = new AtomicBoolean(false);
116
+    private final AtomicBoolean pingNeeded = new AtomicBoolean(false);
117 117
     /** Time last ping was sent at. */
118 118
     private long pingTime;
119 119
     /** Current Server Lag. */
@@ -198,9 +198,9 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
198 198
     final Map<Character, Byte> chanModesOther = new HashMap<Character, Byte>();
199 199
 
200 200
     /** The last line of input recieved from the server */
201
-    ReadLine lastLine = null;
201
+    private ReadLine lastLine = null;
202 202
     /** Should the lastline (where given) be appended to the "data" part of any onErrorInfo call? */
203
-    boolean addLastLine = false;
203
+    private boolean addLastLine = false;
204 204
 
205 205
     /** Channel Prefixes (ie # + etc). */
206 206
     private final List<Character> chanPrefix = Collections.synchronizedList(new LinkedList<Character>());
@@ -214,12 +214,12 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
214 214
     final Map<String, String> h005Info = new HashMap<String, String>();
215 215
 
216 216
     /** Ignore List. */
217
-    IgnoreList myIgnoreList = new IgnoreList();
217
+    private IgnoreList myIgnoreList = new IgnoreList();
218 218
 
219 219
     /** Reference to the callback Manager. */
220
-    CallbackManager<IRCParser> myCallbackManager = new IRCCallbackManager(this);
220
+    private final CallbackManager<IRCParser> myCallbackManager = new IRCCallbackManager(this);
221 221
     /** Reference to the Processing Manager. */
222
-    ProcessingManager myProcessingManager = new ProcessingManager(this);
222
+    private final ProcessingManager myProcessingManager = new ProcessingManager(this);
223 223
 
224 224
     /** Should we automatically disconnect on fatal errors?. */
225 225
     private boolean disconnectOnFatal = true;
@@ -228,7 +228,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
228 228
     protected SocketState currentSocketState = SocketState.NULL;
229 229
 
230 230
     /** Map to store arbitrary data. */
231
-    private Map<Object, Object> myMap = new HashMap<Object, Object>();
231
+    private final Map<Object, Object> myMap = new HashMap<Object, Object>();
232 232
 
233 233
     /** This is the socket used for reading from/writing to the IRC server. */
234 234
     private Socket socket;
@@ -252,10 +252,10 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
252 252
     };
253 253
 
254 254
     /** Should fake (channel)clients be created for callbacks where they do not exist? */
255
-    boolean createFake = true;
255
+    private boolean createFake = true;
256 256
 
257 257
     /** Should channels automatically request list modes? */
258
-    boolean autoListMode = true;
258
+    private boolean autoListMode = true;
259 259
 
260 260
     /** Should part/quit/kick callbacks be fired before removing the user internally? */
261 261
     boolean removeAfterCallback = true;
@@ -1194,25 +1194,15 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1194 1194
         // don't care about it but ordered guarentees that on a specific ircd this
1195 1195
         // method will ALWAYs return the same value.
1196 1196
         final char[] modes = new char[chanModesBool.size()];
1197
-        long nTemp;
1198
-        double pos;
1199 1197
 
1200
-        for (char cTemp : chanModesBool.keySet()) {
1201
-            nTemp = chanModesBool.get(cTemp);
1198
+        for (Map.Entry<Character, Long> entry : chanModesBool.entrySet()) {
1202 1199
             // nTemp should never be less than 0
1203
-            if (nTemp > 0) {
1204
-                pos = Math.log(nTemp) / Math.log(2);
1205
-                modes[(int) pos] = cTemp;
1200
+            if (entry.getValue() > 0) {
1201
+                final double pos = Math.log(entry.getValue()) / Math.log(2);
1202
+                modes[(int) pos] = entry.getKey();
1206 1203
             }
1207
-/*            // Is there an easier way to find out the power of 2 value for a number?
1208
-            // ie 1024 = 10, 512 = 9 ?
1209
-            for (int i = 0; i < modes.length; i++) {
1210
-                if (Math.pow(2, i) == (double) nTemp) {
1211
-                    modes[i] = cTemp;
1212
-                    break;
1213
-                }
1214
-            }*/
1215 1204
         }
1205
+
1216 1206
         return new String(modes);
1217 1207
     }
1218 1208
 
@@ -1287,7 +1277,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1287 1277
             callDebugInfo(DEBUG_INFO, "Found Boolean Mode: %c [%d]", cMode, nextKeyCMBool);
1288 1278
             if (!chanModesBool.containsKey(cMode)) {
1289 1279
                 chanModesBool.put(cMode, nextKeyCMBool);
1290
-                nextKeyCMBool = nextKeyCMBool * 2;
1280
+                nextKeyCMBool *= 2;
1291 1281
             }
1292 1282
         }
1293 1283
     }
@@ -1404,7 +1394,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1404 1394
             callDebugInfo(DEBUG_INFO, "Found User Mode: %c [%d]", cMode, nNextKeyUser);
1405 1395
             if (!userModes.containsKey(cMode)) {
1406 1396
                 userModes.put(cMode, nNextKeyUser);
1407
-                nNextKeyUser = nNextKeyUser * 2;
1397
+                nNextKeyUser *= 2;
1408 1398
             }
1409 1399
         }
1410 1400
     }
@@ -1474,7 +1464,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1474 1464
                 prefixModes.put(cMode, nextKeyPrefix);
1475 1465
                 prefixMap.put(cMode, cPrefix);
1476 1466
                 prefixMap.put(cPrefix, cMode);
1477
-                nextKeyPrefix = nextKeyPrefix * 2;
1467
+                nextKeyPrefix *= 2;
1478 1468
             }
1479 1469
         }
1480 1470
 
@@ -1500,16 +1490,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1500 1490
         joinChannels(new ChannelJoinRequest(channel, key));
1501 1491
     }
1502 1492
 
1503
-    /**
1504
-     * Join a Channel with a key.
1505
-     * This also allows passing a list of channels such as:
1506
-     * "#channel1 key1,#channel2 key2,#channel3,#channel4,#channel5 key2"
1507
-     *
1508
-     * @param channel Name of channel to join or a list of channels.
1509
-     * @param key Key to use to try and join the channel (If a list is given
1510
-     *            then this key will be used for any channels that do not
1511
-     *            specify one themselves.
1512
-     */
1493
+    /** {@inheritDoc} */
1513 1494
     @Override
1514 1495
     public void joinChannels(final ChannelJoinRequest ... channels) {
1515 1496
         // We store a map from key->channels to allow intelligent joining of
@@ -1527,7 +1508,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1527 1508
             // Add the channel to the list. If the name is invalid and
1528 1509
             // autoprefix is off we will just skip this channel.
1529 1510
             if (!channel.getName().isEmpty()) {
1530
-                if (list.length() > 0) { list.append(","); }
1511
+                if (list.length() > 0) { list.append(','); }
1531 1512
                 if (!isValidChannelName(channel.getName())) {
1532 1513
                     if (h005Info.containsKey("CHANTYPES")) {
1533 1514
                         final String chantypes = h005Info.get("CHANTYPES");
@@ -1598,8 +1579,8 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1598 1579
         // and subtract it from the MAX_LINELENGTH. This should be sufficient in most cases.
1599 1580
         // Lint = the 2 ":" at the start and end and the 3 separating " "s
1600 1581
         int length = 0;
1601
-        if (type != null) { length = length + type.length(); }
1602
-        if (target != null) { length = length + target.length(); }
1582
+        if (type != null) { length += type.length(); }
1583
+        if (target != null) { length += target.length(); }
1603 1584
         return getMaxLength(length);
1604 1585
     }
1605 1586
 
@@ -1669,31 +1650,31 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1669 1650
     }
1670 1651
 
1671 1652
     /** {@inheritDoc} */
1672
-        @Override
1653
+    @Override
1673 1654
     public void sendMessage(final String target, final String message) {
1674 1655
         if (target == null || message == null) { return; }
1675
-        if (target.isEmpty()/* || sMessage.isEmpty()*/) { return; }
1656
+        if (target.isEmpty()) { return; }
1676 1657
 
1677 1658
         sendString("PRIVMSG " + target + " :" + message);
1678 1659
     }
1679 1660
 
1680 1661
     /** {@inheritDoc} */
1681
-        @Override
1662
+    @Override
1682 1663
     public void sendNotice(final String target, final String message) {
1683 1664
         if (target == null || message == null) { return; }
1684
-        if (target.isEmpty()/* || sMessage.isEmpty()*/) { return; }
1665
+        if (target.isEmpty()) { return; }
1685 1666
 
1686 1667
         sendString("NOTICE " + target + " :" + message);
1687 1668
     }
1688 1669
 
1689 1670
     /** {@inheritDoc} */
1690
-        @Override
1691
-        public void sendAction(final String target, final String message) {
1671
+    @Override
1672
+    public void sendAction(final String target, final String message) {
1692 1673
         sendCTCP(target, "ACTION", message);
1693 1674
     }
1694 1675
 
1695 1676
     /** {@inheritDoc} */
1696
-        @Override
1677
+    @Override
1697 1678
     public void sendCTCP(final String target, final String type, final String message) {
1698 1679
         if (target == null || message == null) { return; }
1699 1680
         if (target.isEmpty() || type.isEmpty()) { return; }
@@ -1746,13 +1727,13 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1746 1727
     }
1747 1728
 
1748 1729
     /** {@inheritDoc}
1749
-         *
1730
+     *
1750 1731
      * - Before channel prefixes are known (005/noMOTD/MOTDEnd), this checks
1751 1732
      *   that the first character is either #, &amp;, ! or +
1752 1733
      * - Assumes that any channel that is already known is valid, even if
1753 1734
      *   005 disagrees.
1754 1735
      */
1755
-        @Override
1736
+    @Override
1756 1737
     public boolean isValidChannelName(final String name) {
1757 1738
         // Check sChannelName is not empty or null
1758 1739
         if (name == null || name.isEmpty()) { return false; }
@@ -1769,11 +1750,11 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1769 1750
         // Otherwise return true if:
1770 1751
         // Channel equals "0"
1771 1752
         // first character of the channel name is a valid channel prefix.
1772
-        return chanPrefix.contains(name.charAt(0)) || name.equals("0");
1753
+        return chanPrefix.contains(name.charAt(0)) || "0".equals(name);
1773 1754
     }
1774 1755
 
1775 1756
     /** {@inheritDoc} */
1776
-        @Override
1757
+    @Override
1777 1758
     public boolean isUserSettable(final char mode) {
1778 1759
         String validmodes;
1779 1760
         if (h005Info.containsKey("USERCHANMODES")) {
@@ -1952,7 +1933,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1952 1933
     }
1953 1934
 
1954 1935
     /** {@inheritDoc} */
1955
-        @Override
1936
+    @Override
1956 1937
     public long getServerLatency() {
1957 1938
         return serverLag;
1958 1939
     }
@@ -1969,11 +1950,11 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1969 1950
         else { return System.currentTimeMillis() - pingTime; }
1970 1951
     }
1971 1952
 
1972
-        /** {@inheritDoc} */
1973
-        @Override
1974
-        public long getPingTime() {
1975
-            return getPingTime(false);
1976
-        }
1953
+    /** {@inheritDoc} */
1954
+    @Override
1955
+    public long getPingTime() {
1956
+        return getPingTime(false);
1957
+    }
1977 1958
 
1978 1959
     /**
1979 1960
      * Set if a ping is needed or not.
@@ -1994,7 +1975,7 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
1994 1975
     }
1995 1976
 
1996 1977
     /** {@inheritDoc} */
1997
-        @Override
1978
+    @Override
1998 1979
     public IRCClientInfo getLocalClient() { return myself; }
1999 1980
 
2000 1981
     /**
@@ -2113,10 +2094,10 @@ public class IRCParser implements SecureParser, EncodingParser, Runnable {
2113 2094
     }
2114 2095
 
2115 2096
     /** {@inheritDoc} */
2116
-        @Override
2097
+    @Override
2117 2098
     public Collection<IRCChannelInfo> getChannels() {
2118 2099
         synchronized (channelList) {
2119
-                    return channelList.values();
2100
+            return channelList.values();
2120 2101
         }
2121 2102
     }
2122 2103
 

Loading…
Cancel
Save