Procházet zdrojové kódy

Assorted tidying.

Change-Id: I918bb6183a19d0e400e37176e3f213b80a36514a
Reviewed-on: http://gerrit.dmdirc.com/4069
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
pull/1/head
Chris Smith před 9 roky
rodič
revize
b1c59cce2c

+ 18
- 23
src/com/dmdirc/plugins/PluginInfo.java Zobrazit soubor

@@ -98,7 +98,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
98 98
     /** Map of exports. */
99 99
     private final Map<String, ExportInfo> exports = new HashMap<>();
100 100
     /** List of configuration providers. */
101
-    private final List<ConfigProvider> configProviders = new ArrayList<>();
101
+    private final Collection<ConfigProvider> configProviders = new ArrayList<>();
102 102
     /** Event bus to post plugin loaded events to. */
103 103
     private final DMDircMBassador eventBus;
104 104
     /** File system for the plugin's jar. */
@@ -196,7 +196,6 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
196 196
      * @return The injector used for this plugin
197 197
      */
198 198
     public SimpleInjector getInjector() {
199
-        final SimpleInjector injector;
200 199
         final SimpleInjector[] parents = new SimpleInjector[metaData.getParent() == null ? 0 : 1];
201 200
         final Plugin[] plugins = new Plugin[parents.length];
202 201
 
@@ -207,7 +206,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
207 206
             plugins[0] = parent.getPlugin();
208 207
         }
209 208
 
210
-        injector = new SimpleInjector(parents);
209
+        final SimpleInjector injector = new SimpleInjector(parents);
211 210
 
212 211
         for (Plugin parentPlugin : plugins) {
213 212
             injector.addParameter(parentPlugin);
@@ -253,7 +252,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
253 252
      * @throws IOException if there is an error with the ResourceManager.
254 253
      */
255 254
     public Map<String, InputStream> getLicenceStreams() throws IOException {
256
-        final TreeMap<String, InputStream> licences = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
255
+        final Map<String, InputStream> licences = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
257 256
         if (!Files.exists(pluginFilesystem.getPath("/META-INF/licenses/"))) {
258 257
             return licences;
259 258
         }
@@ -333,13 +332,13 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
333 332
                     } catch (final InvalidIdentityFileException ex) {
334 333
                         eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
335 334
                                 "Error with identity file '" + name + "' in plugin '"
336
-                                + metaData.getName() + "'", ""));
335
+                                + metaData.getName() + '\'', ""));
337 336
                     }
338 337
                 }
339 338
             }
340 339
         } catch (final IOException ioe) {
341 340
             eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ioe,
342
-                    "Error finding identities in plugin '" + metaData.getName() + "'", ""));
341
+                    "Error finding identities in plugin '" + metaData.getName() + '\'', ""));
343 342
         }
344 343
     }
345 344
 
@@ -376,7 +375,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
376 375
                 final String name = bits[0];
377 376
                 final String type = bits.length > 1 ? bits[1] : "misc";
378 377
 
379
-                if (!name.equalsIgnoreCase("any") && !type.equalsIgnoreCase("export")) {
378
+                if (!"any".equalsIgnoreCase(name) && !"export".equalsIgnoreCase(type)) {
380 379
                     final Service service = metaData.getManager().getService(type, name, true);
381 380
                     synchronized (provides) {
382 381
                         service.addProvider(this);
@@ -446,7 +445,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
446 445
     @Override
447 446
     public String getProviderName() {
448 447
         return "Plugin: " + metaData.getFriendlyName() + " ("
449
-                + metaData.getName() + " / " + getFilename() + ")";
448
+                + metaData.getName() + " / " + getFilename() + ')';
450 449
     }
451 450
 
452 451
     @Override
@@ -556,11 +555,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
556 555
             }
557 556
         }
558 557
 
559
-        if (metaData.getParent() != null) {
560
-            return loadRequiredPlugin(metaData.getParent());
561
-        }
562
-
563
-        return true;
558
+        return metaData.getParent() == null || loadRequiredPlugin(metaData.getParent());
564 559
     }
565 560
 
