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,6 +35,7 @@ import java.io.File;
35 35
 import java.io.IOException;
36 36
 import java.io.InputStream;
37 37
 import java.util.ArrayList;
38
+import java.util.Collection;
38 39
 import java.util.HashMap;
39 40
 import java.util.HashSet;
40 41
 import java.util.LinkedList;
@@ -160,7 +161,7 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
160 161
             target.setChannel(getOption(DOMAIN, "channel"));
161 162
         } else if (hasOptionString(DOMAIN, "globaldefault")) {
162 163
             target.setGlobalDefault();
163
-        } else if (hasOptionString(DOMAIN, "global") || (forceDefault && !isProfile())) {
164
+        } else if (hasOptionString(DOMAIN, "global") || forceDefault && !isProfile()) {
164 165
             target.setGlobal();
165 166
         } else if (isProfile()) {
166 167
             target.setCustom(PROFILE_DOMAIN);
@@ -205,7 +206,7 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
205 206
             return;
206 207
         }
207 208
 
208
-        final List<String[]> changes = new LinkedList<>();
209
+        final Collection<String[]> changes = new LinkedList<>();
209 210
 
210 211
         synchronized (this) {
211 212
             final Map<String, Map<String, String>> oldProps = file.getKeyDomains();
@@ -276,7 +277,7 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
276 277
             // Migrate
277 278
 
278 279
             setOption(PROFILE_DOMAIN, "nicknames", getOption(PROFILE_DOMAIN, "nickname")
279
-                    + (hasOptionString(PROFILE_DOMAIN, "altnicks") ? "\n"
280
+                    + (hasOptionString(PROFILE_DOMAIN, "altnicks") ? '\n'
280 281
                     + getOption(PROFILE_DOMAIN, "altnicks") : ""));
281 282
             unsetOption(PROFILE_DOMAIN, "nickname");
282 283
             unsetOption(PROFILE_DOMAIN, "altnicks");
@@ -349,8 +350,8 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
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 355
                 file.getKeyDomain(domain).put(option, value);
355 356
                 needSave = true;
356 357
             }
@@ -358,8 +359,8 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
358 359
 
359 360
         // Fire any setting change listeners now we're no longer holding
360 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 364
             fireSettingChange(domain, option);
364 365
         }
365 366
     }
@@ -411,7 +412,7 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
411 412
     public synchronized void save() {
412 413
         LOG.info("{}: saving. Needsave = {}", new Object[]{getName(), needSave});
413 414
 
414
-        if (needSave && file != null && file.isWritable()) {
415
+        if (needSave && file.isWritable()) {
415 416
             if (myTarget != null && myTarget.getType() == ConfigTarget.TYPE.GLOBAL) {
416 417
                 LOG.debug("{}: I'm a global config", getName());
417 418
 
@@ -480,10 +481,7 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
480 481
 
481 482
     @Override
482 483
     public synchronized void delete() throws IOException {
483
-        if (file != null) {
484
-            file.delete();
485
-        }
486
-
484
+        file.delete();
487 485
         identityManager.removeConfigProvider(this);
488 486
     }
489 487
 
@@ -502,7 +500,7 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
502 500
      * @since 0.6.4
503 501
      */
504 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 506
     @Override
@@ -533,8 +531,8 @@ public class ConfigFileBackedConfigProvider extends BaseConfigProvider implement
533 531
     @Override
534 532
     public boolean equals(final Object obj) {
535 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,12 +42,12 @@ import com.dmdirc.util.resourcemanager.ResourceManager;
42 42
 import java.io.File;
43 43
 import java.io.IOException;
44 44
 import java.util.ArrayList;
45
+import java.util.Collection;
45 46
 import java.util.Collections;
46 47
 import java.util.HashMap;
47 48
 import java.util.LinkedHashSet;
48 49
 import java.util.List;
49 50
 import java.util.Map;
50
-import java.util.Set;
51 51
 
52 52
 import org.slf4j.Logger;
53 53
 import org.slf4j.LoggerFactory;
@@ -160,7 +160,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
160 160
                 if (!success) {
161 161
                     eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, null,
162 162
                             "Unable to create directory for default settings folder ("
163
-                            + target + ")",
163
+                            + target + ')',
164 164
                             "A file with that name already exists, and couldn't be renamed."
165 165
                             + " Rename or delete " + file.getAbsolutePath()));
166 166
                     continue;
@@ -175,7 +175,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
175 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 180
                 extractIdentities(target);
180 181
             }
181 182
 
@@ -260,11 +261,12 @@ public class IdentityManager implements IdentityFactory, IdentityController {
260 261
         checkNotNull(dir);
261 262
         checkArgument(dir.isDirectory());
262 263
 
263
-        if (dir.listFiles() == null) {
264
+        final File[] files = dir.listFiles();
265
+        if (files == null) {
264 266
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
265 267
                     "Unable to load user identity files from " + dir.getAbsolutePath(), ""));
266 268
         } else {
267
-            for (File file : dir.listFiles()) {
269
+            for (File file : files) {
268 270
                 if (file.isDirectory()) {
269 271
                     loadUser(file);
270 272
                 } else {
@@ -283,7 +285,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
283 285
     private void loadIdentity(final File file) {
284 286
         synchronized (identities) {
285 287
             for (ConfigProvider identity : getAllIdentities()) {
286
-                if ((identity instanceof ConfigFileBackedConfigProvider)
288
+                if (identity instanceof ConfigFileBackedConfigProvider
287 289
                         && ((ConfigFileBackedConfigProvider) identity).isFile(file)) {
288 290
                     // TODO: This manager should keep a list of files->identities instead of
289 291
                     //       relying on the identities remembering.
@@ -292,7 +294,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
292 294
                     } catch (IOException ex) {
293 295
                         eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
294 296
                                 "I/O error when reloading identity file: "
295
-                                + file.getAbsolutePath() + " (" + ex.getMessage() + ")", ""));
297
+                                + file.getAbsolutePath() + " (" + ex.getMessage() + ')', ""));
296 298
                     } catch (InvalidConfigFileException ex) {
297 299
                         // Do nothing
298 300
                     }
@@ -307,7 +309,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
307 309
         } catch (InvalidIdentityFileException ex) {
308 310
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
309 311
                     "Invalid identity file: " + file.getAbsolutePath() + " ("
310
-                    + ex.getMessage() + ")", ""));
312
+                    + ex.getMessage() + ')', ""));
311 313
         } catch (IOException ex) {
312 314
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
313 315
                     "I/O error when reading identity file: " + file.getAbsolutePath(), ""));
@@ -321,8 +323,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
321 323
      *
322 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 329
         for (Map.Entry<String, List<ConfigProvider>> entry : identities.entrySet()) {
328 330
             res.addAll(entry.getValue());
@@ -517,7 +519,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
517 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 524
         synchronized (identities) {
523 525
             for (ConfigProvider identity : identities.safeGet(null)) {
@@ -665,7 +667,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
665 667
         int attempt = 1;
666 668
 
667 669
         while (file.exists()) {
668
-            file = new File(identitiesDirectory + name + "-" + attempt);
670
+            file = new File(identitiesDirectory + name + '-' + attempt);
669 671
             attempt++;
670 672
         }
671 673
 

Loading…
Cancel
Save