Browse Source

Remove Logger.assertTrue.

Use Guava's Preconditions instead, which throw appropriate exceptions
rather than AssertionErrors (whose idea was that?!)

Also fix weirdness in CommandArguments where start was allowed to be
1 greater than end when getting words.

Change-Id: Icce38e36da6507f645fb8b3b872dfe2c60c43ea7
Reviewed-on: http://gerrit.dmdirc.com/2961
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
7a1c4aa299

+ 9
- 10
src/com/dmdirc/FrameContainerComparator.java View File

22
 
22
 
23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
-import com.dmdirc.logger.Logger;
26
-
27
 import java.io.Serializable;
25
 import java.io.Serializable;
28
 import java.util.Comparator;
26
 import java.util.Comparator;
29
 
27
 
28
+import static com.google.common.base.Preconditions.checkNotNull;
29
+
30
 /**
30
 /**
31
  * Compares FrameContainers by name.
31
  * Compares FrameContainers by name.
32
  */
32
  */
33
-public final class FrameContainerComparator implements Comparator<FrameContainer>,
34
-        Serializable {
33
+public class FrameContainerComparator implements Comparator<FrameContainer>, Serializable {
35
 
34
 
36
     /**
35
     /**
37
      * A version number for this class. It should be changed whenever the class
36
      * A version number for this class. It should be changed whenever the class
56
         "item2.toString() returns a non-null value"
55
         "item2.toString() returns a non-null value"
57
     })
56
     })
58
     public int compare(final FrameContainer item1, final FrameContainer item2) {
57
     public int compare(final FrameContainer item1, final FrameContainer item2) {
59
-        Logger.assertTrue(item1 != null);
60
-        Logger.assertTrue(item2 != null);
61
-        Logger.assertTrue(item1.getName() != null);
62
-        Logger.assertTrue(item2.getName() != null);
58
+        checkNotNull(item1);
59
+        checkNotNull(item2);
60
+        checkNotNull(item1.getName());
61
+        checkNotNull(item2.getName());
63
 
62
 
64
         if (sortBefore(item1, item2)) {
63
         if (sortBefore(item1, item2)) {
65
             return -1;
64
             return -1;
84
      * @param item2 The existing container to test against
83
      * @param item2 The existing container to test against
85
      * @return True iff the new container should be before the old container
84
      * @return True iff the new container should be before the old container
86
      */
85
      */
87
-    private static boolean sortBefore(final FrameContainer item1,
86
+    private static boolean sortBefore(
87
+            final FrameContainer item1,
88
             final FrameContainer item2) {
88
             final FrameContainer item2) {
89
-
90
         return getPosition(item1) < getPosition(item2);
89
         return getPosition(item1) < getPosition(item2);
91
     }
90
     }
92
 
91
 

+ 5
- 2
src/com/dmdirc/Server.java View File

87
 
87
 
88
 import lombok.extern.slf4j.Slf4j;
88
 import lombok.extern.slf4j.Slf4j;
89
 
89
 
90
+import static com.google.common.base.Preconditions.checkArgument;
91
+import static com.google.common.base.Preconditions.checkNotNull;
92
+
90
 /**
93
 /**
91
  * The Server class represents the client's view of a server. It maintains
94
  * The Server class represents the client's view of a server. It maintains
92
  * a list of all channels, queries, etc, and handles parser callbacks pertaining
95
  * a list of all channels, queries, etc, and handles parser callbacks pertaining
830
         "The current profile specifies at least one nickname"
833
         "The current profile specifies at least one nickname"
831
     })
834
     })
832
     private MyInfo buildMyInfo() {
835
     private MyInfo buildMyInfo() {
833
-        Logger.assertTrue(profile != null);
834
-        Logger.assertTrue(!profile.getOptionList(DOMAIN_PROFILE, "nicknames").isEmpty());
836
+        checkNotNull(profile);
837
+        checkArgument(!profile.getOptionList(DOMAIN_PROFILE, "nicknames").isEmpty());
835
 
838
 
836
         final MyInfo myInfo = new MyInfo();
839
         final MyInfo myInfo = new MyInfo();
837
         myInfo.setNickname(profile.getOptionList(DOMAIN_PROFILE, "nicknames").get(0));
840
         myInfo.setNickname(profile.getOptionList(DOMAIN_PROFILE, "nicknames").get(0));

+ 3
- 1
src/com/dmdirc/ServerManager.java View File

45
 import javax.inject.Provider;
45
 import javax.inject.Provider;
46
 import javax.inject.Singleton;
46
 import javax.inject.Singleton;
47
 
47
 
48
+import static com.google.common.base.Preconditions.checkArgument;
49
+
48
 /**
50
 /**
49
  * The ServerManager maintains a list of all servers, and provides methods to
51
  * The ServerManager maintains a list of all servers, and provides methods to
50
  * search or iterate over them.
52
  * search or iterate over them.
210
      * @since 0.6.3
212
      * @since 0.6.3
211
      */
213
      */
212
     public Server connectToAddress(final URI uri, final ConfigProvider profile) {
214
     public Server connectToAddress(final URI uri, final ConfigProvider profile) {
213
-        Logger.assertTrue(profile.isProfile());
215
+        checkArgument(profile.isProfile());
214
         Server server = null;
216
         Server server = null;
215
 
217
 
216
         for (Server loopServer : servers) {
218
         for (Server loopServer : servers) {

+ 6
- 5
src/com/dmdirc/actions/ActionComponentChain.java View File

25
 import com.dmdirc.Precondition;
25
 import com.dmdirc.Precondition;
26
 import com.dmdirc.interfaces.ActionController;
26
 import com.dmdirc.interfaces.ActionController;
27
 import com.dmdirc.interfaces.actions.ActionComponent;
27
 import com.dmdirc.interfaces.actions.ActionComponent;
28
-import com.dmdirc.logger.Logger;
29
 
28
 
30
 import java.util.ArrayList;
29
 import java.util.ArrayList;
31
 import java.util.List;
30
 import java.util.List;
32
 
31
 
32
+import static com.google.common.base.Preconditions.checkArgument;
33
+
33
 /**
34
 /**
34
  * An action component chain supports chaining of multiple action components
35
  * An action component chain supports chaining of multiple action components
35
  * together.
36
  * together.
89
     @Precondition("This component chain has one or more components")
90
     @Precondition("This component chain has one or more components")
90
     @Override
91
     @Override
91
     public Class<?> appliesTo() {
92
     public Class<?> appliesTo() {
92
-        Logger.assertTrue(!components.isEmpty());
93
+        checkArgument(!components.isEmpty());
93
 
94
 
94
         return components.get(0).appliesTo();
95
         return components.get(0).appliesTo();
95
     }
96
     }
98
     @Precondition("This component chain has one or more components")
99
     @Precondition("This component chain has one or more components")
99
     @Override
100
     @Override
100
     public Class<?> getType() {
101
     public Class<?> getType() {
101
-        Logger.assertTrue(!components.isEmpty());
102
+        checkArgument(!components.isEmpty());
102
 
103
 
103
         return components.get(components.size() - 1).getType();
104
         return components.get(components.size() - 1).getType();
104
     }
105
     }
107
     @Precondition("This component chain has one or more components")
108
     @Precondition("This component chain has one or more components")
108
     @Override
109
     @Override
109
     public String getName() {
110
     public String getName() {
110
-        Logger.assertTrue(!components.isEmpty());
111
+        checkArgument(!components.isEmpty());
111
 
112
 
112
         final StringBuilder name = new StringBuilder();
113
         final StringBuilder name = new StringBuilder();
113
 
114
 
123
     @Override
124
     @Override
124
     @Precondition("This component chain has one or more components")
125
     @Precondition("This component chain has one or more components")
125
     public String toString() {
126
     public String toString() {
126
-        Logger.assertTrue(!components.isEmpty());
127
+        checkArgument(!components.isEmpty());
127
 
128
 
128
         final StringBuilder name = new StringBuilder();
129
         final StringBuilder name = new StringBuilder();
129
 
130
 

+ 5
- 3
src/com/dmdirc/actions/ActionGroup.java View File

24
 
24
 
25
 import com.dmdirc.Precondition;
25
 import com.dmdirc.Precondition;
26
 import com.dmdirc.config.prefs.PreferencesSetting;
26
 import com.dmdirc.config.prefs.PreferencesSetting;
27
-import com.dmdirc.logger.Logger;
28
 import com.dmdirc.updater.Version;
27
 import com.dmdirc.updater.Version;
29
 
28
 
30
 import java.util.ArrayList;
29
 import java.util.ArrayList;
33
 import java.util.List;
32
 import java.util.List;
34
 import java.util.Map;
33
 import java.util.Map;
35
 
34
 
35
+import static com.google.common.base.Preconditions.checkArgument;
36
+import static com.google.common.base.Preconditions.checkNotNull;
37
+
36
 /**
38
 /**
37
  * Represents a group of actions, along with their meta-data.
39
  * Represents a group of actions, along with their meta-data.
38
  */
40
  */
230
     })
232
     })
231
     @SuppressWarnings("deprecation")
233
     @SuppressWarnings("deprecation")
232
     public void deleteAction(final Action action) {
234
     public void deleteAction(final Action action) {
233
-        Logger.assertTrue(action != null);
234
-        Logger.assertTrue(actions.contains(action));
235
+        checkNotNull(action);
236
+        checkArgument(actions.contains(action));
235
 
237
 
236
         ActionManager.getActionManager().removeAction(action);
238
         ActionManager.getActionManager().removeAction(action);
237
         action.delete();
239
         action.delete();

+ 34
- 32
src/com/dmdirc/actions/ActionManager.java View File

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

+ 4
- 3
src/com/dmdirc/commandparser/CommandArguments.java View File

24
 
24
 
25
 import com.dmdirc.Precondition;
25
 import com.dmdirc.Precondition;
26
 import com.dmdirc.interfaces.CommandController;
26
 import com.dmdirc.interfaces.CommandController;
27
-import com.dmdirc.logger.Logger;
28
 
27
 
29
 import java.util.Arrays;
28
 import java.util.Arrays;
30
 import java.util.Collection;
29
 import java.util.Collection;
31
 import java.util.regex.Matcher;
30
 import java.util.regex.Matcher;
32
 import java.util.regex.Pattern;
31
 import java.util.regex.Pattern;
33
 
32
 
33
+import static com.google.common.base.Preconditions.checkPositionIndex;
34
+
34
 /**
35
 /**
35
  * Represents a command and its arguments. In this class, input is split into
36
  * Represents a command and its arguments. In this class, input is split into
36
  * 'words' which are separated by any number of whitespace characters;
37
  * 'words' which are separated by any number of whitespace characters;
156
     public String getArgumentsAsString(final int start) {
157
     public String getArgumentsAsString(final int start) {
157
         parse();
158
         parse();
158
 
159
 
159
-        return getArgumentsAsString(start, words.length - 2);
160
+        return getArgumentsAsString(start, Math.max(start, words.length - 2));
160
     }
161
     }
161
 
162
 
162
     /**
163
     /**
195
      */
196
      */
196
     @Precondition("Start index is less than or equal to end index")
197
     @Precondition("Start index is less than or equal to end index")
197
     public String getWordsAsString(final int start, final int end) {
198
     public String getWordsAsString(final int start, final int end) {
198
-        Logger.assertTrue(start <= end + 1);
199
+        checkPositionIndex(start, end);
199
 
200
 
200
         final Pattern pattern = Pattern.compile("(\\S+\\s+){" + start + "}"
201
         final Pattern pattern = Pattern.compile("(\\S+\\s+){" + start + "}"
201
                 + "((\\S+\\s+){" + Math.max(0, end - start) + "}\\S+(\\s+$)?).*?");
202
                 + "((\\S+\\s+){" + Math.max(0, end - start) + "}\\S+(\\s+$)?).*?");

+ 9
- 6
src/com/dmdirc/config/IdentityManager.java View File

50
 
50
 
51
 import lombok.extern.slf4j.Slf4j;
51
 import lombok.extern.slf4j.Slf4j;
52
 
52
 
53
+import static com.google.common.base.Preconditions.checkArgument;
54
+import static com.google.common.base.Preconditions.checkNotNull;
55
+
53
 /**
56
 /**
54
  * The identity manager manages all known identities, providing easy methods
57
  * The identity manager manages all known identities, providing easy methods
55
  * to access them.
58
  * to access them.
268
         "The specified File is a directory"
271
         "The specified File is a directory"
269
     })
272
     })
270
     private void loadUser(final File dir) {
273
     private void loadUser(final File dir) {
271
-        Logger.assertTrue(dir != null);
272
-        Logger.assertTrue(dir.isDirectory());
274
+        checkNotNull(dir);
275
+        checkArgument(dir.isDirectory());
273
 
276
 
274
         if (dir.listFiles() == null) {
277
         if (dir.listFiles() == null) {
275
             Logger.userError(ErrorLevel.MEDIUM,
278
             Logger.userError(ErrorLevel.MEDIUM,
421
     /** {@inheritDoc} */
424
     /** {@inheritDoc} */
422
     @Override
425
     @Override
423
     public void addConfigProvider(final ConfigProvider identity) {
426
     public void addConfigProvider(final ConfigProvider identity) {
424
-        Logger.assertTrue(identity != null);
427
+        checkNotNull(identity);
425
 
428
 
426
         final String target = getGroup(identity);
429
         final String target = getGroup(identity);
427
 
430
 
446
     /** {@inheritDoc} */
449
     /** {@inheritDoc} */
447
     @Override
450
     @Override
448
     public void removeConfigProvider(final ConfigProvider identity) {
451
     public void removeConfigProvider(final ConfigProvider identity) {
449
-        Logger.assertTrue(identity != null);
452
+        checkNotNull(identity);
450
 
453
 
451
         final String group = getGroup(identity);
454
         final String group = getGroup(identity);
452
 
455
 
453
-        Logger.assertTrue(identities.containsValue(group, identity));
456
+        checkArgument(identities.containsValue(group, identity));
454
 
457
 
455
         synchronized (identities) {
458
         synchronized (identities) {
456
             identities.remove(group, identity);
459
             identities.remove(group, identity);
478
     /** {@inheritDoc} */
481
     /** {@inheritDoc} */
479
     @Override
482
     @Override
480
     public void registerIdentityListener(final String type, final ConfigProviderListener listener) {
483
     public void registerIdentityListener(final String type, final ConfigProviderListener listener) {
481
-        Logger.assertTrue(listener != null);
484
+        checkNotNull(listener);
482
 
485
 
483
         synchronized (listeners) {
486
         synchronized (listeners) {
484
             listeners.add(type, listener);
487
             listeners.add(type, listener);

+ 0
- 12
src/com/dmdirc/logger/Logger.java View File

82
         getErrorManager().addError(level, message, exception, true);
82
         getErrorManager().addError(level, message, exception, true);
83
     }
83
     }
84
 
84
 
85
-    /**
86
-     * Asserts that the specified value is true. If not, an AssertionError
87
-     * exception is thrown.
88
-     *
89
-     * @param value The value to be tested
90
-     */
91
-    public static void assertTrue(final boolean value) {
92
-        if (!value) {
93
-            throw new AssertionError();
94
-        }
95
-    }
96
-
97
     /**
85
     /**
98
      * Gets the manager that should be used to report errors.
86
      * Gets the manager that should be used to report errors.
99
      *
87
      *

+ 16
- 15
src/com/dmdirc/ui/WindowManager.java View File

27
 import com.dmdirc.Precondition;
27
 import com.dmdirc.Precondition;
28
 import com.dmdirc.interfaces.FrameCloseListener;
28
 import com.dmdirc.interfaces.FrameCloseListener;
29
 import com.dmdirc.interfaces.ui.FrameListener;
29
 import com.dmdirc.interfaces.ui.FrameListener;
30
-import com.dmdirc.logger.Logger;
31
 import com.dmdirc.util.collections.ListenerList;
30
 import com.dmdirc.util.collections.ListenerList;
32
 
31
 
33
 import java.util.Collection;
32
 import java.util.Collection;
38
 import javax.inject.Inject;
37
 import javax.inject.Inject;
39
 import javax.inject.Singleton;
38
 import javax.inject.Singleton;
40
 
39
 
40
+import static com.google.common.base.Preconditions.checkArgument;
41
+import static com.google.common.base.Preconditions.checkNotNull;
42
+
41
 /**
43
 /**
42
  * The WindowManager maintains a list of all open windows, and their
44
  * The WindowManager maintains a list of all open windows, and their
43
  * parent/child relations.
45
  * parent/child relations.
68
      */
70
      */
69
     @Precondition("The specified FrameListener is not null")
71
     @Precondition("The specified FrameListener is not null")
70
     public void addListener(final FrameListener frameListener) {
72
     public void addListener(final FrameListener frameListener) {
71
-        Logger.assertTrue(frameListener != null);
73
+        checkNotNull(frameListener);
72
 
74
 
73
         listeners.add(FrameListener.class, frameListener);
75
         listeners.add(FrameListener.class, frameListener);
74
     }
76
     }
146
         "The specified Window has not already been added"
148
         "The specified Window has not already been added"
147
     })
149
     })
148
     public void addWindow(final FrameContainer window, final boolean focus) {
150
     public void addWindow(final FrameContainer window, final boolean focus) {
149
-        Logger.assertTrue(window != null);
150
-        Logger.assertTrue(!rootWindows.contains(window));
151
+        checkNotNull(window);
152
+        checkArgument(!rootWindows.contains(window));
151
 
153
 
152
         rootWindows.add(window);
154
         rootWindows.add(window);
153
 
155
 
184
     })
186
     })
185
     public void addWindow(final FrameContainer parent,
187
     public void addWindow(final FrameContainer parent,
186
             final FrameContainer child, final boolean focus) {
188
             final FrameContainer child, final boolean focus) {
187
-        Logger.assertTrue(parent != null);
188
-        Logger.assertTrue(isInHierarchy(parent));
189
-        Logger.assertTrue(child != null);
190
-        Logger.assertTrue(!isInHierarchy(child));
189
+        checkNotNull(parent);
190
+        checkArgument(isInHierarchy(parent));
191
+        checkNotNull(child);
192
+        checkArgument(!isInHierarchy(child));
191
 
193
 
192
         parent.addChild(child);
194
         parent.addChild(child);
193
 
195
 
224
         "The specified window is in the window hierarchy"
226
         "The specified window is in the window hierarchy"
225
     })
227
     })
226
     public void removeWindow(final FrameContainer window) {
228
     public void removeWindow(final FrameContainer window) {
227
-        Logger.assertTrue(isInHierarchy(window));
228
-        Logger.assertTrue(window != null);
229
+        checkNotNull(window != null);
230
+        checkArgument(isInHierarchy(window));
229
 
231
 
230
         for (FrameContainer child : window.getChildren()) {
232
         for (FrameContainer child : window.getChildren()) {
231
             child.close();
233
             child.close();
252
      */
254
      */
253
     @Precondition("The specified window name is not null")
255
     @Precondition("The specified window name is not null")
254
     public FrameContainer findCustomWindow(final String name) {
256
     public FrameContainer findCustomWindow(final String name) {
255
-        Logger.assertTrue(name != null);
257
+        checkNotNull(name);
256
 
258
 
257
         return findCustomWindow(rootWindows, name);
259
         return findCustomWindow(rootWindows, name);
258
     }
260
     }
270
         "The specified parent window is not null",
272
         "The specified parent window is not null",
271
         "The specified parent window has been added to the Window Manager"
273
         "The specified parent window has been added to the Window Manager"
272
     })
274
     })
273
-    public FrameContainer findCustomWindow(final FrameContainer parent,
274
-            final String name) {
275
-        Logger.assertTrue(parent != null);
276
-        Logger.assertTrue(name != null);
275
+    public FrameContainer findCustomWindow(final FrameContainer parent, final String name) {
276
+        checkNotNull(parent);
277
+        checkNotNull(name);
277
 
278
 
278
         return findCustomWindow(parent.getChildren(), name);
279
         return findCustomWindow(parent.getChildren(), name);
279
     }
280
     }

Loading…
Cancel
Save