Browse Source

Style fixes

Change-Id: I7743e62ce70f3e4e0bc07c90aeb62279783f7af6
Reviewed-on: http://gerrit.dmdirc.com/4006
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 9 years ago
parent
commit
fb0ab89eb5

+ 13
- 15
src/com/dmdirc/config/ConfigFileBackedConfigProvider.java View File

35
 import java.io.IOException;
35
 import java.io.IOException;
36
 import java.io.InputStream;
36
 import java.io.InputStream;
37
 import java.util.ArrayList;
37
 import java.util.ArrayList;
38
+import java.util.Collection;
38
 import java.util.HashMap;
39
 import java.util.HashMap;
39
 import java.util.HashSet;
40
 import java.util.HashSet;
40
 import java.util.LinkedList;
41
 import java.util.LinkedList;
160
             target.setChannel(getOption(DOMAIN, "channel"));
161
             target.setChannel(getOption(DOMAIN, "channel"));
161
         } else if (hasOptionString(DOMAIN, "globaldefault")) {
162
         } else if (hasOptionString(DOMAIN, "globaldefault")) {
162
             target.setGlobalDefault();
163
             target.setGlobalDefault();
163
-        } else if (hasOptionString(DOMAIN, "global") || (forceDefault && !isProfile())) {
164
+        } else if (hasOptionString(DOMAIN, "global") || forceDefault && !isProfile()) {
164
             target.setGlobal();
165
             target.setGlobal();
165
         } else if (isProfile()) {
166
         } else if (isProfile()) {
166
             target.setCustom(PROFILE_DOMAIN);
167
             target.setCustom(PROFILE_DOMAIN);
205
             return;
206
             return;
206
         }
207
         }
207
 
208
 
208
-        final List<String[]> changes = new LinkedList<>();
209
+        final Collection<String[]> changes = new LinkedList<>();
209
 
210
 
210
         synchronized (this) {
211
         synchronized (this) {
211
             final Map<String, Map<String, String>> oldProps = file.getKeyDomains();
212
             final Map<String, Map<String, String>> oldProps = file.getKeyDomains();
276
             // Migrate
277
             // Migrate
277
 
278
 
278
             setOption(PROFILE_DOMAIN, "nicknames", getOption(PROFILE_DOMAIN, "nickname")
279
             setOption(PROFILE_DOMAIN, "nicknames", getOption(PROFILE_DOMAIN, "nickname")
279
-                    + (hasOptionString(PROFILE_DOMAIN, "altnicks") ? "\n"
280
+                    + (hasOptionString(PROFILE_DOMAIN, "altnicks") ? '\n'
280
                     + getOption(PROFILE_DOMAIN, "altnicks") : ""));
281
                     + getOption(PROFILE_DOMAIN, "altnicks") : ""));
281
             unsetOption(PROFILE_DOMAIN, "nickname");
282
             unsetOption(PROFILE_DOMAIN, "nickname");
282
             unsetOption(PROFILE_DOMAIN, "altnicks");
283
             unsetOption(PROFILE_DOMAIN, "altnicks");
349
                 }
350
                 }
350
             }
351
             }
351
 
352
 
352
-            if (!unset && ((oldValue == null && value != null)
353
-                    || (oldValue != null && !oldValue.equals(value)))) {
353
+            if (!unset && (oldValue == null && value != null
354
+                    || oldValue != null && !oldValue.equals(value))) {
354
                 file.getKeyDomain(domain).put(option, value);
355
                 file.getKeyDomain(domain).put(option, value);
355
                 needSave = true;
356
                 needSave = true;
356
             }
357
             }
358
 
359
 
359
         // Fire any setting change listeners now we're no longer holding
360
         // Fire any setting change listeners now we're no longer holding
360
         // a lock on this identity.
361
         // a lock on this identity.
361
-        if (unset || (oldValue == null && value != null)
362
-                || (oldValue != null && !oldValue.equals(value))) {
362
+        if (unset || oldValue == null && value != null
363
+                || oldValue != null && !oldValue.equals(value)) {
363
             fireSettingChange(domain, option);
364
             fireSettingChange(domain, option);
364
         }
365
         }
365
     }
366
     }
