瀏覽代碼

Java 7 conversions

Change-Id: I0b0f84fee719d5d2ad4ff62864ea340af07192a3
Reviewed-on: http://gerrit.dmdirc.com/2893
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.8rc1
Greg Holmes 10 年之前
父節點
當前提交
64b6878f29
共有 32 個文件被更改,包括 131 次插入145 次删除
  1. 10
    6
      src/com/dmdirc/Channel.java
  2. 4
    5
      src/com/dmdirc/actions/ActionGroup.java
  3. 1
    1
      src/com/dmdirc/actions/ActionModel.java
  4. 3
    3
      src/com/dmdirc/actions/ConditionTree.java
  5. 1
    1
      src/com/dmdirc/commandparser/PopupMenu.java
  6. 2
    2
      src/com/dmdirc/commandparser/commands/flags/CommandFlag.java
  7. 7
    7
      src/com/dmdirc/commandparser/commands/flags/CommandFlagHandler.java
  8. 1
    1
      src/com/dmdirc/commandparser/commands/global/Echo.java
  9. 11
    12
      src/com/dmdirc/logger/ProgramError.java
  10. 1
    1
      src/com/dmdirc/messages/LastCommandMessageSink.java
  11. 1
    3
      src/com/dmdirc/plugins/ExportInfo.java
  12. 3
    5
      src/com/dmdirc/plugins/ExportedService.java
  13. 1
    1
      src/com/dmdirc/plugins/GlobalClassLoader.java
  14. 1
    1
      src/com/dmdirc/plugins/PluginClassLoader.java
  15. 1
    2
      src/com/dmdirc/plugins/PluginMetaDataValidator.java
  16. 2
    2
      src/com/dmdirc/plugins/Service.java
  17. 9
    24
      src/com/dmdirc/tls/CertificateManager.java
  18. 6
    6
      src/com/dmdirc/ui/core/dialogs/sslcertificate/SSLCertificateDialogModel.java
  19. 1
    1
      src/com/dmdirc/ui/input/AdditionalTabTargets.java
  20. 1
    1
      src/com/dmdirc/ui/input/InputHandler.java
  21. 1
    1
      src/com/dmdirc/ui/input/TabCompleterResult.java
  22. 1
    1
      src/com/dmdirc/ui/messages/IRCDocumentSearcher.java
  23. 1
    2
      src/com/dmdirc/ui/messages/IRCTextAttribute.java
  24. 13
    8
      src/com/dmdirc/ui/messages/Styliser.java
  25. 13
    12
      src/com/dmdirc/updater/checking/DMDircCheckStrategy.java
  26. 1
    2
      src/com/dmdirc/updater/checking/NaiveConsolidator.java
  27. 10
    10
      src/com/dmdirc/util/resourcemanager/DMDircResourceManager.java
  28. 5
    5
      src/com/dmdirc/util/resourcemanager/FileResourceManager.java
  29. 5
    5
      src/com/dmdirc/util/resourcemanager/ZipResourceManager.java
  30. 1
    1
      test/com/dmdirc/actions/ActionComparisonNamesTest.java
  31. 1
    1
      test/com/dmdirc/actions/validators/ActionNameValidatorTest.java
  32. 12
    12
      test/com/dmdirc/updater/checking/NaiveConsolidatorTest.java

+ 10
- 6
src/com/dmdirc/Channel.java 查看文件

