Browse Source

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 years ago
parent
commit
b1c00c3168

+ 12
- 7
src/com/dmdirc/util/ConfigFile.java View File

23
 package com.dmdirc.util;
23
 package com.dmdirc.util;
24
 
24
 
25
 import java.io.File;
25
 import java.io.File;
26
-import java.io.FileNotFoundException;
27
 import java.io.IOException;
26
 import java.io.IOException;
28
 import java.io.InputStream;
27
 import java.io.InputStream;
29
 import java.nio.charset.Charset;
28
 import java.nio.charset.Charset;
44
     private final List<String> domains = new ArrayList<String>();
43
     private final List<String> domains = new ArrayList<String>();
45
 
44
 
46
     /** The values associated with each flat domain. */
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
     /** The key/value sets associated with each key domain. */
49
     /** The key/value sets associated with each key domain. */
50
     private final Map<String, Map<String, String>> keydomains
50
     private final Map<String, Map<String, String>> keydomains
162
         final List<String> lines = new ArrayList<String>();
162
         final List<String> lines = new ArrayList<String>();
163
 
163
 
164
         lines.add("# This is a DMDirc configuration file.");
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
         writeMeta(lines);
168
         writeMeta(lines);
168
 
169
 
180
                     lines.add("  " + escape(entry));
181
                     lines.add("  " + escape(entry));
181
                 }
182
                 }
182
             } else {
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
                     lines.add("  " + escape(entry.getKey()) + "="
186
                     lines.add("  " + escape(entry.getKey()) + "="
185
                             + escape(entry.getValue()));
187
                             + escape(entry.getValue()));
186
                 }
188
                 }
197
      */
199
      */