411
     public synchronized void save() {
412
     public synchronized void save() {
412
         LOG.info("{}: saving. Needsave = {}", new Object[]{getName(), needSave});
413
         LOG.info("{}: saving. Needsave = {}", new Object[]{getName(), needSave});
413
 
414
 
414
-        if (needSave && file != null && file.isWritable()) {
415
+        if (needSave && file.isWritable()) {
415
             if (myTarget != null && myTarget.getType() == ConfigTarget.TYPE.GLOBAL) {
416
             if (myTarget != null && myTarget.getType() == ConfigTarget.TYPE.GLOBAL) {
416
                 LOG.debug("{}: I'm a global config", getName());
417
                 LOG.debug("{}: I'm a global config", getName());
417
 
418
 
480
 
481
 
481
     @Override
482
     @Override
482
     public synchronized void delete() throws IOException {
483
     public synchronized void delete() throws IOException {
483
-        if (file != null) {
484
-            file.delete();
485
-        }
486
-
484
+        file.delete();
487
         identityManager.removeConfigProvider(this);
485
         identityManager.removeConfigProvider(this);
488
     }
486
     }
489
 
487
 
502
      * @since 0.6.4
500
      * @since 0.6.4
503
      */
501
      */
504
     public boolean isFile(final File target) {
502
     public boolean isFile(final File target) {
505
-        return file != null && file.getFile() != null && file.getFile().equals(target);
503
+        return file.getFile() != null && file.getFile().equals(target);
506
     }
504
     }
507
 
505
 
508
     @Override
506
     @Override
533
     @Override
531
     @Override
534
     public boolean equals(final Object obj) {
532
     public boolean equals(final Object obj) {
535
         return obj instanceof ConfigFileBackedConfigProvider
533
         return obj instanceof ConfigFileBackedConfigProvider
536
-                && getName().equals(((ConfigFileBackedConfigProvider) obj).getName())
537
-                && getTarget() == ((ConfigFileBackedConfigProvider) obj).getTarget();
534
+                && getName().equals(((ConfigProvider) obj).getName())
535
+                && getTarget() == ((ConfigProvider) obj).getTarget();
538
     }
536
     }
539
 
537
 
540
 }
538
 }

+ 14
- 12
src/com/dmdirc/config/IdentityManager.java View File

42
 import java.io.File;
42
 import java.io.File;
43
 import java.io.IOException;
43
 import java.io.IOException;
44
 import java.util.ArrayList;
44
 import java.util.ArrayList;
45
+import java.util.Collection;
45
 import java.util.Collections;
46
 import java.util.Collections;
46
 import java.util.HashMap;
47
 import java.util.HashMap;
47
 import java.util.LinkedHashSet;
48
 import java.util.LinkedHashSet;
48
 import java.util.List;
49
 import java.util.List;
49
 import java.util.Map;
50
 import java.util.Map;
50
-import java.util.Set;
51
 
51
 
52
 import org.slf4j.Logger;
52
 import org.slf4j.Logger;
53
 import org.slf4j.LoggerFactory;
53
 import org.slf4j.LoggerFactory;
160
                 if (!success) {
160
                 if (!success) {
161
                     eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, null,
161
                     eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, null,
162
                             "Unable to create directory for default settings folder ("
162
                             "Unable to create directory for default settings folder ("
163
-                            + target + ")",
163
+                            + target + ')',
164
                             "A file with that name already exists, and couldn't be renamed."
164
                             "A file with that name already exists, and couldn't be renamed."
165
                             + " Rename or delete " + file.getAbsolutePath()));
165
                             + " Rename or delete " + file.getAbsolutePath()));
166
                     continue;
166
                     continue;
175
                 return;
175
                 return;
176
             }
176
             }
177
 
177
 
178
-            if (file.listFiles() == null || file.listFiles().length == 0) {
178
+            final File[] files = file.listFiles();
179
+            if (files == null || files.length == 0) {
179
                 extractIdentities(target);
180
                 extractIdentities(target);
180
             }
181
             }
181
 
182
 
260
         checkNotNull(dir);
261
         checkNotNull(dir);
261
         checkArgument(dir.isDirectory());
262
         checkArgument(dir.isDirectory());
262
 
263
 
263
-        if (dir.listFiles() == null) {
264
+        final File[] files = dir.listFiles();
265
+        if (files == null) {
264
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
266
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
265
                     "Unable to load user identity files from " + dir.getAbsolutePath(), ""));
