|
@@ -34,7 +34,6 @@ import com.dmdirc.interfaces.actions.ActionType;
|
34
|
34
|
import com.dmdirc.interfaces.config.IdentityController;
|
35
|
35
|
import com.dmdirc.logger.ErrorLevel;
|
36
|
36
|
import com.dmdirc.logger.Logger;
|
37
|
|
-import com.dmdirc.updater.UpdateChecker;
|
38
|
37
|
import com.dmdirc.updater.components.ActionGroupComponent;
|
39
|
38
|
import com.dmdirc.updater.manager.UpdateManager;
|
40
|
39
|
import com.dmdirc.util.collections.MapList;
|
|
@@ -53,6 +52,9 @@ import javax.inject.Provider;
|
53
|
52
|
|
54
|
53
|
import lombok.extern.slf4j.Slf4j;
|
55
|
54
|
|
|
55
|
+import static com.google.common.base.Preconditions.checkArgument;
|
|
56
|
+import static com.google.common.base.Preconditions.checkNotNull;
|
|
57
|
+
|
56
|
58
|
/**
|
57
|
59
|
* Manages all actions for the client.
|
58
|
60
|
*/
|
|
@@ -215,7 +217,7 @@ public class ActionManager implements ActionController {
|
215
|
217
|
@Override
|
216
|
218
|
public void registerTypes(final ActionType[] newTypes) {
|
217
|
219
|
for (ActionType type : newTypes) {
|
218
|
|
- Logger.assertTrue(type != null);
|
|
220
|
+ checkNotNull(type);
|
219
|
221
|
|
220
|
222
|
if (!types.contains(type)) {
|
221
|
223
|
log.debug("Registering action type: {}", type);
|
|
@@ -229,7 +231,7 @@ public class ActionManager implements ActionController {
|
229
|
231
|
@Override
|
230
|
232
|
public void registerComponents(final ActionComponent[] comps) {
|
231
|
233
|
for (ActionComponent comp : comps) {
|
232
|
|
- Logger.assertTrue(comp != null);
|
|
234
|
+ checkNotNull(comp);
|
233
|
235
|
|
234
|
236
|
log.debug("Registering action component: {}", comp);
|
235
|
237
|
components.add(comp);
|
|
@@ -240,7 +242,7 @@ public class ActionManager implements ActionController {
|
240
|
242
|
@Override
|
241
|
243
|
public void registerComparisons(final ActionComparison[] comps) {
|
242
|
244
|
for (ActionComparison comp : comps) {
|
243
|
|
- Logger.assertTrue(comp != null);
|
|
245
|
+ checkNotNull(comp);
|
244
|
246
|
|
245
|
247
|
log.debug("Registering action comparison: {}", comp);
|
246
|
248
|
comparisons.add(comp);
|
|
@@ -313,8 +315,8 @@ public class ActionManager implements ActionController {
|
313
|
315
|
*/
|
314
|
316
|
@Precondition("The specified File is not null and represents a directory")
|
315
|
317
|
private void loadActions(final File dir) {
|
316
|
|
- Logger.assertTrue(dir != null);
|
317
|
|
- Logger.assertTrue(dir.isDirectory());
|
|
318
|
+ checkNotNull(dir);
|
|
319
|
+ checkArgument(dir.isDirectory());
|
318
|
320
|
|
319
|
321
|
log.debug("Loading actions from directory: {}", dir.getAbsolutePath());
|
320
|
322
|
|
|
@@ -330,7 +332,7 @@ public class ActionManager implements ActionController {
|
330
|
332
|
/** {@inheritDoc} */
|
331
|
333
|
@Override
|
332
|
334
|
public void addAction(final Action action) {
|
333
|
|
- Logger.assertTrue(action != null);
|
|
335
|
+ checkNotNull(action);
|
334
|
336
|
|
335
|
337
|
log.debug("Registering action: {}/{} (status: {})",
|
336
|
338
|
new Object[] { action.getGroup(), action.getName(), action.getStatus() });
|
|
@@ -358,7 +360,7 @@ public class ActionManager implements ActionController {
|
358
|
360
|
/** {@inheritDoc} */
|
359
|
361
|
@Override
|
360
|
362
|
public void removeAction(final Action action) {
|
361
|
|
- Logger.assertTrue(action != null);
|
|
363
|
+ checkNotNull(action);
|
362
|
364
|
|
363
|
365
|
actions.removeFromAll(action);
|
364
|
366
|
getOrCreateGroup(action.getGroup()).remove(action);
|
|
@@ -375,9 +377,9 @@ public class ActionManager implements ActionController {
|
375
|
377
|
@Override
|
376
|
378
|
public boolean triggerEvent(final ActionType type,
|
377
|
379
|
final StringBuffer format, final Object ... arguments) {
|
378
|
|
- Logger.assertTrue(type != null);
|
379
|
|
- Logger.assertTrue(type.getType() != null);
|
380
|
|
- Logger.assertTrue(type.getType().getArity() == arguments.length);
|
|
380
|
+ checkNotNull(type);
|
|
381
|
+ checkNotNull(type.getType());
|
|
382
|
+ checkArgument(type.getType().getArity() == arguments.length);
|
381
|
383
|
|
382
|
384
|
log.trace("Calling listeners for event of type {}", type);
|
383
|
385
|
|
|
@@ -413,7 +415,7 @@ public class ActionManager implements ActionController {
|
413
|
415
|
@Precondition("The specified ActionType is not null")
|
414
|
416
|
private boolean triggerActions(final ActionType type,
|
415
|
417
|
final StringBuffer format, final Object ... arguments) {
|
416
|
|
- Logger.assertTrue(type != null);
|
|
418
|
+ checkNotNull(type);
|
417
|
419
|
|
418
|
420
|
boolean res = false;
|
419
|
421
|
|
|
@@ -457,9 +459,9 @@ public class ActionManager implements ActionController {
|
457
|
459
|
/** {@inheritDoc} */
|
458
|
460
|
@Override
|
459
|
461
|
public ActionGroup createGroup(final String group) {
|
460
|
|
- Logger.assertTrue(group != null);
|
461
|
|
- Logger.assertTrue(!group.isEmpty());
|
462
|
|
- Logger.assertTrue(!groups.containsKey(group));
|
|
462
|
+ checkNotNull(group);
|
|
463
|
+ checkArgument(!group.isEmpty());
|
|
464
|
+ checkArgument(!groups.containsKey(group));
|
463
|
465
|
|
464
|
466
|
final File file = new File(getDirectory() + group);
|
465
|
467
|
if (file.isDirectory() || file.mkdir()) {
|
|
@@ -475,9 +477,9 @@ public class ActionManager implements ActionController {
|
475
|
477
|
/** {@inheritDoc} */
|
476
|
478
|
@Override
|
477
|
479
|
public void deleteGroup(final String group) {
|
478
|
|
- Logger.assertTrue(group != null);
|
479
|
|
- Logger.assertTrue(!group.isEmpty());
|
480
|
|
- Logger.assertTrue(groups.containsKey(group));
|
|
480
|
+ checkNotNull(group);
|
|
481
|
+ checkArgument(!group.isEmpty());
|
|
482
|
+ checkArgument(groups.containsKey(group));
|
481
|
483
|
|
482
|
484
|
for (Action action : groups.get(group).getActions()) {
|
483
|
485
|
removeAction(action);
|
|
@@ -507,13 +509,13 @@ public class ActionManager implements ActionController {
|
507
|
509
|
/** {@inheritDoc} */
|
508
|
510
|
@Override
|
509
|
511
|
public void changeGroupName(final String oldName, final String newName) {
|
510
|
|
- Logger.assertTrue(oldName != null);
|
511
|
|
- Logger.assertTrue(!oldName.isEmpty());
|
512
|
|
- Logger.assertTrue(newName != null);
|
513
|
|
- Logger.assertTrue(!newName.isEmpty());
|
514
|
|
- Logger.assertTrue(groups.containsKey(oldName));
|
515
|
|
- Logger.assertTrue(!groups.containsKey(newName));
|
516
|
|
- Logger.assertTrue(!newName.equals(oldName));
|
|
512
|
+ checkNotNull(oldName);
|
|
513
|
+ checkArgument(!oldName.isEmpty());
|
|
514
|
+ checkNotNull(newName);
|
|
515
|
+ checkArgument(!newName.isEmpty());
|
|
516
|
+ checkArgument(groups.containsKey(oldName));
|
|
517
|
+ checkArgument(!groups.containsKey(newName));
|
|
518
|
+ checkArgument(!newName.equals(oldName));
|
517
|
519
|
|
518
|
520
|
createGroup(newName);
|
519
|
521
|
|
|
@@ -545,7 +547,7 @@ public class ActionManager implements ActionController {
|
545
|
547
|
/** {@inheritDoc} */
|
546
|
548
|
@Override
|
547
|
549
|
public List<ActionType> findCompatibleTypes(final ActionType type) {
|
548
|
|
- Logger.assertTrue(type != null);
|
|
550
|
+ checkNotNull(type);
|
549
|
551
|
|
550
|
552
|
final List<ActionType> res = new ArrayList<>();
|
551
|
553
|
for (ActionType target : types) {
|
|
@@ -560,7 +562,7 @@ public class ActionManager implements ActionController {
|
560
|
562
|
/** {@inheritDoc} */
|
561
|
563
|
@Override
|
562
|
564
|
public List<ActionComponent> findCompatibleComponents(final Class<?> target) {
|
563
|
|
- Logger.assertTrue(target != null);
|
|
565
|
+ checkNotNull(target);
|
564
|
566
|
|
565
|
567
|
final List<ActionComponent> res = new ArrayList<>();
|
566
|
568
|
for (ActionComponent subject : components) {
|
|
@@ -575,7 +577,7 @@ public class ActionManager implements ActionController {
|
575
|
577
|
/** {@inheritDoc} */
|
576
|
578
|
@Override
|
577
|
579
|
public List<ActionComparison> findCompatibleComparisons(final Class<?> target) {
|
578
|
|
- Logger.assertTrue(target != null);
|
|
580
|
+ checkNotNull(target);
|
579
|
581
|
|
580
|
582
|
final List<ActionComparison> res = new ArrayList<>();
|
581
|
583
|
for (ActionComparison subject : comparisons) {
|
|
@@ -590,8 +592,8 @@ public class ActionManager implements ActionController {
|
590
|
592
|
/** {@inheritDoc} */
|
591
|
593
|
@Override
|
592
|
594
|
public ActionComponent getComponent(final String type) {
|
593
|
|
- Logger.assertTrue(type != null);
|
594
|
|
- Logger.assertTrue(!type.isEmpty());
|
|
595
|
+ checkNotNull(type);
|
|
596
|
+ checkArgument(!type.isEmpty());
|
595
|
597
|
|
596
|
598
|
for (ActionComponent target : components) {
|
597
|
599
|
if (target.name().equals(type)) {
|
|
@@ -605,8 +607,8 @@ public class ActionManager implements ActionController {
|
605
|
607
|
/** {@inheritDoc} */
|
606
|
608
|
@Override
|
607
|
609
|
public ActionComparison getComparison(final String type) {
|
608
|
|
- Logger.assertTrue(type != null);
|
609
|
|
- Logger.assertTrue(!type.isEmpty());
|
|
610
|
+ checkNotNull(type);
|
|
611
|
+ checkArgument(!type.isEmpty());
|
610
|
612
|
|
611
|
613
|
for (ActionComparison target : comparisons) {
|
612
|
614
|
if (target.name().equals(type)) {
|