@@ -436,12 +436,16 @@ public class Channel extends MessageTarget implements ConfigChangeListener {
436 436
     /** {@inheritDoc} */
437 437
     @Override
438 438
     public void configChanged(final String domain, final String key) {
439
-        if ("sendwho".equals(key)) {
440
-            sendWho = getConfigManager().getOptionBool("channel", "sendwho");
441
-        } else if ("showmodeprefix".equals(key)) {
442
-            showModePrefix = getConfigManager().getOptionBool("channel", "showmodeprefix");
443
-        } else if ("shownickcoloursintext".equals(key)) {
444
-            showColours = getConfigManager().getOptionBool("ui", "shownickcoloursintext");
439
+        switch (key) {
440
+            case "sendwho":
441
+                sendWho = getConfigManager().getOptionBool("channel", "sendwho");
442
+                break;
443
+            case "showmodeprefix":
444
+                showModePrefix = getConfigManager().getOptionBool("channel", "showmodeprefix");
445
+                break;
446
+            case "shownickcoloursintext":
447
+                showColours = getConfigManager().getOptionBool("ui", "shownickcoloursintext");
448
+                break;
445 449
         }
446 450
     }
447 451
 

+ 4
- 5
src/com/dmdirc/actions/ActionGroup.java 查看文件

@@ -46,7 +46,7 @@ public class ActionGroup implements Iterable<Action> {
46 46
     private static final long serialVersionUID = 1;
47 47
 
48 48
     /** The actions in this group. */
49
-    private final List<Action> actions = new ArrayList<Action>();
49
+    private final List<Action> actions = new ArrayList<>();
50 50
 
51 51
     /** The name of this action group. */
52 52
     private final String name;
@@ -64,8 +64,7 @@ public class ActionGroup implements Iterable<Action> {
64 64
     private Version version;
65 65
 
66 66
     /** A list of settings used by this action group. */
67
-    private final Map<String, PreferencesSetting> settings
68
-            = new HashMap<String, PreferencesSetting>();
67
+    private final Map<String, PreferencesSetting> settings = new HashMap<>();
69 68
 
70 69
     /**
71 70
      * Creates a new instance of ActionGroup.
@@ -219,7 +218,7 @@ public class ActionGroup implements Iterable<Action> {
219 218
      * Removes all actions from this group, and removes all meta-data.
220 219
      */
221 220
     public void clear() {
222
-        for (Action action : new ArrayList<Action>(actions)) {
221
+        for (Action action : new ArrayList<>(actions)) {
223 222
             remove(action);
224 223
         }
225 224
 
@@ -245,7 +244,7 @@ public class ActionGroup implements Iterable<Action> {
245 244
      * @return A list of actions in this group
246 245
      */
247 246
     public List<Action> getActions() {
248
-        return new ArrayList<Action>(actions);
247
+        return new ArrayList<>(actions);
249 248
     }
250 249
 
251 250
     /**

+ 1
- 1
src/com/dmdirc/actions/ActionModel.java 查看文件

@@ -57,7 +57,7 @@ public class ActionModel {
57 57
     protected String newFormat;
58 58
 
59 59
     /** The conditions for this action. */
60
-    protected List<ActionCondition> conditions = new ArrayList<ActionCondition>();
60
+    protected List<ActionCondition> conditions = new ArrayList<>();
61 61
 
62 62
     /** The condition tree used for evaluating conditions. */
63 63
     protected ConditionTree conditionTree;

+ 3
- 3
src/com/dmdirc/actions/ConditionTree.java 查看文件

@@ -185,7 +185,7 @@ public class ConditionTree {
185 185
      * while parsing the data
186 186
      */
187 187
     public static ConditionTree parseString(final String string) {
188
-        final Deque<Object> stack = new ArrayDeque<Object>();
188
+        final Deque<Object> stack = new ArrayDeque<>();
189 189
 
190 190
         for (int i = 0; i < string.length(); i++) {
191 191
             final char m = string.charAt(i);
@@ -220,7 +220,7 @@ public class ConditionTree {
220 220
      * while parsing the data.
221 221
      */
222 222
     private static ConditionTree parseStack(final Deque<Object> stack) {
223
-        final Deque<Object> myStack = new ArrayDeque<Object>();
223
+        final Deque<Object> myStack = new ArrayDeque<>();
224 224
 
225 225
         while (!stack.isEmpty()) {
226 226
             final Object object = stack.poll();
@@ -318,7 +318,7 @@ public class ConditionTree {
318 318
      * mismatched.
319 319
      */
320 320
     private static ConditionTree readBracket(final Deque<Object> stack) {
321
-        final Deque<Object> tempStack = new ArrayDeque<Object>();
321
+        final Deque<Object> tempStack = new ArrayDeque<>();
322 322
         boolean found = false;
323 323
 
324 324
         while (!found && !stack.isEmpty()) {

+ 1
- 1
src/com/dmdirc/commandparser/PopupMenu.java 查看文件

@@ -32,7 +32,7 @@ import java.util.List;
32 32
 public class PopupMenu {
33 33
 
34 34
     /** The items contained within this popup menu. */
35
-    private final List<PopupMenuItem> items = new ArrayList<PopupMenuItem>();
35
+    private final List<PopupMenuItem> items = new ArrayList<>();
36 36
 
37 37
     /**
38 38
      * Retrieves a list of items contained within this popup menu.

+ 2
- 2
src/com/dmdirc/commandparser/commands/flags/CommandFlag.java 查看文件

@@ -43,9 +43,9 @@ public class CommandFlag {
43 43
     /** The name of the flag. */
44 44
     private final String name;
45 45
     /** The list of flags that become enabled if this one is used. */
46
-    private final List<CommandFlag> enables = new LinkedList<CommandFlag>();
46
+    private final List<CommandFlag> enables = new LinkedList<>();
47 47
     /** The list of flags that become disabled if this one is used. */
48
-    private final List<CommandFlag> disables = new LinkedList<CommandFlag>();
48
+    private final List<CommandFlag> disables = new LinkedList<>();
49 49
     /** The number of args expected following this flag. */
50 50
     private final int immediateArgs;
51 51
     /** The number of args expected after flags are finished. */

+ 7
- 7
src/com/dmdirc/commandparser/commands/flags/CommandFlagHandler.java 查看文件

@@ -40,13 +40,13 @@ import java.util.Map;
40 40
 public class CommandFlagHandler {
41 41
 
42 42
     /** A map of all known flag names to their flag objects. */
43
-    private final Map<String, CommandFlag> flags = new HashMap<String, CommandFlag>();
43
+    private final Map<String, CommandFlag> flags = new HashMap<>();
44 44
     /** A map of currently enabled flag names to their flag objects. */
45
-    private final Map<String, CommandFlag> enabledFlags = new HashMap<String, CommandFlag>();
45
+    private final Map<String, CommandFlag> enabledFlags = new HashMap<>();
46 46
     /** A map of currently disabled flag names to their flag objects. */
47
-    private final Map<String, CommandFlag> disabledFlags = new HashMap<String, CommandFlag>();
47
+    private final Map<String, CommandFlag> disabledFlags = new HashMap<>();
48 48
     /** A map of disabled flag names to the flag objects that caused them to be disabled. */
49
-    private final Map<String, CommandFlag> disabledBy = new HashMap<String, CommandFlag>();
49
+    private final Map<String, CommandFlag> disabledBy = new HashMap<>();
50 50
 
51 51
     /**
52 52
      * Creates a new command flag handler which will handle all of the specified
@@ -98,8 +98,8 @@ public class CommandFlagHandler {
98 98
             (flag.isEnabled() ? enabledFlags : disabledFlags).put(flag.getName(), flag);
99 99
         }
100 100
 
101
-        final Map<CommandFlag, Integer> results = new HashMap<CommandFlag, Integer>();
102
-        final List<CommandFlag> delayedFlags = new ArrayList<CommandFlag>(flags.size());
101
+        final Map<CommandFlag, Integer> results = new HashMap<>();
102
+        final List<CommandFlag> delayedFlags = new ArrayList<>(flags.size());
103 103
 
104 104
         int offset;
105 105
         for (offset = 0; offset < arguments.getArguments().length; offset++) {
@@ -221,7 +221,7 @@ public class CommandFlagHandler {
221 221
      * specified flag.
222 222
      */
223 223
     protected String getEnablers(final CommandFlag flag) {
224
-        final List<CommandFlag> enablers = new LinkedList<CommandFlag>();
224
+        final List<CommandFlag> enablers = new LinkedList<>();
225 225
 
226 226
         for (CommandFlag target : flags.values()) {
227 227
             if (target.getEnables().contains(flag)) {

+ 1
- 1
src/com/dmdirc/commandparser/commands/global/Echo.java 查看文件

@@ -137,7 +137,7 @@ public class Echo extends Command implements IntelligentCommand {
137 137
                 || (arg == 3 && context.getPreviousArgs().get(2).equals("--target")
138 138
                 && context.getPreviousArgs().get(0).equals("--ts"))) {
139 139
 
140
-            final List<FrameContainer> windowList = new ArrayList<FrameContainer>();
140
+            final List<FrameContainer> windowList = new ArrayList<>();
141 141
             final Server currentServer = context.getWindow().getServer();
142 142
 
143 143
             //Active window's Children

+ 11
- 12
src/com/dmdirc/logger/ProgramError.java 查看文件

@@ -248,17 +248,16 @@ public final class ProgramError implements Serializable {
248 248
      * Saves this error to disk.
249 249
      */
250 250
     public void save() {
251
-        final PrintWriter out = new PrintWriter(getErrorFile(), true);
252
-        out.println("Date:" + getDate());
253
-        out.println("Level: " + getLevel());
254
-        out.println("Description: " + getMessage());
255
-        out.println("Details:");
256
-
257
-        for (String traceLine : getTrace()) {
258
-            out.println('\t' + traceLine);
251
+        try (PrintWriter out = new PrintWriter(getErrorFile(), true)) {
252
+            out.println("Date:" + getDate());
253
+            out.println("Level: " + getLevel());
254
+            out.println("Description: " + getMessage());
255
+            out.println("Details:");
256
+
257
+            for (String traceLine : getTrace()) {
258
+                out.println('\t' + traceLine);
259
+            }
259 260
         }
260
-
261
-        out.close();
262 261
     }
263 262
 
264 263
     /**
@@ -304,8 +303,8 @@ public final class ProgramError implements Serializable {
304 303
      * Sends this error report to the DMDirc developers.
305 304
      */
306 305
     public void send() {
307
-        final Map<String, String> postData = new HashMap<String, String>();
308
-        List<String> response = new ArrayList<String>();
306
+        final Map<String, String> postData = new HashMap<>();
307
+        List<String> response = new ArrayList<>();
309 308
         int tries = 0;
310 309
 
311 310
         String traceString = Arrays.toString(getTrace());

+ 1
- 1
src/com/dmdirc/messages/LastCommandMessageSink.java 查看文件

@@ -63,7 +63,7 @@ public class LastCommandMessageSink implements MessageSink {
63 63
         WritableFrameContainer best = source;
64 64
         long besttime = 0;
65 65
 
66
-        final List<FrameContainer> containers = new ArrayList<FrameContainer>();
66
+        final List<FrameContainer> containers = new ArrayList<>();
67 67
 
68 68
         containers.add(source.getServer());
69 69
         containers.addAll(source.getServer().getChildren());

+ 1
- 3
src/com/dmdirc/plugins/ExportInfo.java 查看文件

@@ -54,9 +54,7 @@ public class ExportInfo {
54 54
             final Class<?> c = pluginInfo.getPluginClassLoader().loadClass(className, false);
55 55
             final Plugin p = className.equals(pluginInfo.getMetaData().getMainClass()) ? pluginInfo.getPlugin() : null;
56 56
             return new ExportedService(c, methodName, p);
57
-        } catch (ClassNotFoundException cnfe) {
58
-            return null;
59
-        } catch (IllegalArgumentException ex) {
57
+        } catch (ClassNotFoundException | IllegalArgumentException cnfe) {
60 58
             return null;
61 59
         }
62 60
     }

+ 3
- 5
src/com/dmdirc/plugins/ExportedService.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.plugins;
24 24
 
25
+import java.lang.reflect.InvocationTargetException;
25 26
 import java.lang.reflect.Method;
26 27
 
27 28
 import lombok.extern.slf4j.Slf4j;
@@ -84,14 +85,11 @@ public class ExportedService {
84 85
     public Object execute(final Object... args) {
85 86
         try {
86 87
             return method.invoke(object, args);
87
-        } catch (final LinkageError le) {
88
+        } catch (final LinkageError | IllegalAccessException |
89
+                IllegalArgumentException | InvocationTargetException le) {
88 90
             log.error("Error with exported service calling {}",
89 91
                     method, le);
90 92
             return null;
91
-        } catch (final Exception e) {
92
-            log.error("Error with exported service calling {}",
93
-                    method, e);
94
-            return null;
95 93
         }
96 94
     }
97 95
 

+ 1
- 1
src/com/dmdirc/plugins/GlobalClassLoader.java 查看文件

@@ -35,7 +35,7 @@ import java.util.Map;
35 35
 public final class GlobalClassLoader extends ClassLoader {
36 36
 
37 37
     /** HashMap containing sources of Global class files. */
38
-    private final Map<String, String> resourcesList = new HashMap<String, String>();
38
+    private final Map<String, String> resourcesList = new HashMap<>();
39 39
 
40 40
     /** Plugin Manager that owns this GlobalClassLoader. */
41 41
     private final PluginManager manager;

+ 1
- 1
src/com/dmdirc/plugins/PluginClassLoader.java 查看文件

@@ -211,7 +211,7 @@ public class PluginClassLoader extends ClassLoader {
211 211
     protected Enumeration<URL> findResources(final String name)
212 212
             throws IOException {
213 213
         final URL resource = findResource(name);
214
-        final List<URL> resources = new ArrayList<URL>();
214
+        final List<URL> resources = new ArrayList<>();
215 215
 
216 216
         if (resource != null) {
217 217
             resources.add(resource);

+ 1
- 2
src/com/dmdirc/plugins/PluginMetaDataValidator.java 查看文件

@@ -43,8 +43,7 @@ public class PluginMetaDataValidator {
43 43
     private final PluginMetaData metadata;
44 44
 
45 45
     /** A collection of errors which have been identified. */
46
-    private final Collection<String> errors
47
-            = new ArrayList<String>();
46
+    private final Collection<String> errors = new ArrayList<>();
48 47
 
49 48
     /**
50 49
      * Creates a new metadata validator.

+ 2
- 2
src/com/dmdirc/plugins/Service.java 查看文件

@@ -37,7 +37,7 @@ public class Service {
37 37
     private final String name;
38 38
 
39 39
     /** List of ServiceProviders that implement this service. */
40
-    private final List<ServiceProvider> serviceproviders = new ArrayList<ServiceProvider>();
40
+    private final List<ServiceProvider> serviceproviders = new ArrayList<>();
41 41
 
42 42
     /**
43 43
      * Create a new Service.
@@ -92,7 +92,7 @@ public class Service {
92 92
      * @return List of ServiceProvider that provide this service
93 93
      */
94 94
     public List<ServiceProvider> getProviders() {
95
-        return new ArrayList<ServiceProvider>(serviceproviders);
95
+        return new ArrayList<>(serviceproviders);
96 96
     }
97 97
 
98 98
     /**

+ 9
- 24
src/com/dmdirc/tls/CertificateManager.java 查看文件

@@ -33,11 +33,11 @@ import java.io.File;
33 33
 import java.io.FileInputStream;
34 34
 import java.io.FileNotFoundException;
35 35
 import java.io.IOException;
36
+import java.security.GeneralSecurityException;
36 37
 import java.security.InvalidAlgorithmParameterException;
37 38
 import java.security.KeyStore;
38 39
 import java.security.KeyStoreException;
39 40
 import java.security.NoSuchAlgorithmException;
40
-import java.security.UnrecoverableKeyException;
41 41
 import java.security.cert.CertificateException;
42 42
 import java.security.cert.CertificateParsingException;
43 43
 import java.security.cert.PKIXParameters;
@@ -80,7 +80,7 @@ public class CertificateManager implements X509TrustManager {
80 80
     private final AggregateConfigProvider config;
81 81
 
82 82
     /** The set of CAs from the global cacert file. */
83
-    private final Set<X509Certificate> globalTrustedCAs = new HashSet<X509Certificate>();
83
+    private final Set<X509Certificate> globalTrustedCAs = new HashSet<>();
84 84
 
85 85
     /** Whether or not to check specified parts of the certificate. */
86 86
     private boolean checkDate, checkIssuer, checkHost;
@@ -92,7 +92,7 @@ public class CertificateManager implements X509TrustManager {
92 92
     private CertificateAction action;
93 93
 
94 94
     /** A list of problems encountered most recently. */
95
-    private final List<CertificateException> problems = new ArrayList<CertificateException>();
95
+    private final List<CertificateException> problems = new ArrayList<>();
96 96
 
97 97
     /** The chain of certificates currently being validated. */
98 98
     private X509Certificate[] chain;
@@ -131,15 +131,8 @@ public class CertificateManager implements X509TrustManager {
131 131
             for (TrustAnchor anchor : params.getTrustAnchors()) {
132 132
                 globalTrustedCAs.add(anchor.getTrustedCert());
133 133
             }
134
-        } catch (CertificateException ex) {
135
-            Logger.userError(ErrorLevel.MEDIUM, "Unable to load trusted certificates", ex);
136
-        } catch (IOException ex) {
137
-            Logger.userError(ErrorLevel.MEDIUM, "Unable to load trusted certificates", ex);
138
-        } catch (InvalidAlgorithmParameterException ex) {
139
-            Logger.userError(ErrorLevel.MEDIUM, "Unable to load trusted certificates", ex);
140
-        } catch (KeyStoreException ex) {
141
-            Logger.userError(ErrorLevel.MEDIUM, "Unable to load trusted certificates", ex);
142
-        } catch (NoSuchAlgorithmException ex) {
134
+        } catch (CertificateException | IOException | InvalidAlgorithmParameterException |
135
+                KeyStoreException | NoSuchAlgorithmException ex) {
143 136
             Logger.userError(ErrorLevel.MEDIUM, "Unable to load trusted certificates", ex);
144 137
         } finally {
145 138
             StreamUtils.close(is);
@@ -175,15 +168,7 @@ public class CertificateManager implements X509TrustManager {
175 168
                 return kmf.getKeyManagers();
176 169
             } catch (FileNotFoundException ex) {
177 170
                 Logger.userError(ErrorLevel.MEDIUM, "Certificate file not found", ex);
178
-            } catch (KeyStoreException ex) {
179
-                Logger.appError(ErrorLevel.MEDIUM, "Unable to get key manager", ex);
180
-            } catch (IOException ex) {
181
-                Logger.userError(ErrorLevel.MEDIUM, "Unable to get key manager", ex);
182
-            } catch (CertificateException ex) {
183
-                Logger.appError(ErrorLevel.MEDIUM, "Unable to get key manager", ex);
184
-            } catch (NoSuchAlgorithmException ex) {
185
-                Logger.appError(ErrorLevel.MEDIUM, "Unable to get key manager", ex);
186
-            } catch (UnrecoverableKeyException ex) {
171
+            } catch (GeneralSecurityException | IOException ex) {
187 172
                 Logger.appError(ErrorLevel.MEDIUM, "Unable to get key manager", ex);
188 173
             } finally {
189 174
                 StreamUtils.close(fis);
@@ -225,7 +210,7 @@ public class CertificateManager implements X509TrustManager {
225 210
                     }
226 211
                 }
227 212
             }
228
-        } catch (Exception ex) {
213
+        } catch (GeneralSecurityException ex) {
229 214
            return TrustResult.UNTRUSTED_EXCEPTION;
230 215
         }
231 216
 
@@ -362,7 +347,7 @@ public class CertificateManager implements X509TrustManager {
362 347
                 case DISCONNECT:
363 348
                     throw new CertificateException("Not trusted");
364 349
                 case IGNORE_PERMANENTY:
365
-                    final List<String> list = new ArrayList<String>(config
350
+                    final List<String> list = new ArrayList<>(config
366 351
                             .getOptionList("ssl", "trusted"));
367 352
                     list.add(Base64.encodeToString(chain[0].getSignature(), false));
368 353
                     IdentityManager.getIdentityManager().getUserSettings()
@@ -426,7 +411,7 @@ public class CertificateManager implements X509TrustManager {
426 411
      * name
427 412
      */
428 413
     public static Map<String, String> getDNFieldsFromCert(final X509Certificate cert) {
429
-        final Map<String, String> res = new HashMap<String, String>();
414
+        final Map<String, String> res = new HashMap<>();
430 415
 
431 416
         try {
432 417
             final LdapName name = new LdapName(cert.getSubjectX500Principal().getName());

+ 6
- 6
src/com/dmdirc/ui/core/dialogs/sslcertificate/SSLCertificateDialogModel.java 查看文件

@@ -78,7 +78,7 @@ public class SSLCertificateDialogModel {
78 78
      * certificate chain being questioned.
79 79
      */
80 80
     public List<CertificateChainEntry> getCertificateChain() {
81
-        final List<CertificateChainEntry> res = new ArrayList<CertificateChainEntry>();
81
+        final List<CertificateChainEntry> res = new ArrayList<>();
82 82
 
83 83
         boolean first = true;
84 84
 
@@ -109,7 +109,7 @@ public class SSLCertificateDialogModel {
109 109
      */
110 110
     public List<List<CertificateInformationEntry>> getCertificateInfo(final int index) {
111 111
         final List<List<CertificateInformationEntry>> res
112
-                = new ArrayList<List<CertificateInformationEntry>>();
112
+                = new ArrayList<>();
113 113
         final X509Certificate cert = chain[index];
114 114
         List<CertificateInformationEntry> group;
115 115
 
@@ -123,7 +123,7 @@ public class SSLCertificateDialogModel {
123 123
             tooNew = true;
124 124
         }
125 125
 
126
-        group = new ArrayList<CertificateInformationEntry>();
126
+        group = new ArrayList<>();
127 127
         group.add(new CertificateInformationEntry("Valid from",
128 128
                 cert.getNotBefore().toString(), tooNew, false));
129 129
         group.add(new CertificateInformationEntry("Valid to",
@@ -134,7 +134,7 @@ public class SSLCertificateDialogModel {
134 134
         final String names = getAlternateNames(cert);
135 135
         final Map<String, String> fields = CertificateManager.getDNFieldsFromCert(cert);
136 136
 
137
-        group = new ArrayList<CertificateInformationEntry>();
137
+        group = new ArrayList<>();
138 138
         addCertField(fields, group, "Common name", "CN", wrongName);
139 139
 
140 140
         group.add(new CertificateInformationEntry("Alternate names",
@@ -147,7 +147,7 @@ public class SSLCertificateDialogModel {
147 147
         addCertField(fields, group, "Country", "C", false);
148 148
         res.add(group);
149 149
 
150
-        group = new ArrayList<CertificateInformationEntry>();
150
+        group = new ArrayList<>();
151 151
         group.add(new CertificateInformationEntry("Serial number",
152 152
                 cert.getSerialNumber().toString(), false, false));
153 153
         group.add(new CertificateInformationEntry("Algorithm",
@@ -217,7 +217,7 @@ public class SSLCertificateDialogModel {
217 217
      * @return A list of summary entries
218 218
      */
219 219
     public List<CertificateSummaryEntry> getSummary() {
220
-        final List<CertificateSummaryEntry> res = new ArrayList<CertificateSummaryEntry>();
220
+        final List<CertificateSummaryEntry> res = new ArrayList<>();
221 221
 
222 222
         boolean outofdate = false, wronghost = false, nottrusted = false;
223 223
 

+ 1
- 1
src/com/dmdirc/ui/input/AdditionalTabTargets.java 查看文件

@@ -41,7 +41,7 @@ public final class AdditionalTabTargets extends ArrayList<String> {
41 41
 
42 42
     /** Whether to include normal targets. */
43 43
     private List<TabCompletionType> includes
44
-            = new ArrayList<TabCompletionType>(Arrays.asList(TabCompletionType.values()));
44
+            = new ArrayList<>(Arrays.asList(TabCompletionType.values()));
45 45
 
46 46
     /**
47 47
      * Determines if the specified type of completion should be used.

+ 1
- 1
src/com/dmdirc/ui/input/InputHandler.java 查看文件

@@ -472,7 +472,7 @@ public abstract class InputHandler implements ConfigChangeListener {
472 472
      * @return A copy of the input backbuffer.
473 473
      */
474 474
     public List<String> getBackBuffer() {
475
-        return new ArrayList<String>(buffer.getList());
475
+        return new ArrayList<>(buffer.getList());
476 476
     }
477 477
 
478 478
     /**

+ 1
- 1
src/com/dmdirc/ui/input/TabCompleterResult.java 查看文件

@@ -42,7 +42,7 @@ public final class TabCompleterResult {
42 42
      * Creates a new instance of TabCompleterResult with an empty result set.
43 43
      */
44 44
     public TabCompleterResult() {
45
-        this.results = new ArrayList<String>();
45
+        this.results = new ArrayList<>();
46 46
     }
47 47
 
48 48
     /**

+ 1
- 1
src/com/dmdirc/ui/messages/IRCDocumentSearcher.java 查看文件

@@ -167,7 +167,7 @@ public class IRCDocumentSearcher {
167 167
      * @return List of matches
168 168
      */
169 169
     private List<LinePosition> searchLine(final int lineNum, final String line) {
170
-        final List<LinePosition> matches = new ArrayList<LinePosition>();
170
+        final List<LinePosition> matches = new ArrayList<>();
171 171
         final Matcher matcher = Pattern.compile((caseSensitive ? "" : "(?i)")
172 172
                 + "\\Q" + phrase + "\\E").matcher(line);
173 173
 

+ 1
- 2
src/com/dmdirc/ui/messages/IRCTextAttribute.java 查看文件

@@ -41,8 +41,7 @@ public final class IRCTextAttribute extends Attribute {
41 41
     private static final long serialVersionUID = 1;
42 42
 
43 43
     /** table of all instances in this class, used by readResolve. */
44
-    private static final Map<String, IRCTextAttribute> INSTANCE_MAP
45
-            = new HashMap<String, IRCTextAttribute>(1);
44
+    private static final Map<String, IRCTextAttribute> INSTANCE_MAP = new HashMap<>(1);
46 45
 
47 46
     /**
48 47
      * Constructs an Attribute with the given name.

+ 13
- 8
src/com/dmdirc/ui/messages/Styliser.java 查看文件

@@ -876,14 +876,19 @@ public class Styliser implements ConfigChangeListener {
876 876
     /** {@inheritDoc} */
877 877
     @Override
878 878
     public void configChanged(final String domain, final String key) {
879
-        if ("stylelinks".equals(key)) {
880
-            styleURIs = configManager.getOptionBool("ui", "stylelinks");
881
-        } else if ("stylechannels".equals(key)) {
882
-            styleChannels = configManager.getOptionBool("ui", "stylechannels");
883
-        } else if ("linkcolour".equals(key)) {
884
-            uriColour = configManager.getOptionColour("ui", "linkcolour");
885
-        } else if ("channelcolour".equals(key)) {
886
-            channelColour = configManager.getOptionColour("ui", "channelcolour");
879
+        switch (key) {
880
+            case "stylelinks":
881
+                styleURIs = configManager.getOptionBool("ui", "stylelinks");
882
+                break;
883
+            case "stylechannels":
884
+                styleChannels = configManager.getOptionBool("ui", "stylechannels");
885
+                break;
886
+            case "linkcolour":
887
+                uriColour = configManager.getOptionColour("ui", "linkcolour");
888
+                break;
889
+            case "channelcolour":
890
+                channelColour = configManager.getOptionColour("ui", "channelcolour");
891
+                break;
887 892
         }
888 893
     }
889 894
 

+ 13
- 12
src/com/dmdirc/updater/checking/DMDircCheckStrategy.java 查看文件

@@ -57,8 +57,7 @@ public class DMDircCheckStrategy implements UpdateCheckStrategy {
57 57
     /** {@inheritDoc} */
58 58
     @Override
59 59
     public Map<UpdateComponent, UpdateCheckResult> checkForUpdates(final Collection<UpdateComponent> components) {
60
-        final Map<UpdateComponent, UpdateCheckResult> res
61
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
60
+        final Map<UpdateComponent, UpdateCheckResult> res = new HashMap<>();
62 61
         final Map<String, UpdateComponent> names = getComponentsByName(components);
63 62
 
64 63
         try {
@@ -139,15 +138,17 @@ public class DMDircCheckStrategy implements UpdateCheckStrategy {
139 138
     private UpdateCheckResult parseResponse(final UpdateComponent component,
140 139
             final String line) {
141 140
         final String[] parts = line.split(" ");
142
-
143
-        if ("outofdate".equals(parts[0])) {
144
-            return parseOutOfDateResponse(component, parts);
145
-        } else if ("uptodate".equals(parts[0])) {
146
-            return new BaseCheckResult(component);
147
-        } else if ("error".equals(parts[0])) {
148
-            log.warn("Error received from update server: {}", line);
149
-        } else {
150
-            log.error("Unknown update line received from server: {}", line);
141
+        switch (parts[0]) {
142
+            case "outofdate":
143
+                return parseOutOfDateResponse(component, parts);
144
+            case "uptodate":
145
+                return new BaseCheckResult(component);
146
+            case "error":
147
+                log.warn("Error received from update server: {}", line);
148
+                break;
149
+            default:
150
+                log.error("Unknown update line received from server: {}", line);
151
+                break;
151 152
         }
152 153
 
153 154
         return null;
@@ -181,7 +182,7 @@ public class DMDircCheckStrategy implements UpdateCheckStrategy {
181 182
      * which the component's name as a key and the component itself as a value.
182 183
      */
183 184
     private Map<String, UpdateComponent> getComponentsByName(final Collection<UpdateComponent> components) {
184
-        final Map<String, UpdateComponent> res = new HashMap<String, UpdateComponent>();
185
+        final Map<String, UpdateComponent> res = new HashMap<>();
185 186
 
186 187
         for (UpdateComponent component : components) {
187 188
             res.put(component.getName(), component);

+ 1
- 2
src/com/dmdirc/updater/checking/NaiveConsolidator.java 查看文件

@@ -38,8 +38,7 @@ public class NaiveConsolidator implements CheckResultConsolidator {
38 38
     @Override
39 39
     public Map<UpdateComponent, UpdateCheckResult> consolidate(
40 40
             final Collection<Map<UpdateComponent, UpdateCheckResult>> results) {
41
-        final Map<UpdateComponent, UpdateCheckResult> res
42
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
41
+        final Map<UpdateComponent, UpdateCheckResult> res = new HashMap<>();
43 42
 
44 43
         for (Map<UpdateComponent, UpdateCheckResult> set : results) {
45 44
             for (Map.Entry<UpdateComponent, UpdateCheckResult> entry : set.entrySet()) {

+ 10
- 10
src/com/dmdirc/util/resourcemanager/DMDircResourceManager.java 查看文件

@@ -38,6 +38,10 @@ import java.net.URLDecoder;
38 38
  */
39 39
 public class DMDircResourceManager {
40 40
 
41
+    private DMDircResourceManager() {
42
+        //Prevent instantiation
43
+    }
44
+
41 45
     /**
42 46
      * Returns the working directory for the application.
43 47
      *
@@ -57,8 +61,7 @@ public class DMDircResourceManager {
57 61
      */
58 62
     public static String getWorkingDirectoryString(final URL mainClassURL) {
59 63
         try {
60
-            return URLDecoder.decode(
61
-                    getWorkingDirectoryURL(mainClassURL).getPath(), "UTF-8");
64
+            return URLDecoder.decode(getWorkingDirectoryURL(mainClassURL).getPath(), "UTF-8");
62 65
         } catch (UnsupportedEncodingException ex) {
63 66
             Logger.userError(ErrorLevel.MEDIUM, "Unable to decode path");
64 67
         }
@@ -86,8 +89,7 @@ public class DMDircResourceManager {
86 89
      * @return URL of client folder file or null
87 90
      */
88 91
     protected static URL getFileURL() {
89
-        return Thread.currentThread().getContextClassLoader()
90
-                    .getResource("");
92
+        return Thread.currentThread().getContextClassLoader().getResource("");
91 93
     }
92 94
 
93 95
     /**
@@ -99,11 +101,9 @@ public class DMDircResourceManager {
99 101
      */
100 102
     protected static URL getJarURL(final URL mainClassURL) {
101 103
         try {
102
-            return new URI(mainClassURL.getPath()
103
-                    .substring(0,mainClassURL.getPath().indexOf("!/"))).toURL();
104
-        } catch(MalformedURLException ex) {
105
-            return null;
106
-        } catch (URISyntaxException ex) {
104
+            return new URI(mainClassURL.getPath().substring(0, mainClassURL.getPath()
105
+                    .indexOf("!/"))).toURL();
106
+        } catch (MalformedURLException | URISyntaxException ex) {
107 107
             return null;
108 108
         }
109 109
     }
@@ -115,7 +115,7 @@ public class DMDircResourceManager {
115 115
      */
116 116
     public static boolean isRunningFromJar() {
117 117
         return isRunningFromJar(Thread.currentThread().getContextClassLoader().
118
-                        getResource("com/dmdirc/Main.class"));
118
+                getResource("com/dmdirc/Main.class"));
119 119
 
120 120
     }
121 121
 

+ 5
- 5
src/com/dmdirc/util/resourcemanager/FileResourceManager.java 查看文件

@@ -145,7 +145,7 @@ public final class FileResourceManager extends ResourceManager {
145 145
     public Map<String, byte[]> getResourcesEndingWithAsBytes(
146 146
             final String resourcesSuffix) {
147 147
         final List<File> files = getFileListing(new File(basePath));
148
-        final Map<String, byte[]> resources = new HashMap<String, byte[]>();
148
+        final Map<String, byte[]> resources = new HashMap<>();
149 149
 
150 150
         for (File file : files) {
151 151
             final String path = file.getPath().substring(basePath.length(),
@@ -163,7 +163,7 @@ public final class FileResourceManager extends ResourceManager {
163 163
     public Map<String, byte[]> getResourcesStartingWithAsBytes(
164 164
             final String resourcesPrefix) {
165 165
         final List<File> files = getFileListing(new File(basePath));
166
-        final Map<String, byte[]> resources = new HashMap<String, byte[]>();
166
+        final Map<String, byte[]> resources = new HashMap<>();
167 167
 
168 168
         for (File file : files) {
169 169
             final String path = file.getPath().substring(basePath.length(),
@@ -181,7 +181,7 @@ public final class FileResourceManager extends ResourceManager {
181 181
     public Map<String, InputStream> getResourcesStartingWithAsInputStreams(
182 182
             final String resourcesPrefix) {
183 183
         final List<File> files = getFileListing(new File(basePath));
184
-        final Map<String, InputStream> resources = new HashMap<String, InputStream>();
184
+        final Map<String, InputStream> resources = new HashMap<>();
185 185
 
186 186
         for (File file : files) {
187 187
             final String path = file.getPath().substring(basePath.length(),
@@ -198,7 +198,7 @@ public final class FileResourceManager extends ResourceManager {
198 198
     @Override
199 199
     public List<String> getResourcesStartingWith(final String resourcesPrefix) {
200 200
         final List<File> files = getFileListing(new File(basePath));
201
-        final List<String> resources = new ArrayList<String>();
201
+        final List<String> resources = new ArrayList<>();
202 202
 
203 203
         for (File file : files) {
204 204
             final String path = file.getPath().substring(basePath.length(),
@@ -219,7 +219,7 @@ public final class FileResourceManager extends ResourceManager {
219 219
      * @return Recursive directory listing
220 220
      */
221 221
     private static List<File> getFileListing(final File startingDirectory) {
222
-        final List<File> result = new ArrayList<File>();
222
+        final List<File> result = new ArrayList<>();
223 223
 
224 224
         if (startingDirectory.listFiles() == null) {
225 225
             return result;

+ 5
- 5
src/com/dmdirc/util/resourcemanager/ZipResourceManager.java 查看文件

@@ -77,7 +77,7 @@ public final class ZipResourceManager extends ResourceManager {
77 77
     protected ZipResourceManager(final ZipFile file) {
78 78
         super();
79 79
         zipFile = file;
80
-        entries = new ArrayList<String>();
80
+        entries = new ArrayList<>();
81 81
         final Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
82 82
         while (zipEntries.hasMoreElements()) {
83 83
             entries.add(zipEntries.nextElement().getName());
@@ -169,7 +169,7 @@ public final class ZipResourceManager extends ResourceManager {
169 169
     @Override
170 170
     public Map<String, byte[]> getResourcesEndingWithAsBytes(
171 171
             final String resourcesSuffix) {
172
-        final Map<String, byte[]> resources = new HashMap<String, byte[]>();
172
+        final Map<String, byte[]> resources = new HashMap<>();
173 173
 
174 174
         for (String entry : entries) {
175 175
             if (entry.endsWith(resourcesSuffix)) {
@@ -184,7 +184,7 @@ public final class ZipResourceManager extends ResourceManager {
184 184
     @Override
185 185
     public Map<String, byte[]> getResourcesStartingWithAsBytes(
186 186
             final String resourcesPrefix) {
187
-        final Map<String, byte[]> resources = new HashMap<String, byte[]>();
187
+        final Map<String, byte[]> resources = new HashMap<>();
188 188
 
189 189
         for (String entry : entries) {
190 190
             if (entry.startsWith(resourcesPrefix)) {
@@ -200,7 +200,7 @@ public final class ZipResourceManager extends ResourceManager {
200 200
     public Map<String, InputStream> getResourcesStartingWithAsInputStreams(
201 201
             final String resourcesPrefix) {
202 202
         final Map<String, InputStream> resources =
203
-                new HashMap<String, InputStream>();
203
+                new HashMap<>();
204 204
 
205 205
         for (String entry : entries) {
206 206
             if (entry.startsWith(resourcesPrefix)) {
@@ -214,7 +214,7 @@ public final class ZipResourceManager extends ResourceManager {
214 214
     /** {@inheritDoc} */
215 215
     @Override
216 216
     public List<String> getResourcesStartingWith(final String resourcesPrefix) {
217
-        final List<String> resources = new ArrayList<String>();
217
+        final List<String> resources = new ArrayList<>();
218 218
 
219 219
         for (String entry : entries) {
220 220
             if (entry.startsWith(resourcesPrefix)) {

+ 1
- 1
test/com/dmdirc/actions/ActionComparisonNamesTest.java 查看文件

@@ -51,7 +51,7 @@ public class ActionComparisonNamesTest {
51 51
 
52 52
     @Parameterized.Parameters
53 53
     public static List<Object[]> data() {
54
-        final List<Object[]> res = new LinkedList<Object[]>();
54
+        final List<Object[]> res = new LinkedList<>();
55 55
 
56 56
         for (ActionComparison comp : CoreActionComparison.values()) {
57 57
             res.add(new Object[]{comp});

+ 1
- 1
test/com/dmdirc/actions/validators/ActionNameValidatorTest.java 查看文件

@@ -35,7 +35,7 @@ import static org.mockito.Mockito.*;
35 35
 public class ActionNameValidatorTest {
36 36
 
37 37
     private ActionGroup getGroup() {
38
-        final List<Action> actions = new ArrayList<Action>();
38
+        final List<Action> actions = new ArrayList<>();
39 39
         final Action action1 = mock(Action.class);
40 40
         final Action action2 = mock(Action.class);
41 41
         final ActionGroup group = mock(ActionGroup.class);

+ 12
- 12
test/com/dmdirc/updater/checking/NaiveConsolidatorTest.java 查看文件

@@ -45,9 +45,9 @@ public class NaiveConsolidatorTest {
45 45
     @Before
46 46
     public void setUp() {
47 47
         consolidator = new NaiveConsolidator();
48
-        components = new ArrayList<UpdateComponent>();
49
-        positiveResults = new ArrayList<UpdateCheckResult>();
50
-        negativeResults = new ArrayList<UpdateCheckResult>();
48
+        components = new ArrayList<>();
49
+        positiveResults = new ArrayList<>();
50
+        negativeResults = new ArrayList<>();
51 51
 
52 52
         for (int i = 0; i < 4; i++) {
53 53
             final UpdateComponent component = mock(UpdateComponent.class);
@@ -67,11 +67,11 @@ public class NaiveConsolidatorTest {
67 67
     @Test
68 68
     public void testIncludesAllComponentsFromAllMaps() {
69 69
         final Map<UpdateComponent, UpdateCheckResult> map1
70
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
70
+                = new HashMap<>();
71 71
         final Map<UpdateComponent, UpdateCheckResult> map2
72
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
72
+                = new HashMap<>();
73 73
         final List<Map<UpdateComponent, UpdateCheckResult>> maps
74
-                = new ArrayList<Map<UpdateComponent, UpdateCheckResult>>();
74
+                = new ArrayList<>();
75 75
 
76 76
         map1.put(components.get(0), negativeResults.get(0));
77 77
         map1.put(components.get(1), negativeResults.get(1));
@@ -90,11 +90,11 @@ public class NaiveConsolidatorTest {
90 90
     @Test
91 91
     public void testIncludesPositiveResultsForKnownNegativeComponents() {
92 92
         final Map<UpdateComponent, UpdateCheckResult> map1
93
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
93
+                = new HashMap<>();
94 94
         final Map<UpdateComponent, UpdateCheckResult> map2
95
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
95
+                = new HashMap<>();
96 96
         final List<Map<UpdateComponent, UpdateCheckResult>> maps
97
-                = new ArrayList<Map<UpdateComponent, UpdateCheckResult>>();
97
+                = new ArrayList<>();
98 98
 
99 99
         map1.put(components.get(0), negativeResults.get(0));
100 100
         map1.put(components.get(1), negativeResults.get(1));
@@ -112,11 +112,11 @@ public class NaiveConsolidatorTest {
112 112
     @Test
113 113
     public void testIgnoresNegativeResultsForKnownPositiveComponents() {
114 114
         final Map<UpdateComponent, UpdateCheckResult> map1
115
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
115
+                = new HashMap<>();
116 116
         final Map<UpdateComponent, UpdateCheckResult> map2
117
-                = new HashMap<UpdateComponent, UpdateCheckResult>();
117
+                = new HashMap<>();
118 118
         final List<Map<UpdateComponent, UpdateCheckResult>> maps
119
-                = new ArrayList<Map<UpdateComponent, UpdateCheckResult>>();
119
+                = new ArrayList<>();
120 120
 
121 121
         map1.put(components.get(0), negativeResults.get(0));
122 122
         map1.put(components.get(1), positiveResults.get(1));

Loading…
取消
儲存