Bläddra i källkod

Fix some warnings

Change-Id: Ib9222a1a0ddf182fe9c092fa2340c3954c251848
Reviewed-on: http://gerrit.dmdirc.com/2815
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 år sedan
förälder
incheckning
d94427df6b

+ 2
- 3
src/com/dmdirc/parser/common/BaseParser.java Visa fil

@@ -67,7 +67,7 @@ public abstract class BaseParser extends ThreadedParser {
67 67
     private final CallbackManager callbackManager;
68 68
 
69 69
     /** A map for callers to use to store things for no sane reason. */
70
-    private final Map<Object, Object> map = new HashMap<Object, Object>();
70
+    private final Map<Object, Object> map = new HashMap<>();
71 71
 
72 72
     /**
73 73
      * Creates a new base parser for the specified URI.
@@ -77,8 +77,7 @@ public abstract class BaseParser extends ThreadedParser {
77 77
     public BaseParser(final URI uri) {
78 78
         this.uri = uri;
79 79
 
80
-        final Map<Class<?>, Class<?>> implementations
81
-                = new HashMap<Class<?>, Class<?>>();
80
+        final Map<Class<?>, Class<?>> implementations = new HashMap<>();
82 81
 
83 82
         for (Class<?> child : this.getClass().getAnnotation(ChildImplementations.class).value()) {
84 83
             for (Class<?> iface : child.getInterfaces()) {

+ 2
- 0
src/com/dmdirc/parser/interfaces/Parser.java Visa fil

@@ -61,6 +61,8 @@ public interface Parser {
61 61
      *
62 62
      * Disconnect from server.  This method will wait for the server to
63 63
      * close the socket.
64
+     *
65
+     * @param message Reason for quitting.
64 66
      */
65 67
     void quit(String message);
66 68
 

+ 31
- 29
src/com/dmdirc/parser/irc/IRCParser.java Visa fil

@@ -156,16 +156,16 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
156 156
     /** Connect timeout. */
157 157
     private int connectTimeout = 5000;
158 158
     /** Hashtable storing known prefix modes (ohv). */
159
-    final Map<Character, Long> prefixModes = new HashMap<Character, Long>();
159
+    final Map<Character, Long> prefixModes = new HashMap<>();
160 160
     /**
161 161
      * Hashtable maping known prefix modes (ohv) to prefixes (@%+) - Both ways.
162 162
      * Prefix map contains 2 pairs for each mode. (eg @ => o and o => @)
163 163
      */
164
-    final Map<Character, Character> prefixMap = new HashMap<Character, Character>();
164
+    final Map<Character, Character> prefixMap = new HashMap<>();
165 165
     /** Integer representing the next avaliable integer value of a prefix mode. */
166 166
     long nextKeyPrefix = 1;
167 167
     /** Hashtable storing known user modes (owxis etc). */
168
-    final Map<Character, Long> userModes = new HashMap<Character, Long>();
168
+    final Map<Character, Long> userModes = new HashMap<>();
169 169
     /** Integer representing the next avaliable integer value of a User mode. */
170 170
     long nNextKeyUser = 1;
171 171
     /**
@@ -176,7 +176,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
176 176
      * <br>
177 177
      * Channel modes discovered but not listed in 005 are stored as boolean modes automatically (and a ERROR_WARNING Error is called)
178 178
      */
179
-    final Map<Character, Long> chanModesBool = new HashMap<Character, Long>();
179
+    final Map<Character, Long> chanModesBool = new HashMap<>();
180 180
     /** Integer representing the next avaliable integer value of a Boolean mode. */
181 181
     long nextKeyCMBool = 1;
182 182
     /**
@@ -188,7 +188,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
188 188
      * see MODE_SET<br>
189 189
      * see MODE_UNSET<br>
190 190
      */
191
-    final Map<Character, Byte> chanModesOther = new HashMap<Character, Byte>();
191
+    final Map<Character, Byte> chanModesOther = new HashMap<>();
192 192
     /** The last line of input received from the server */
193 193
     private ReadLine lastLine = null;
194 194
     /** Should the lastline (where given) be appended to the "data" part of any onErrorInfo call? */
@@ -196,13 +196,13 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
196 196
     /** Channel Prefixes (ie # + etc). */
197 197
     private String chanPrefix = DEFAULT_CHAN_PREFIX;
198 198
     /** Hashtable storing all known clients based on nickname (in lowercase). */
199
-    private final Map<String, IRCClientInfo> clientList = new HashMap<String, IRCClientInfo>();
199
+    private final Map<String, IRCClientInfo> clientList = new HashMap<>();
200 200
     /** Hashtable storing all known channels based on chanel name (inc prefix - in lowercase). */
201
-    private final Map<String, IRCChannelInfo> channelList = new HashMap<String, IRCChannelInfo>();
201
+    private final Map<String, IRCChannelInfo> channelList = new HashMap<>();
202 202
     /** Reference to the ClientInfo object that references ourself. */
203 203
     private IRCClientInfo myself = new IRCClientInfo(this, "myself").setFake(true);
204 204
     /** Hashtable storing all information gathered from 005. */
205
-    final Map<String, String> h005Info = new HashMap<String, String>();
205
+    final Map<String, String> h005Info = new HashMap<>();
206 206
     /** difference in ms between our time and the servers time (used for timestampedIRC). */
207 207
     long tsdiff;
208 208
     /** Reference to the Processing Manager. */
@@ -252,9 +252,9 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
252 252
     /** The KeyManagers used for client certificates for SSL sockets. */
253 253
     private KeyManager[] myKeyManagers;
254 254
     /** This is list containing 001 - 005 inclusive. */
255
-    private final List<String> serverInformationLines = new LinkedList<String>();
255
+    private final List<String> serverInformationLines = new LinkedList<>();
256 256
     /** Map of capabilities and their state. */
257
-    private final Map<String, CapabilityState> capabilities = new HashMap<String, CapabilityState>();
257
+    private final Map<String, CapabilityState> capabilities = new HashMap<>();
258 258
 
259 259
     /**
260 260
      * Default constructor, ServerInfo and MyInfo need to be added separately (using IRC.me and IRC.server).
@@ -350,7 +350,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
350 350
 
351 351
         // Look for SRV records if no port is specified.
352 352
         if (port == -1) {
353
-            List<SRVRecord> recordList = new ArrayList<SRVRecord>();
353
+            List<SRVRecord> recordList = new ArrayList<>();
354 354
             if (isSSL) {
355 355
                 // There are a few possibilities for ssl...
356 356
                 final String[] protocols = {"_ircs._tcp.", "_irc._tls."};
@@ -414,7 +414,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
414 414
      * @return A corresponding collection of join request objects
415 415
      */
416 416
     protected Collection<? extends ChannelJoinRequest> extractChannels(final String channels) {
417
-        final List<ChannelJoinRequest> res = new ArrayList<ChannelJoinRequest>();
417
+        final List<ChannelJoinRequest> res = new ArrayList<>();
418 418
 
419 419
         for (String channel : channels.split(",")) {
420 420
             final String[] parts = channel.split(" ", 2);
@@ -528,7 +528,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
528 528
      * @return a reference to trustAllCerts
529 529
      */
530 530
     public TrustManager[] getDefaultTrustManager() {
531
-        return trustAllCerts;
531
+        return Arrays.copyOf(trustAllCerts, trustAllCerts.length);
532 532
     }
533 533
 
534 534
     /**
@@ -537,19 +537,19 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
537 537
      * @return a reference to myTrustManager;
538 538
      */
539 539
     public TrustManager[] getTrustManager() {
540
-        return myTrustManager;
540
+        return Arrays.copyOf(myTrustManager, myTrustManager.length);
541 541
     }
542 542
 
543 543
     /** {@inheritDoc} */
544 544
     @Override
545 545
     public void setTrustManagers(final TrustManager[] managers) {
546
-        myTrustManager = managers;
546
+        myTrustManager = managers == null ? null : Arrays.copyOf(managers, managers.length);
547 547
     }
548 548
 
549 549
     /** {@inheritDoc} */
550 550
     @Override
551 551
     public void setKeyManagers(final KeyManager[] managers) {
552
-        myKeyManagers = managers;
552
+        myKeyManagers = managers == null ? null : Arrays.copyOf(managers, managers.length);
553 553
     }
554 554
 
555 555
     //---------------------------------------------------------------------------
@@ -773,7 +773,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
773 773
             throw new IOException("Server port (" + target.getPort() + ") is invalid.");
774 774
         }
775 775
 
776
-        Socket mySocket = null;
776
+        Socket mySocket;
777 777
         if (proxy == null) {
778 778
             callDebugInfo(DEBUG_SOCKET, "Not using Proxy");
779 779
             mySocket = new Socket();
@@ -1078,14 +1078,13 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1078 1078
 
1079 1079
     /**
1080 1080
      * Get the trailing parameter for a line.
1081
-     * The parameter is everything after the first occurance of " :" ot the last token in the line after a space.
1081
+     * The parameter is everything after the first occurrence of " :" to the last token in the line after a space.
1082 1082
      *
1083 1083
      * @param line Line to get parameter for
1084 1084
      * @return Parameter of the line
1085 1085
      */
1086 1086
     public static String getParam(final String line) {
1087
-        String[] params = null;
1088
-        params = line.split(" :", 2);
1087
+        String[] params = line.split(" :", 2);
1089 1088
         return params[params.length - 1];
1090 1089
     }
1091 1090
 
@@ -1098,7 +1097,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1098 1097
      */
1099 1098
     public static String[] tokeniseLine(final String line) {
1100 1099
         if (line == null) {
1101
-            return new String[]{""}; // Return empty string[]
1100
+            return new String[]{""};
1102 1101
         }
1103 1102
 
1104 1103
         final int lastarg = line.indexOf(" :");
@@ -1219,7 +1218,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1219 1218
             if (channel != null) {
1220 1219
                 // This makes sure we don't add the same item to the LMQ twice,
1221 1220
                 // even if its requested twice, as the ircd will only reply once
1222
-                final Deque<Character> foundModes = new LinkedList<Character>();
1221
+                final Deque<Character> foundModes = new LinkedList<>();
1223 1222
                 final Queue<Character> listModeQueue = channel.getListModeQueue();
1224 1223
                 for (int i = 0; i < newLine[2].length(); ++i) {
1225 1224
                     final Character mode = newLine[2].charAt(i);
@@ -1256,7 +1255,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1256 1255
     @Override
1257 1256
     public List<String> getServerInformationLines() {
1258 1257
         synchronized (serverInformationLines) {
1259
-            return new LinkedList<String>(serverInformationLines);
1258
+            return new LinkedList<>(serverInformationLines);
1260 1259
         }
1261 1260
     }
1262 1261
 
@@ -1425,6 +1424,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1425 1424
     /**
1426 1425
      * Check the state of the requested capability.
1427 1426
      *
1427
+     * @param capability The capability to check the state of.
1428 1428
      * @return State of the requested capability.
1429 1429
      */
1430 1430
     public CapabilityState getCapabilityState(final String capability) {
@@ -1469,7 +1469,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1469 1469
      */
1470 1470
     public Map<String, CapabilityState> getCapabilities() {
1471 1471
         synchronized (capabilities) {
1472
-            return new HashMap<String, CapabilityState>(capabilities);
1472
+            return new HashMap<>(capabilities);
1473 1473
         }
1474 1474
     }
1475 1475
 
@@ -1478,7 +1478,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1478 1478
      */
1479 1479
     public void parseChanModes() {
1480 1480
         final StringBuilder sDefaultModes = new StringBuilder("b,k,l,");
1481
-        String[] bits = null;
1481
+        String[] bits;
1482 1482
         String modeStr;
1483 1483
         if (h005Info.containsKey("USERCHANMODES")) {
1484 1484
             if (getServerType() == ServerType.DANCER) {
@@ -1571,7 +1571,8 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1571 1571
         final char[] modes = new char[chanModesBool.size()];
1572 1572
         int i = 0;
1573 1573
         for (char mode : chanModesBool.keySet()) {
1574
-            modes[i++] = mode;
1574
+            modes[i] = mode;
1575
+            i++;
1575 1576
         }
1576 1577
         // Alphabetically sort the array
1577 1578
         Arrays.sort(modes);
@@ -1616,7 +1617,8 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1616 1617
         for (char cTemp : chanModesOther.keySet()) {
1617 1618
             nTemp = chanModesOther.get(cTemp);
1618 1619
             if (nTemp == value) {
1619
-                modes[i++] = cTemp;
1620
+                modes[i] = cTemp;
1621
+                i++;
1620 1622
             }
1621 1623
         }
1622 1624
         // Alphabetically sort the array
@@ -1726,7 +1728,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1726 1728
     public void joinChannels(final ChannelJoinRequest... channels) {
1727 1729
         // We store a map from key->channels to allow intelligent joining of
1728 1730
         // channels using as few JOIN commands as needed.
1729
-        final Map<String, StringBuffer> joinMap = new HashMap<String, StringBuffer>();
1731
+        final Map<String, StringBuffer> joinMap = new HashMap<>();
1730 1732
 
1731 1733
         for (ChannelJoinRequest channel : channels) {
1732 1734
             // Make sure we have a list to put stuff in.
@@ -2033,7 +2035,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
2033 2035
      * @return 005Info hashtable.
2034 2036
      */
2035 2037
     public Map<String, String> get005() {
2036
-        return h005Info;
2038
+        return Collections.unmodifiableMap(h005Info);
2037 2039
     }
2038 2040
 
2039 2041
     /**

Laddar…
Avbryt
Spara