566 561
     /**
@@ -594,7 +589,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
594 589
      */
595 590
     public void loadPlugin() {
596 591
         if (isLoaded() || isLoading) {
597
-            lastError = "Not Loading: (" + isLoaded() + "||" + isLoading + ")";
592
+            lastError = "Not Loading: (" + isLoaded() + "||" + isLoading + ')';
598 593
             return;
599 594
         }
600 595
 
@@ -613,7 +608,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
613 608
                 plugin.load(this, getObjectGraph());
614 609
                 plugin.onLoad();
615 610
             } catch (LinkageError | Exception e) {
616
-                lastError = "Error in onLoad for " + metaData.getName() + ":"
611
+                lastError = "Error in onLoad for " + metaData.getName() + ':'
617 612
                         + e.getMessage();
618 613
                 eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
619 614
                 unloadPlugin();
@@ -741,7 +736,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
741 736
                     if (prerequisites.isFailure()) {
742 737
                         if (!tempLoaded) {
743 738
                             lastError = "Prerequisites for plugin not met. ('"
744
-                                    + filename + ":" + metaData.getMainClass()
739
+                                    + filename + ':' + metaData.getMainClass()
745 740
                                     + "' -> '" + prerequisites.getFailureReason() + "') ";
746 741
                             eventBus.publish(new UserErrorEvent(ErrorLevel.LOW, null, lastError, ""));
747 742
                         }
@@ -758,7 +753,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
758 753
                                 plugin.onLoad();
759 754
                             } catch (LinkageError | Exception e) {
760 755
                                 lastError = "Error in onLoad for "
761
-                                        + metaData.getName() + ":" + e.getMessage();
756
+                                        + metaData.getName() + ':' + e.getMessage();
762 757
                                 eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM,
763 758
                                         e, lastError, ""));
764 759
                                 unloadPlugin();
@@ -768,19 +763,19 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
768 763
                 }
769 764
             }
770 765
         } catch (ClassNotFoundException cnfe) {
771
-            lastError = "Class not found ('" + filename + ":" + classname + ":"
766
+            lastError = "Class not found ('" + filename + ':' + classname + ':'
772 767
                     + classname.equals(metaData.getMainClass()) + "') - "
773 768
                     + cnfe.getMessage();
774 769
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, cnfe, lastError, ""));
775 770
         } catch (NoClassDefFoundError ncdf) {
776
-            lastError = "Unable to instantiate plugin ('" + filename + ":"
777
-                    + classname + ":"
771
+            lastError = "Unable to instantiate plugin ('" + filename + ':'
772
+                    + classname + ':'
778 773
                     + classname.equals(metaData.getMainClass())
779 774
                     + "') - Unable to find class: " + ncdf.getMessage();
780 775
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ncdf, lastError, ""));
781 776
         } catch (VerifyError ve) {
782
-            lastError = "Unable to instantiate plugin ('" + filename + ":"
783
-                    + classname + ":"
777
+            lastError = "Unable to instantiate plugin ('" + filename + ':'
778
+                    + classname + ':'
784 779
                     + classname.equals(metaData.getMainClass())
785 780
                     + "') - Incompatible: " + ve.getMessage();
786 781
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ve, lastError, ""));
@@ -846,7 +841,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
846 841
                     plugin.onUnload();
847 842
                 } catch (Exception | LinkageError e) {
848 843
                     lastError = "Error in onUnload for " + metaData.getName()
849
-                            + ":" + e + " - " + e.getMessage();
844
+                            + ':' + e + " - " + e.getMessage();
850 845
                     eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
851 846
                 }
852 847
 

+ 4
- 10
src/com/dmdirc/ui/core/aliases/CoreAliasDialogModel.java Zobrazit soubor

