Ver código fonte

PMD fixes for util

Change-Id: I3fb69847901bb13d9906c10dbae67d1d437daced
Reviewed-on: http://gerrit.dmdirc.com/1702
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.5
Greg Holmes 13 anos atrás
pai
commit
b1c00c3168

+ 12
- 7
src/com/dmdirc/util/ConfigFile.java Ver arquivo

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.util;
24 24
 
25 25
 import java.io.File;
26
-import java.io.FileNotFoundException;
27 26
 import java.io.IOException;
28 27
 import java.io.InputStream;
29 28
 import java.nio.charset.Charset;
@@ -44,7 +43,8 @@ public class ConfigFile extends TextFile {
44 43
     private final List<String> domains = new ArrayList<String>();
45 44
 
46 45
     /** The values associated with each flat domain. */
47
-    private final MapList<String, String> flatdomains = new MapList<String, String>();
46
+    private final MapList<String, String> flatdomains
47
+            = new MapList<String, String>();
48 48
 
49 49
     /** The key/value sets associated with each key domain. */
50 50
     private final Map<String, Map<String, String>> keydomains
@@ -162,7 +162,8 @@ public class ConfigFile extends TextFile {
162 162
         final List<String> lines = new ArrayList<String>();
163 163
 
164 164
         lines.add("# This is a DMDirc configuration file.");
165
-        lines.add("# Written on: " + new GregorianCalendar().getTime().toString());
165
+        lines.add("# Written on: " + new GregorianCalendar().getTime()
166
+                .toString());
166 167
 
167 168
         writeMeta(lines);
168 169
 
@@ -180,7 +181,8 @@ public class ConfigFile extends TextFile {
180 181
                     lines.add("  " + escape(entry));
181 182
                 }
182 183
             } else {
183
-                for (Map.Entry<String, String> entry : keydomains.get(domain).entrySet()) {
184
+                for (Map.Entry<String, String> entry : keydomains.get(domain)
185
+                        .entrySet()) {
184 186
                     lines.add("  " + escape(entry.getKey()) + "="
185 187
                             + escape(entry.getValue()));
186 188
                 }
@@ -197,8 +199,10 @@ public class ConfigFile extends TextFile {
197 199
      */
198 200
     private void writeMeta(final List<String> lines) {
199 201
         lines.add("");
200
-        lines.add("# This section indicates which sections below take key/value");
201
-        lines.add("# pairs, rather than a simple list. It should be placed above");
202
+        lines.add("# This section indicates which sections below take "
203
+                + "key/value");
204
+        lines.add("# pairs, rather than a simple list. It should be "
205
+                + "placed above");
202 206
         lines.add("# any sections that take key/values.");
203 207
         lines.add("keysections:");
204 208
 
@@ -252,7 +256,8 @@ public class ConfigFile extends TextFile {
252 256
      * @return True if the domain is known, false otherwise
253 257
      */
254 258
     public boolean hasDomain(final String domain) {
255
-        return keydomains.containsKey(domain) || flatdomains.containsKey(domain);
259
+        return keydomains.containsKey(domain)
260
+                || flatdomains.containsKey(domain);
256 261
     }
257 262
 
258 263
     /**

+ 2
- 1
src/com/dmdirc/util/DownloadListener.java Ver arquivo

@@ -38,7 +38,8 @@ public interface DownloadListener {
38 38
     void downloadProgress(float percent);
39 39
     
40 40
     /**
41
-     * Called to notify the listener if this download has an indeterminate length.
41
+     * Called to notify the listener if this download has an indeterminate
42
+     * length.
42 43
      * 
43 44
      * @param indeterminate true or false
44 45
      * 

+ 10
- 5
src/com/dmdirc/util/Downloader.java Ver arquivo

@@ -83,7 +83,8 @@ public final class Downloader {
83 83
         BufferedReader in = null;
84 84
 
85 85
         try {
86
-            in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
86
+            in = new BufferedReader(new InputStreamReader(
87
+                    urlConn.getInputStream()));
87 88
 
88 89
             String line;
89 90
 
@@ -110,7 +111,8 @@ public final class Downloader {
110 111
      * @throws java.net.MalformedURLException If the URL is malformed
111 112
      * @throws java.io.IOException If there's an I/O error while downloading
112 113
      */
113
-    public static List<String> getPage(final String url, final Map<String, String> postData)
114
+    public static List<String> getPage(final String url,
115
+            final Map<String, String> postData)
114 116
             throws MalformedURLException, IOException {
115 117
         final StringBuilder data = new StringBuilder();
116 118
 
@@ -174,7 +176,8 @@ public final class Downloader {
174 176
                     output.write(buffer, 0, count);
175 177
 
176 178
                     if (listener != null && length != -1) {
177
-                        listener.downloadProgress(100 * (float) current / length);
179
+                        listener.downloadProgress(100 * (float) current
180
+                                / length);
178 181
                     }
179 182
                 }
180 183
             } while (count > 0);
@@ -193,7 +196,8 @@ public final class Downloader {
193 196
      * @throws java.net.MalformedURLException If the specified URL is malformed
194 197
      * @throws java.io.IOException If an I/O exception occurs while connecting
195 198
      */
196
-    private static URLConnection getConnection(final String url, final String postData)
199
+    private static URLConnection getConnection(final String url,
200
+            final String postData)
197 201
             throws MalformedURLException, IOException {
198 202
         final URL myUrl = new URL(url);
199 203
         final URLConnection urlConn = myUrl.openConnection();
@@ -204,7 +208,8 @@ public final class Downloader {
204 208
         urlConn.setConnectTimeout(10000);
205 209
 
206 210
         if (postData.length() > 0) {
207
-            urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
211
+            urlConn.setRequestProperty("Content-Type",
212
+                    "application/x-www-form-urlencoded");
208 213
 
209 214
             DataOutputStream out = null;
210 215
 

+ 2
- 2
src/com/dmdirc/util/EquatableWeakReference.java Ver arquivo

@@ -39,13 +39,13 @@ public class EquatableWeakReference<T> extends WeakReference<T> {
39 39
      * 
40 40
      * @param referent The object that this weak reference should reference.
41 41
      */
42
-    public EquatableWeakReference(T referent) {
42
+    public EquatableWeakReference(final T referent) {
43 43
         super(referent);
44 44
     }
45 45
 
46 46
     /** {@inheritDoc} */
47 47
     @Override
48
-    public boolean equals(Object obj) {
48
+    public boolean equals(final Object obj) {
49 49
         if (obj instanceof Reference<?>) {
50 50
             return get().equals(((Reference<?>) obj).get());
51 51
         } else {

+ 1
- 1
src/com/dmdirc/util/InvalidConfigFileException.java Ver arquivo

@@ -40,7 +40,7 @@ public class InvalidConfigFileException extends Exception {
40 40
      * 
41 41
      * @param string A description of the exception that occured.
42 42
      */
43
-    public InvalidConfigFileException(String string) {
43
+    public InvalidConfigFileException(final String string) {
44 44
         super(string);
45 45
     }
46 46
 

+ 14
- 13
src/com/dmdirc/util/RollingList.java Ver arquivo

@@ -36,15 +36,12 @@ public class RollingList<T> {
36 36
    
37 37
     /** The items in this rolling list. */
38 38
     private final List<T> items = new ArrayList<T>();
39
-    
40 39
     /** The maximum capacity of this list. */
41 40
     private final int capacity;
42
-    
41
+    /** Whether or not to add a fake empty item to the end of this list. */
42
+    private final boolean addEmpty;
43 43
     /** This list's position pointer. */
44 44
     private int position = 0;
45
-    
46
-    /** Whether or not to add a fake empty item to the end of this list. */
47
-    private boolean addEmpty;
48 45
     /** The "empty" item to be added. */
49 46
     private T empty;
50 47
     
@@ -75,9 +72,10 @@ public class RollingList<T> {
75 72
      * Removes the specified element from this list.
76 73
      * 
77 74
      * @param o The object to be removed from the list.
78
-     * @return True if the list contained the specified element, false otherwise.
75
+     * @return True if the list contained the specified element,
76
+     * false otherwise.
79 77
      */
80
-    public boolean remove(final Object o) {
78
+    public boolean remove(final T o) {
81 79
         return items.remove(o);
82 80
     }
83 81
 
@@ -106,7 +104,7 @@ public class RollingList<T> {
106 104
      * @param o The object to be checked
107 105
      * @return True if this list contains the item, false otherwise.
108 106
      */
109
-    public boolean contains(final Object o) {
107
+    public boolean contains(final T o) {
110 108
         return items.contains(o);
111 109
     }
112 110
 
@@ -125,7 +123,7 @@ public class RollingList<T> {
125 123
      * @param e The element to be added to the list.
126 124
      * @return True
127 125
      */
128
-    public boolean add(T e) {
126
+    public boolean add(final T e) {
129 127
         while (items.size() > capacity - 1) {
130 128
             items.remove(0);
131 129
             position--;
@@ -148,17 +146,19 @@ public class RollingList<T> {
148 146
      * 
149 147
      * @param position The new position
150 148
      */
151
-    public void setPosition(int position) {
149
+    public void setPosition(final int position) {
152 150
         this.position = position;
153 151
     }    
154 152
     
155 153
     /**
156
-     * Determines if there is an element after the positional pointer of the list.
154
+     * Determines if there is an element after the positional pointer of
155
+     * the list.
157 156
      * 
158 157
      * @return True if there is an element, false otherwise.
159 158
      */
160 159
     public boolean hasNext() {
161
-        return (items.size() > position + 1) || ((items.size() > position) && addEmpty);
160
+        return (items.size() > position + 1) || ((items.size() > position)
161
+                && addEmpty);
162 162
     }
163 163
     
164 164
     /**
@@ -176,7 +176,8 @@ public class RollingList<T> {
176 176
     }
177 177
     
178 178
     /**
179
-     * Determines if there is an element befpre the positional pointer of the list.
179
+     * Determines if there is an element befpre the positional pointer of
180
+     * the list.
180 181
      * 
181 182
      * @return True if there is an element, false otherwise.
182 183
      */    

+ 6
- 3
src/com/dmdirc/util/WeakList.java Ver arquivo

@@ -39,7 +39,8 @@ import java.util.ListIterator;
39 39
 public class WeakList<T> implements List<T> {
40 40
 
41 41
     /** The items in this list. */
42
-    private final List<WeakReference<T>> list = new ArrayList<WeakReference<T>>();
42
+    private final List<WeakReference<T>> list
43
+            = new ArrayList<WeakReference<T>>();
43 44
 
44 45
     /**
45 46
      * Removes any entries from the list that have been GC'd.
@@ -79,8 +80,10 @@ public class WeakList<T> implements List<T> {
79 80
      * a weak reference.
80 81
      */
81 82
     @SuppressWarnings(value = "unchecked")
82
-    private Collection<WeakReference<T>> referenceCollection(final Collection<?> c) {
83
-        final Collection<WeakReference<T>> res = new ArrayList<WeakReference<T>>();
83
+    private Collection<WeakReference<T>> referenceCollection(
84
+            final Collection<?> c) {
85
+        final Collection<WeakReference<T>> res
86
+                = new ArrayList<WeakReference<T>>();
84 87
 
85 88
         for (Object item : c) {
86 89
             res.add(new EquatableWeakReference(item));

+ 2
- 1
src/com/dmdirc/util/validators/ColourValidator.java Ver arquivo

@@ -28,7 +28,8 @@ package com.dmdirc.util.validators;
28 28
  * @since 0.6.5
29 29
  * @author chris
30 30
  */
31
-public class ColourValidator extends RegexStringValidator implements Validator<String> {
31
+public class ColourValidator extends RegexStringValidator implements
32
+        Validator<String> {
32 33
 
33 34
     /**
34 35
      * Creates a new colour validator.

+ 2
- 1
src/com/dmdirc/util/validators/NicknameValidator.java Ver arquivo

@@ -28,7 +28,8 @@ package com.dmdirc.util.validators;
28 28
 public class NicknameValidator implements Validator<String> {
29 29
 
30 30
     /** Nickname regex. */
31
-    private static final String NICKNAME_REGEX = "[A-Za-z0-9\\[\\]{|}\\-\\^\\\\\\`\\_]+";
31
+    private static final String NICKNAME_REGEX
32
+            = "[A-Za-z0-9\\[\\]{|}\\-\\^\\\\\\`\\_]+";
32 33
     /** Failure reason. */
33 34
     private static final String FAILURE_REASON = "Nickname must only contain "
34 35
             + "letters, numbers and []{}|-^\\.`_";

+ 1
- 1
src/com/dmdirc/util/validators/NumericalValidator.java Ver arquivo

@@ -41,7 +41,7 @@ public class NumericalValidator implements Validator<String> {
41 41
      * @param min The minimum value for the number, or -1 for unlimited.
42 42
      * @param max The maximum value for the number, or -1 for unlimited.
43 43
      */
44
-    public NumericalValidator(int min, int max) {
44
+    public NumericalValidator(final int min, final int max) {
45 45
         this.max = max == -1 ? Integer.MAX_VALUE : max;
46 46
         this.min = min == -1 ? Integer.MIN_VALUE : min;
47 47
         if (this.min > this.max) {

+ 4
- 2
src/com/dmdirc/util/validators/StringLengthValidator.java Ver arquivo

@@ -50,9 +50,11 @@ public class StringLengthValidator implements Validator<String> {
50 50
     @Override
51 51
     public ValidationResponse validate(final String object) {
52 52
         if (object.length() < min && min != -1) {
53
-            return new ValidationResponse("Must be at least " + min + " characters long");
53
+            return new ValidationResponse("Must be at least " + min
54
+                    + " characters long");
54 55
         } else if (object.length() > max && max != -1) {
55
-            return new ValidationResponse("Must be at most " + max + " characters long");
56
+            return new ValidationResponse("Must be at most " + max
57
+                    + " characters long");
56 58
         } else {
57 59
             return new ValidationResponse();
58 60
         }

+ 2
- 3
src/com/dmdirc/util/validators/ValidatorChain.java Ver arquivo

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.util.validators;
24 24
 
25 25
 import java.util.ArrayList;
26
+import java.util.Arrays;
26 27
 import java.util.List;
27 28
 
28 29
 /**
@@ -43,9 +44,7 @@ public class ValidatorChain<A> implements Validator<A> {
43 44
      * @param validators The validators to be used in this chain.
44 45
      */
45 46
     public ValidatorChain(final Validator<A> ... validators) {
46
-        for (Validator<A> validator : validators) {
47
-            validatorList.add(validator);
48
-        }
47
+        validatorList.addAll(Arrays.asList(validators));
49 48
     }
50 49
 
51 50
     /** {@inheritDoc} */

Carregando…
Cancelar
Salvar