267
                     "Unable to load user identity files from " + dir.getAbsolutePath(), ""));
266
         } else {
268
         } else {
267
-            for (File file : dir.listFiles()) {
269
+            for (File file : files) {
268
                 if (file.isDirectory()) {
270
                 if (file.isDirectory()) {
269
                     loadUser(file);
271
                     loadUser(file);
270
                 } else {
272
                 } else {
283
     private void loadIdentity(final File file) {
285
     private void loadIdentity(final File file) {
284
         synchronized (identities) {
286
         synchronized (identities) {
285
             for (ConfigProvider identity : getAllIdentities()) {
287
             for (ConfigProvider identity : getAllIdentities()) {
286
-                if ((identity instanceof ConfigFileBackedConfigProvider)
288
+                if (identity instanceof ConfigFileBackedConfigProvider
287
                         && ((ConfigFileBackedConfigProvider) identity).isFile(file)) {
289
                         && ((ConfigFileBackedConfigProvider) identity).isFile(file)) {
288
                     // TODO: This manager should keep a list of files->identities instead of
290
                     // TODO: This manager should keep a list of files->identities instead of
289
                     //       relying on the identities remembering.
291
                     //       relying on the identities remembering.
292
                     } catch (IOException ex) {
294
                     } catch (IOException ex) {
293
                         eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
295
                         eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
294
                                 "I/O error when reloading identity file: "
296
                                 "I/O error when reloading identity file: "
295
-                                + file.getAbsolutePath() + " (" + ex.getMessage() + ")", ""));
297
+                                + file.getAbsolutePath() + " (" + ex.getMessage() + ')', ""));
296
                     } catch (InvalidConfigFileException ex) {
298
                     } catch (InvalidConfigFileException ex) {
297
                         // Do nothing
299
                         // Do nothing
298
                     }
300
                     }
307
         } catch (InvalidIdentityFileException ex) {
309
         } catch (InvalidIdentityFileException ex) {
308
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
310
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
309
                     "Invalid identity file: " + file.getAbsolutePath() + " ("
311
                     "Invalid identity file: " + file.getAbsolutePath() + " ("
310
-                    + ex.getMessage() + ")", ""));
312
+                    + ex.getMessage() + ')', ""));
311
         } catch (IOException ex) {
313
         } catch (IOException ex) {
312
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
314
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
313
                     "I/O error when reading identity file: " + file.getAbsolutePath(), ""));
315
                     "I/O error when reading identity file: " + file.getAbsolutePath(), ""));
321
      *
323
      *
322
      * @since 0.6.4
324
      * @since 0.6.4
323
      */
325
      */
324
-    private Set<ConfigProvider> getAllIdentities() {
325
-        final Set<ConfigProvider> res = new LinkedHashSet<>();
326
+    private Iterable<ConfigProvider> getAllIdentities() {
327
+        final Collection<ConfigProvider> res = new LinkedHashSet<>();
326
 
328
 
327
         for (Map.Entry<String, List<ConfigProvider>> entry : identities.entrySet()) {
329
         for (Map.Entry<String, List<ConfigProvider>> entry : identities.entrySet()) {
328
             res.addAll(entry.getValue());
330
             res.addAll(entry.getValue());
517
                     + "with null or empty channel\n\nChannel: " + channel);
519
                     + "with null or empty channel\n\nChannel: " + channel);
518
         }
520
         }
519
 
521
 
520
-        final String myTarget = (channel + "@" + network).toLowerCase();
522
+        final String myTarget = (channel + '@' + network).toLowerCase();
521
 
523
 
522
         synchronized (identities) {
524
         synchronized (identities) {
523
             for (ConfigProvider identity : identities.safeGet(null)) {
525
             for (ConfigProvider identity : identities.safeGet(null)) {
665
         int attempt = 1;
667
         int attempt = 1;
666
 
668
 
667
         while (file.exists()) {
669
         while (file.exists()) {
668
-            file = new File(identitiesDirectory + name + "-" + attempt);
670
+            file = new File(identitiesDirectory + name + '-' + attempt);
669
             attempt++;
671
             attempt++;
670
         }
672
         }
671
 
673
 

Loading…
Cancel
Save