198
     private void writeMeta(final List<String> lines) {
200
     private void writeMeta(final List<String> lines) {
199
         lines.add("");
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
         lines.add("# any sections that take key/values.");
206
         lines.add("# any sections that take key/values.");
203
         lines.add("keysections:");
207
         lines.add("keysections:");
204
 
208
 
252
      * @return True if the domain is known, false otherwise
256
      * @return True if the domain is known, false otherwise
253
      */
257
      */
254
     public boolean hasDomain(final String domain) {
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 View File

38
     void downloadProgress(float percent);
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
      * @param indeterminate true or false
44
      * @param indeterminate true or false
44
      * 
45
      * 

+ 10
- 5
src/com/dmdirc/util/Downloader.java View File

83
         BufferedReader in = null;
83
         BufferedReader in = null;
84
 
84
 
85
         try {
85
         try {
86
-            in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
86
+            in = new BufferedReader(new InputStreamReader(
87
+                    urlConn.getInputStream()));
87
 
88
 
88
             String line;
89
             String line;
89
 
90
 
110
      * @throws java.net.MalformedURLException If the URL is malformed
111
      * @throws java.net.MalformedURLException If the URL is malformed
111
      * @throws java.io.IOException If there's an I/O error while downloading
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
             throws MalformedURLException, IOException {
116
             throws MalformedURLException, IOException {
115
         final StringBuilder data = new StringBuilder();
117
         final StringBuilder data = new StringBuilder();
116
 
118
 
174
                     output.write(buffer, 0, count);
176
                     output.write(buffer, 0, count);
175
 
177
 
176
                     if (listener != null && length != -1) {
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
             } while (count > 0);
183
             } while (count > 0);
193
      * @throws java.net.MalformedURLException If the specified URL is malformed
196
      * @throws java.net.MalformedURLException If the specified URL is malformed
194
      * @throws java.io.IOException If an I/O exception occurs while connecting
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
             throws MalformedURLException, IOException {
201
             throws MalformedURLException, IOException {
198
         final URL myUrl = new URL(url);
202
         final URL myUrl = new URL(url);
199
         final URLConnection urlConn = myUrl.openConnection();
203
         final URLConnection urlConn = myUrl.openConnection();
204
         urlConn.setConnectTimeout(10000);
208
         urlConn.setConnectTimeout(10000);
205
 
209
 
206
         if (postData.length() > 0) {
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
             DataOutputStream out = null;
214
             DataOutputStream out = null;
210
 
215
 

+ 2
- 2
src/com/dmdirc/util/EquatableWeakReference.java View File

39
      * 
39
      * 
40
      * @param referent The object that this weak reference should reference.
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
         super(referent);
43
         super(referent);
44
     }
44
     }
45
 
45
 
46
     /** {@inheritDoc} */
46
     /** {@inheritDoc} */
47
     @Override
47
     @Override
48
-    public boolean equals(Object obj) {
48
+    public boolean equals(final Object obj) {
49
         if (obj instanceof Reference<?>) {
49
         if (obj instanceof Reference<?>) {
50
             return get().equals(((Reference<?>) obj).get());
50
             return get().equals(((Reference<?>) obj).get());
51
         } else {
51
         } else {

+ 1
- 1
src/com/dmdirc/util/InvalidConfigFileException.java View File

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

+ 14
- 13
src/com/dmdirc/util/RollingList.java View File

36
    
36
    
37
     /** The items in this rolling list. */
37
     /** The items in this rolling list. */
38
     private final List<T> items = new ArrayList<T>();
38
     private final List<T> items = new ArrayList<T>();
39
-    
40
     /** The maximum capacity of this list. */
39
     /** The maximum capacity of this list. */
41
     private final int capacity;
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
     /** This list's position pointer. */
43
     /** This list's position pointer. */
44
     private int position = 0;
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
     /** The "empty" item to be added. */
45
     /** The "empty" item to be added. */
49
     private T empty;
46
     private T empty;
50
     
47
     
75
      * Removes the specified element from this list.
72
      * Removes the specified element from this list.
76
      * 
73
      * 
77
      * @param o The object to be removed from the list.
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
         return items.remove(o);
79
         return items.remove(o);
82
     }
80
     }
83
 
81
 
106
      * @param o The object to be checked
104
      * @param o The object to be checked
107
      * @return True if this list contains the item, false otherwise.
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
         return items.contains(o);
108
         return items.contains(o);
111
     }
109
     }
112
 
110
 
125
      * @param e The element to be added to the list.
123
      * @param e The element to be added to the list.
126
      * @return True
124
      * @return True
127
      */
125
      */
128
-    public boolean add(T e) {
126
+    public boolean add(final T e) {
129
         while (items.size() > capacity - 1) {
127
         while (items.size() > capacity - 1) {
130
             items.remove(0);
128
             items.remove(0);
131
             position--;
129
             position--;
148
      * 
146
      * 
149
      * @param position The new position
147
      * @param position The new position
150
      */
148
      */
151
-    public void setPosition(int position) {
149
+    public void setPosition(final int position) {
152
         this.position = position;
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
      * @return True if there is an element, false otherwise.
157
      * @return True if there is an element, false otherwise.
159
      */
158
      */
160
     public boolean hasNext() {
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
     }
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
      * @return True if there is an element, false otherwise.
182
      * @return True if there is an element, false otherwise.
182
      */    
183
      */    

+ 6
- 3
src/com/dmdirc/util/WeakList.java View File

39
 public class WeakList<T> implements List<T> {
39
 public class WeakList<T> implements List<T> {
40
 
40
 
41
     /** The items in this list. */
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
      * Removes any entries from the list that have been GC'd.
46
      * Removes any entries from the list that have been GC'd.
79
      * a weak reference.
80
      * a weak reference.
80
      */
81
      */
81
     @SuppressWarnings(value = "unchecked")
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
         for (Object item : c) {
88
         for (Object item : c) {
86
             res.add(new EquatableWeakReference(item));
89
             res.add(new EquatableWeakReference(item));

+ 2
- 1
src/com/dmdirc/util/validators/ColourValidator.java View File

28
  * @since 0.6.5
28
  * @since 0.6.5
29
  * @author chris
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
      * Creates a new colour validator.
35
      * Creates a new colour validator.

+ 2
- 1
src/com/dmdirc/util/validators/NicknameValidator.java View File

28
 public class NicknameValidator implements Validator<String> {
28
 public class NicknameValidator implements Validator<String> {
29
 
29
 
30
     /** Nickname regex. */
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
     /** Failure reason. */
33
     /** Failure reason. */
33
     private static final String FAILURE_REASON = "Nickname must only contain "
34
     private static final String FAILURE_REASON = "Nickname must only contain "
34
             + "letters, numbers and []{}|-^\\.`_";
35
             + "letters, numbers and []{}|-^\\.`_";

+ 1
- 1
src/com/dmdirc/util/validators/NumericalValidator.java View File

41
      * @param min The minimum value for the number, or -1 for unlimited.
41
      * @param min The minimum value for the number, or -1 for unlimited.
42
      * @param max The maximum value for the number, or -1 for unlimited.
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
         this.max = max == -1 ? Integer.MAX_VALUE : max;
45
         this.max = max == -1 ? Integer.MAX_VALUE : max;
46
         this.min = min == -1 ? Integer.MIN_VALUE : min;
46
         this.min = min == -1 ? Integer.MIN_VALUE : min;
47
         if (this.min > this.max) {
47
         if (this.min > this.max) {

+ 4
- 2
src/com/dmdirc/util/validators/StringLengthValidator.java View File

50
     @Override
50
     @Override
51
     public ValidationResponse validate(final String object) {
51
     public ValidationResponse validate(final String object) {
52
         if (object.length() < min && min != -1) {
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
         } else if (object.length() > max && max != -1) {
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
         } else {
58
         } else {
57
             return new ValidationResponse();
59
             return new ValidationResponse();
58
         }
60
         }

+ 2
- 3
src/com/dmdirc/util/validators/ValidatorChain.java View File

23
 package com.dmdirc.util.validators;
23
 package com.dmdirc.util.validators;
24
 
24
 
25
 import java.util.ArrayList;
25
 import java.util.ArrayList;
26
+import java.util.Arrays;
26
 import java.util.List;
27
 import java.util.List;
27
 
28
 
28
 /**
29
 /**
43
      * @param validators The validators to be used in this chain.
44
      * @param validators The validators to be used in this chain.
44
      */
45
      */
45
     public ValidatorChain(final Validator<A> ... validators) {
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
     /** {@inheritDoc} */
50
     /** {@inheritDoc} */

Loading…
Cancel
Save