@@ -251,20 +251,14 @@ public class CoreAliasDialogModel implements AliasDialogModel {
251 251
 
252 252
     @Override
253 253
     public boolean isSelectedAliasValid() {
254
-        if (selectedAlias.isPresent()) {
255
-            return isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
256
-        } else {
257
-            return true;
258
-        }
254
+        return !selectedAlias.isPresent() ||
255
+                isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
259 256
     }
260 257
 
261 258
     @Override
262 259
     public boolean isChangeAliasAllowed() {
263
-        if (selectedAlias.isPresent()) {
264
-            return isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
265
-        } else {
266
-            return true;
267
-        }
260
+        return !selectedAlias.isPresent() ||
261
+                isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
268 262
     }
269 263
 
270 264
     @Override

+ 14
- 28
src/com/dmdirc/ui/core/profiles/CoreProfilesDialogModel.java Zobrazit soubor

@@ -260,11 +260,9 @@ public class CoreProfilesDialogModel implements ProfilesDialogModel {
260 260
 
261 261
     @Override
262 262
     public boolean isSelectedProfileNameValid() {
263
-        if (getSelectedProfileName().isPresent()) {
264
-            return !getSelectedProfileNameValidator()
265
-                    .validate(getSelectedProfileName().get()).isFailure();
266
-        }
267
-        return true;
263
+        return !getSelectedProfileName().isPresent() ||
264
+                !getSelectedProfileNameValidator().validate(getSelectedProfileName().get())
265
+                        .isFailure();
268 266
     }
269 267
 
270 268
     @Override
@@ -291,11 +289,9 @@ public class CoreProfilesDialogModel implements ProfilesDialogModel {
291 289
 
292 290
     @Override
293 291
     public boolean isSelectedProfileRealnameValid() {
294
-        if (getSelectedProfileRealname().isPresent()) {
295
-            return !getSelectedProfileRealnameValidator()
296
-                    .validate(getSelectedProfileRealname().get()).isFailure();
297
-        }
298
-        return true;
292
+        return !getSelectedProfileRealname().isPresent() ||
293
+                !getSelectedProfileRealnameValidator().validate(getSelectedProfileRealname().get())
294
+                        .isFailure();
299 295
     }
300 296
 
301 297
     @Override
@@ -322,11 +318,9 @@ public class CoreProfilesDialogModel implements ProfilesDialogModel {
322 318
 
323 319
     @Override
324 320
     public boolean isSelectedProfileIdentValid() {
325
-        if (getSelectedProfileIdent().isPresent()) {
326
-            return !getSelectedProfileIdentValidator()
327
-                    .validate(getSelectedProfileIdent().get()).isFailure();
328
-        }
329
-        return true;
321
+        return !getSelectedProfileIdent().isPresent() ||
322
+                !getSelectedProfileIdentValidator().validate(getSelectedProfileIdent().get())
323
+                        .isFailure();
330 324
     }
331 325
 
332 326
     @Override
@@ -358,11 +352,8 @@ public class CoreProfilesDialogModel implements ProfilesDialogModel {
358 352
 
359 353
     @Override
360 354
     public boolean isSelectedProfileNicknamesValid() {
361
-        if (getSelectedProfileNicknames().isPresent()) {
362
-            return !getSelectedProfileNicknamesValidator()
363
-                    .validate(getSelectedProfileNicknames().get()).isFailure();
364
-        }
365
-        return true;
355
+        return !getSelectedProfileNicknames().isPresent() || !getSelectedProfileNicknamesValidator()
356
+                .validate(getSelectedProfileNicknames().get()).isFailure();
366 357
     }
367 358
 
368 359
     @Override
@@ -447,14 +438,9 @@ public class CoreProfilesDialogModel implements ProfilesDialogModel {
447 438
 
448 439
     @Override
449 440
     public boolean canSwitchProfiles() {
450
-        if (selectedProfile.isPresent()) {
451
-            return isSelectedProfileIdentValid()
452
-                    && isSelectedProfileNameValid()
453
-                    && isSelectedProfileNicknamesValid()
454
-                    && isSelectedProfileRealnameValid();
455
-        } else {
456
-            return true;
457
-        }
441
+        return !selectedProfile.isPresent() ||
442
+                isSelectedProfileIdentValid() && isSelectedProfileNameValid() &&
443
+                        isSelectedProfileNicknamesValid() && isSelectedProfileRealnameValid();
458 444
     }
459 445
 
460 446
     @Override

Načítá se…
Zrušit
Uložit