Browse Source

Java 7 conversions

Change-Id: Ib05f625f14ab2f486f0c83c47c860dd0f0ef3ba1
Reviewed-on: http://gerrit.dmdirc.com/2896
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/96/2896/3
Greg Holmes 10 years ago
parent
commit
779a61d876

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

44
      * @return An array of arguments corresponding to the command
44
      * @return An array of arguments corresponding to the command
45
      */
45
      */
46
     public static String[] parseArguments(final String command) {
46
     public static String[] parseArguments(final String command) {
47
-        final List<String> args = new ArrayList<String>();
47
+        final List<String> args = new ArrayList<>();
48
         final StringBuilder builder = new StringBuilder();
48
         final StringBuilder builder = new StringBuilder();
49
         boolean inquote = false;
49
         boolean inquote = false;
50
 
50
 

+ 3
- 14
src/com/dmdirc/util/SimpleInjector.java View File

23
 package com.dmdirc.util;
23
 package com.dmdirc.util;
24
 
24
 
25
 import java.lang.reflect.Constructor;
25
 import java.lang.reflect.Constructor;
26
-import java.lang.reflect.InvocationTargetException;
27
 import java.util.HashMap;
26
 import java.util.HashMap;
28
 import java.util.Map;
27
 import java.util.Map;
29
 
28
 
40
     private final SimpleInjector[] parents;
39
     private final SimpleInjector[] parents;
41
 
40
 
42
     /** A mapping of known classes to the objects that should be injected. */
41
     /** A mapping of known classes to the objects that should be injected. */
43
-    private final Map<Class<?>, Object> parameters
44
-            = new HashMap<Class<?>, Object>();
42
+    private final Map<Class<?>, Object> parameters = new HashMap<>();
45
 
43
 
46
     /**
44
     /**
47
      * Creates a new injector which will inherit injection parameters from
45
      * Creates a new injector which will inherit injection parameters from
97
      * @return A map of injectable parameters
95
      * @return A map of injectable parameters
98
      */
96
      */
99
     public Map<Class<?>, Object> getParameters() {
97
     public Map<Class<?>, Object> getParameters() {
100
-        final Map<Class<?>, Object> localParams
101
-                = new HashMap<Class<?>, Object>(parameters.size());
98
+        final Map<Class<?>, Object> localParams = new HashMap<>(parameters.size());
102
 
99
 
103
         for (SimpleInjector parent : parents) {
100
         for (SimpleInjector parent : parents) {
104
             localParams.putAll(parent.getParameters());
101
             localParams.putAll(parent.getParameters());
146
             if (i == args.length) {
143
             if (i == args.length) {
147
                 try {
144
                 try {
148
                     return ctor.newInstance(args);
145
                     return ctor.newInstance(args);
149
-                } catch (IllegalAccessException ex) {
146
+                } catch (ReflectiveOperationException ex) {
150
                     throwable = ex;
147
                     throwable = ex;
151
-                } catch (IllegalArgumentException ex) {
152
-                    throwable = ex;
153
-                } catch (InstantiationException ex) {
154
-                    throwable = ex;
155
-                } catch (InvocationTargetException ex) {
156
-                    throwable = ex;
157
-                } catch (LinkageError err) {
158
-                    throwable = err;
159
                 }
148
                 }
160
             }
149
             }
161
         }
150
         }

+ 6
- 6
src/com/dmdirc/util/collections/DoubleMap.java View File

41
 public class DoubleMap<A,B> implements Map<A, B> {
41
 public class DoubleMap<A,B> implements Map<A, B> {
42
 
42
 
43
     /** The keys in this map. */
43
     /** The keys in this map. */
44
-    protected final List<A> keys = new ArrayList<A>();
44
+    protected final List<A> keys = new ArrayList<>();
45
     /** The values in this map. */
45
     /** The values in this map. */
46
-    protected final List<B> values = new ArrayList<B>();
46
+    protected final List<B> values = new ArrayList<>();
47
 
47
 
48
     /**
48
     /**
49
      * Retrieves the value associated with the specified key.
49
      * Retrieves the value associated with the specified key.
87
     /** {@inheritDoc} */
87
     /** {@inheritDoc} */
88
     @Override
88
     @Override
89
     public Set<A> keySet() {
89
     public Set<A> keySet() {
90
-        return new HashSet<A>(keys);
90
+        return new HashSet<>(keys);
91
     }
91
     }
92
 
92
 
93
     /** {@inheritDoc} */
93
     /** {@inheritDoc} */
152
     /** {@inheritDoc} */
152
     /** {@inheritDoc} */
153
     @Override
153
     @Override
154
     public Collection<B> values() {
154
     public Collection<B> values() {
155
-        return new ArrayList<B>(values);
155
+        return new ArrayList<>(values);
156
     }
156
     }
157
 
157
 
158
     /** {@inheritDoc} */
158
     /** {@inheritDoc} */
159
     @Override
159
     @Override
160
     public Set<Entry<A, B>> entrySet() {
160
     public Set<Entry<A, B>> entrySet() {
161
-        final Set<Entry<A, B>> set = new HashSet<Entry<A, B>>();
161
+        final Set<Entry<A, B>> set = new HashSet<>();
162
         for (A key : keys) {
162
         for (A key : keys) {
163
-            set.add(new SimpleEntry<A, B>(key, getValue(key)));
163
+            set.add(new SimpleEntry<>(key, getValue(key)));
164
         }
164
         }
165
         return set;
165
         return set;
166
     }
166
     }

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

55
      * Creates a new, empty MapList.
55
      * Creates a new, empty MapList.
56
      */
56
      */
57
     public MapList() {
57
     public MapList() {
58
-        map = new HashMap<S, List<T>>();
58
+        map = new HashMap<>();
59
     }
59
     }
60
 
60
 
61
     /**
61
     /**
255
      * @return This MapList's map.
255
      * @return This MapList's map.
256
      */
256
      */
257
     public Map<S, List<T>> getMap() {
257
     public Map<S, List<T>> getMap() {
258
-        return new HashMap<S, List<T>>(map);
258
+        return new HashMap<>(map);
259
     }
259
     }
260
 
260
 
261
 }
261
 }

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

33
 public class RollingList<T> {
33
 public class RollingList<T> {
34
 
34
 
35
     /** The items in this rolling list. */
35
     /** The items in this rolling list. */
36
-    private final List<T> items = new ArrayList<T>();
36
+    private final List<T> items = new ArrayList<>();
37
     /** The maximum capacity of this list. */
37
     /** The maximum capacity of this list. */
38
     private final int capacity;
38
     private final int capacity;
39
     /** Whether or not to add a fake empty item to the end of this list. */
39
     /** Whether or not to add a fake empty item to the end of this list. */
212
      * @return A list of items in this rolling list.
212
      * @return A list of items in this rolling list.
213
      */
213
      */
214
     public List<T> getList() {
214
     public List<T> getList() {
215
-        return new ArrayList<T>(items);
215
+        return new ArrayList<>(items);
216
     }
216
     }
217
 }
217
 }

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

38
 public class WeakList<T> implements List<T> {
38
 public class WeakList<T> implements List<T> {
39
 
39
 
40
     /** The items in this list. */
40
     /** The items in this list. */
41
-    private final List<WeakReference<T>> list
42
-            = new ArrayList<WeakReference<T>>();
41
+    private final List<WeakReference<T>> list = new ArrayList<>();
43
 
42
 
44
     /**
43
     /**
45
      * Removes any entries from the list that have been GC'd.
44
      * Removes any entries from the list that have been GC'd.
59
      * @return A list containing the items referenced by the specified list
58
      * @return A list containing the items referenced by the specified list
60
      */
59
      */
61
     private List<T> dereferenceList(final List<WeakReference<T>> list) {
60
     private List<T> dereferenceList(final List<WeakReference<T>> list) {
62
-        final List<T> res = new ArrayList<T>();
61
+        final List<T> res = new ArrayList<>();
63
 
62
 
64
         for (WeakReference<T> item : list) {
63
         for (WeakReference<T> item : list) {
65
             if (item.get() != null) {
64
             if (item.get() != null) {
81
     @SuppressWarnings({"unchecked", "rawtypes"})
80
     @SuppressWarnings({"unchecked", "rawtypes"})
82
     private Collection<WeakReference<T>> referenceCollection(
81
     private Collection<WeakReference<T>> referenceCollection(
83
             final Collection<?> c) {
82
             final Collection<?> c) {
84
-        final Collection<WeakReference<T>> res
85
-                = new ArrayList<WeakReference<T>>();
83
+        final Collection<WeakReference<T>> res = new ArrayList<>();
86
 
84
 
87
         for (Object item : c) {
85
         for (Object item : c) {
88
             res.add(new EquatableWeakReference(item));
86
             res.add(new EquatableWeakReference(item));
135
     /** {@inheritDoc} */
133
     /** {@inheritDoc} */
136
     @Override
134
     @Override
137
     public boolean add(final T e) {
135
     public boolean add(final T e) {
138
-        return list.add(new EquatableWeakReference<T>(e));
136
+        return list.add(new EquatableWeakReference<>(e));
139
     }
137
     }
140
 
138
 
141
     /** {@inheritDoc} */
139
     /** {@inheritDoc} */
192
     /** {@inheritDoc} */
190
     /** {@inheritDoc} */
193
     @Override
191
     @Override
194
     public T set(final int index, final T element) {
192
     public T set(final int index, final T element) {
195
-        list.set(index, new EquatableWeakReference<T>(element));
193
+        list.set(index, new EquatableWeakReference<>(element));
196
 
194
 
197
         return element;
195
         return element;
198
     }
196
     }
200
     /** {@inheritDoc} */
198
     /** {@inheritDoc} */
201
     @Override
199
     @Override
202
     public void add(final int index, final T element) {
200
     public void add(final int index, final T element) {
203
-        list.add(index, new EquatableWeakReference<T>(element));
201
+        list.add(index, new EquatableWeakReference<>(element));
204
     }
202
     }
205
 
203
 
206
     /** {@inheritDoc} */
204
     /** {@inheritDoc} */

+ 5
- 6
src/com/dmdirc/util/io/ConfigFile.java View File

23
 package com.dmdirc.util.io;
23
 package com.dmdirc.util.io;
24
 
24
 
25
 import com.dmdirc.util.collections.MapList;
25
 import com.dmdirc.util.collections.MapList;
26
+
26
 import java.io.File;
27
 import java.io.File;
27
 import java.io.IOException;
28
 import java.io.IOException;
28
 import java.io.InputStream;
29
 import java.io.InputStream;
39
 public class ConfigFile extends TextFile {
40
 public class ConfigFile extends TextFile {
40
 
41
 
41
     /** A list of domains in this config file. */
42
     /** A list of domains in this config file. */
42
-    private final List<String> domains = new ArrayList<String>();
43
+    private final List<String> domains = new ArrayList<>();
43
 
44
 
44
     /** The values associated with each flat domain. */
45
     /** The values associated with each flat domain. */
45
-    private final MapList<String, String> flatdomains
46
-            = new MapList<String, String>();
46
+    private final MapList<String, String> flatdomains = new MapList<>();
47
 
47
 
48
     /** The key/value sets associated with each key domain. */
48
     /** The key/value sets associated with each key domain. */
49
-    private final Map<String, Map<String, String>> keydomains
50
-            = new HashMap<String, Map<String, String>>();
49
+    private final Map<String, Map<String, String>> keydomains = new HashMap<>();
51
 
50
 
52
     /** Whether or not we should automatically create domains. */
51
     /** Whether or not we should automatically create domains. */
53
     private boolean automake;
52
     private boolean automake;
158
                     + "that isn't writable");
157
                     + "that isn't writable");
159
         }
158
         }
160
 
159
 
161
-        final List<String> lines = new ArrayList<String>();
160
+        final List<String> lines = new ArrayList<>();
162
 
161
 
163
         lines.add("# This is a DMDirc configuration file.");
162
         lines.add("# This is a DMDirc configuration file.");
164
         lines.add("# Written on: " + new GregorianCalendar().getTime()
163
         lines.add("# Written on: " + new GregorianCalendar().getTime()

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

71
     public static List<String> getPage(final String url, final String postData)
71
     public static List<String> getPage(final String url, final String postData)
72
             throws IOException {
72
             throws IOException {
73
 
73
 
74
-        final List<String> res = new ArrayList<String>();
74
+        final List<String> res = new ArrayList<>();
75
 
75
 
76
         final URLConnection urlConn = getConnection(url, postData);
76
         final URLConnection urlConn = getConnection(url, postData);
77
 
77
 

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

127
         }
127
         }
128
         // Used to store result to output.
128
         // Used to store result to output.
129
 
129
 
130
-        final ArrayList<Byte> line = new ArrayList<Byte>(seekLength);
130
+        final ArrayList<Byte> line = new ArrayList<>(seekLength);
131
         // Used to store position in file pre-read
131
         // Used to store position in file pre-read
132
         long fp = 0;
132
         long fp = 0;
133
         // Used to store position in file when this is called
133
         // Used to store position in file when this is called
224
      * @return The requested lines
224
      * @return The requested lines
225
      */
225
      */
226
     public Stack<String> getLines(final int numLines) {
226
     public Stack<String> getLines(final int numLines) {
227
-        final Stack<String> result = new Stack<String>();
227
+        final Stack<String> result = new Stack<>();
228
         for (int i = 0; i < numLines; ++i) {
228
         for (int i = 0; i < numLines; ++i) {
229
             try {
229
             try {
230
                 result.push(getNextLine());
230
                 result.push(getNextLine());

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

133
             inputStream = file == null ? is : new FileInputStream(file);
133
             inputStream = file == null ? is : new FileInputStream(file);
134
             inputReader = new InputStreamReader(inputStream, charset);
134
             inputReader = new InputStreamReader(inputStream, charset);
135
             reader = new BufferedReader(inputReader);
135
             reader = new BufferedReader(inputReader);
136
-            lines = new ArrayList<String>();
136
+            lines = new ArrayList<>();
137
 
137
 
138
             String line;
138
             String line;
139
 
139
 

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

35
 public class ValidatorChain<A> implements Validator<A> {
35
 public class ValidatorChain<A> implements Validator<A> {
36
 
36
 
37
     /** A list of validators to use. */
37
     /** A list of validators to use. */
38
-    private final List<Validator<A>> validatorList
39
-            = new ArrayList<Validator<A>>();
38
+    private final List<Validator<A>> validatorList = new ArrayList<>();
40
 
39
 
41
     /**
40
     /**
42
      * Creates a new validator chain containing the specified validators.
41
      * Creates a new validator chain containing the specified validators.

+ 4
- 4
test/com/dmdirc/util/collections/DoubleMapTest.java View File

30
 
30
 
31
     @Test
31
     @Test
32
     public void testPut() {
32
     public void testPut() {
33
-        final DoubleMap<String, String> dm = new DoubleMap<String, String>();
33
+        final DoubleMap<String, String> dm = new DoubleMap<>();
34
         dm.put("a", "b");
34
         dm.put("a", "b");
35
         
35
         
36
         assertEquals(1, dm.keySet().size());
36
         assertEquals(1, dm.keySet().size());
41
     
41
     
42
     @Test(expected=NullPointerException.class)
42
     @Test(expected=NullPointerException.class)
43
     public void testPutNull1() {
43
     public void testPutNull1() {
44
-        final DoubleMap<String, String> dm = new DoubleMap<String, String>();
44
+        final DoubleMap<String, String> dm = new DoubleMap<>();
45
         dm.put(null, "b");
45
         dm.put(null, "b");
46
     }
46
     }
47
     
47
     
48
     @Test(expected=NullPointerException.class)
48
     @Test(expected=NullPointerException.class)
49
     public void testPutNull2() {
49
     public void testPutNull2() {
50
-        final DoubleMap<String, String> dm = new DoubleMap<String, String>();
50
+        final DoubleMap<String, String> dm = new DoubleMap<>();
51
         dm.put("a", null);
51
         dm.put("a", null);
52
     }    
52
     }    
53
     
53
     
54
     @Test
54
     @Test
55
     public void testGet() {
55
     public void testGet() {
56
-        final DoubleMap<String, String> dm = new DoubleMap<String, String>();
56
+        final DoubleMap<String, String> dm = new DoubleMap<>();
57
         dm.put("a", "b");
57
         dm.put("a", "b");
58
         dm.put("b", "c");
58
         dm.put("b", "c");
59
         dm.put("c", "a");
59
         dm.put("c", "a");

+ 3
- 3
test/com/dmdirc/util/collections/EquatableWeakReferenceTest.java View File

32
     @Test
32
     @Test
33
     public void testEquals() {
33
     public void testEquals() {
34
         final Object myObject = "moo";
34
         final Object myObject = "moo";
35
-        final Reference<Object> myRef = new WeakReference<Object>(myObject);
36
-        final EquatableWeakReference<Object> ewf = new EquatableWeakReference<Object>(myObject);
35
+        final Reference<Object> myRef = new WeakReference<>(myObject);
36
+        final EquatableWeakReference<Object> ewf = new EquatableWeakReference<>(myObject);
37
 
37
 
38
         assertTrue(ewf.equals(myObject));
38
         assertTrue(ewf.equals(myObject));
39
         assertTrue(ewf.equals(myRef));
39
         assertTrue(ewf.equals(myRef));
44
     @Test
44
     @Test
45
     public void testHashCode() {
45
     public void testHashCode() {
46
         final Object myObject = "moo";
46
         final Object myObject = "moo";
47
-        final EquatableWeakReference<Object> ewf = new EquatableWeakReference<Object>(myObject);
47
+        final EquatableWeakReference<Object> ewf = new EquatableWeakReference<>(myObject);
48
         
48
         
49
         assertEquals(myObject.hashCode(), ewf.hashCode());
49
         assertEquals(myObject.hashCode(), ewf.hashCode());
50
     }
50
     }

+ 15
- 15
test/com/dmdirc/util/collections/MapListTest.java View File

33
 
33
 
34
     @Test
34
     @Test
35
     public void testIsEmpty() {
35
     public void testIsEmpty() {
36
-        final MapList<String, String> test = new MapList<String, String>();
36
+        final MapList<String, String> test = new MapList<>();
37
         assertTrue(test.isEmpty());
37
         assertTrue(test.isEmpty());
38
 
38
 
39
         test.add("a", "b");
39
         test.add("a", "b");
44
 
44
 
45
     @Test
45
     @Test
46
     public void testAddCollection() {
46
     public void testAddCollection() {
47
-        final MapList<String, String> test = new MapList<String, String>();
48
-        final List<String> testList = new ArrayList<String>();
47
+        final MapList<String, String> test = new MapList<>();
48
+        final List<String> testList = new ArrayList<>();
49
         testList.add("d");
49
         testList.add("d");
50
         testList.add("e");
50
         testList.add("e");
51
         test.add("key", testList);
51
         test.add("key", testList);
57
 
57
 
58
     @Test
58
     @Test
59
     public void testClear() {
59
     public void testClear() {
60
-        final MapList<String, String> test = new MapList<String, String>();
60
+        final MapList<String, String> test = new MapList<>();
61
         test.add("a", "b");
61
         test.add("a", "b");
62
         test.add("d", "e");
62
         test.add("d", "e");
63
         test.clear();
63
         test.clear();
66
 
66
 
67
     @Test
67
     @Test
68
     public void testClearKey() {
68
     public void testClearKey() {
69
-        final MapList<String, String> test = new MapList<String, String>();
69
+        final MapList<String, String> test = new MapList<>();
70
         test.add("a", "b");
70
         test.add("a", "b");
71
         test.add("d", "e");
71
         test.add("d", "e");
72
         test.clear("a");
72
         test.clear("a");
76
 
76
 
77
     @Test
77
     @Test
78
     public void testRemove() {
78
     public void testRemove() {
79
-        final MapList<String, String> test = new MapList<String, String>();
79
+        final MapList<String, String> test = new MapList<>();
80
         test.add("a", "b");
80
         test.add("a", "b");
81
         test.add("d", "e");
81
         test.add("d", "e");
82
         test.remove("z", "b");
82
         test.remove("z", "b");
93
 
93
 
94
     @Test
94
     @Test
95
     public void testRemoveKey() {
95
     public void testRemoveKey() {
96
-        final MapList<String, String> instance = new MapList<String, String>();
96
+        final MapList<String, String> instance = new MapList<>();
97
         instance.add("a", "b");
97
         instance.add("a", "b");
98
         assertTrue(instance.containsKey("a"));
98
         assertTrue(instance.containsKey("a"));
99
         instance.remove("a");
99
         instance.remove("a");
102
 
102
 
103
     @Test
103
     @Test
104
     public void testKeySet() {
104
     public void testKeySet() {
105
-        final MapList<String, String> test = new MapList<String, String>();
105
+        final MapList<String, String> test = new MapList<>();
106
         test.add("a", "b");
106
         test.add("a", "b");
107
         test.add("d", "e");
107
         test.add("d", "e");
108
         assertEquals(2, test.keySet().size());
108
         assertEquals(2, test.keySet().size());
112
 
112
 
113
     @Test
113
     @Test
114
     public void testContainsKey() {
114
     public void testContainsKey() {
115
-        final MapList<String, String> test = new MapList<String, String>();
115
+        final MapList<String, String> test = new MapList<>();
116
         test.add("a", "b");
116
         test.add("a", "b");
117
         assertTrue(test.containsKey("a"));
117
         assertTrue(test.containsKey("a"));
118
     }
118
     }
119
 
119
 
120
     @Test
120
     @Test
121
     public void testContainsValue() {
121
     public void testContainsValue() {
122
-        final MapList<String, String> test = new MapList<String, String>();
122
+        final MapList<String, String> test = new MapList<>();
123
         test.add("a", "b");
123
         test.add("a", "b");
124
         assertTrue(test.containsValue("a", "b"));
124
         assertTrue(test.containsValue("a", "b"));
125
     }
125
     }
126
 
126
 
127
     @Test
127
     @Test
128
     public void testGet() {
128
     public void testGet() {
129
-        final MapList<String, String> test = new MapList<String, String>();
129
+        final MapList<String, String> test = new MapList<>();
130
         test.add("a", "b");
130
         test.add("a", "b");
131
         assertEquals(1, test.get("a").size());
131
         assertEquals(1, test.get("a").size());
132
         assertEquals("b", test.get("a").get(0));
132
         assertEquals("b", test.get("a").get(0));
135
 
135
 
136
     @Test
136
     @Test
137
     public void testInherit() {
137
     public void testInherit() {
138
-        final MapList<String, String> test1 = new MapList<String, String>();
138
+        final MapList<String, String> test1 = new MapList<>();
139
         test1.add("a", "b");
139
         test1.add("a", "b");
140
 
140
 
141
-        final MapList<String, String> test2 = new MapList<String, String>(test1);
141
+        final MapList<String, String> test2 = new MapList<>(test1);
142
         assertEquals(1, test2.get("a").size());
142
         assertEquals(1, test2.get("a").size());
143
         assertEquals("b", test2.get("a").get(0));
143
         assertEquals("b", test2.get("a").get(0));
144
         assertEquals("b", test2.get("a", 0));
144
         assertEquals("b", test2.get("a", 0));
146
 
146
 
147
     @Test
147
     @Test
148
     public void testGetMap() {
148
     public void testGetMap() {
149
-        final MapList<String, String> test1 = new MapList<String, String>();
149
+        final MapList<String, String> test1 = new MapList<>();
150
         test1.add("a", "b");
150
         test1.add("a", "b");
151
         assertNotSame(test1.getMap(), test1.getMap());
151
         assertNotSame(test1.getMap(), test1.getMap());
152
 
152
 
153
-        final MapList<String, String> test2 = new MapList<String, String>(test1);
153
+        final MapList<String, String> test2 = new MapList<>(test1);
154
         assertEquals(test1.getMap(), test2.getMap());
154
         assertEquals(test1.getMap(), test2.getMap());
155
     }
155
     }
156
 
156
 

+ 2
- 2
test/com/dmdirc/util/collections/ObservableListDecoratorTest.java View File

41
 
41
 
42
     @Before
42
     @Before
43
     public void setup() {
43
     public void setup() {
44
-        list = new LinkedList<String>();
45
-        obslist = new ObservableListDecorator<String>(list);
44
+        list = new LinkedList<>();
45
+        obslist = new ObservableListDecorator<>(list);
46
         observer = mock(ListObserver.class);
46
         observer = mock(ListObserver.class);
47
         obslist.addListListener(observer);
47
         obslist.addListListener(observer);
48
     }
48
     }

+ 7
- 7
test/com/dmdirc/util/collections/RollingListTest.java View File

30
 
30
 
31
     @Test
31
     @Test
32
     public void testIsEmpty() {
32
     public void testIsEmpty() {
33
-        final RollingList<String> rl = new RollingList<String>(1);
33
+        final RollingList<String> rl = new RollingList<>(1);
34
         assertTrue(rl.isEmpty());
34
         assertTrue(rl.isEmpty());
35
         assertTrue(rl.getList().isEmpty());
35
         assertTrue(rl.getList().isEmpty());
36
         
36
         
41
     
41
     
42
     @Test
42
     @Test
43
     public void testRolling() {
43
     public void testRolling() {
44
-        final RollingList<String> rl = new RollingList<String>(1);
44
+        final RollingList<String> rl = new RollingList<>(1);
45
         
45
         
46
         rl.add("Foo");
46
         rl.add("Foo");
47
         rl.add("Bar");
47
         rl.add("Bar");
54
     
54
     
55
     @Test
55
     @Test
56
     public void testClear() {
56
     public void testClear() {
57
-        final RollingList<String> rl = new RollingList<String>(3);
57
+        final RollingList<String> rl = new RollingList<>(3);
58
         
58
         
59
         rl.add("Foo");
59
         rl.add("Foo");
60
         rl.add("Bar");
60
         rl.add("Bar");
67
     
67
     
68
     @Test
68
     @Test
69
     public void testPositions() {
69
     public void testPositions() {
70
-        final RollingList<String> rl = new RollingList<String>(3);
70
+        final RollingList<String> rl = new RollingList<>(3);
71
         
71
         
72
         rl.add("Foo");
72
         rl.add("Foo");
73
         rl.add("Bar");
73
         rl.add("Bar");
84
 
84
 
85
     @Test
85
     @Test
86
     public void testSetPosition() {
86
     public void testSetPosition() {
87
-        final RollingList<String> rl = new RollingList<String>(3);
87
+        final RollingList<String> rl = new RollingList<>(3);
88
 
88
 
89
         rl.add("Foo");
89
         rl.add("Foo");
90
         rl.add("Bar");
90
         rl.add("Bar");
103
     
103
     
104
     @Test
104
     @Test
105
     public void testPrevNext() {
105
     public void testPrevNext() {
106
-        final RollingList<String> rl = new RollingList<String>(3);
106
+        final RollingList<String> rl = new RollingList<>(3);
107
         
107
         
108
         rl.add("Foo");
108
         rl.add("Foo");
109
         rl.add("Bar");
109
         rl.add("Bar");
122
     
122
     
123
     @Test
123
     @Test
124
     public void testEmpty() {
124
     public void testEmpty() {
125
-        final RollingList<String> rl = new RollingList<String>(1, "Meep");
125
+        final RollingList<String> rl = new RollingList<>(1, "Meep");
126
         rl.add("Foo");
126
         rl.add("Foo");
127
         
127
         
128
         assertEquals("Meep", rl.getNext());
128
         assertEquals("Meep", rl.getNext());

+ 26
- 26
test/com/dmdirc/util/collections/WeakListTest.java View File

35
 
35
 
36
     @Test
36
     @Test
37
     public void testIsEmpty() {
37
     public void testIsEmpty() {
38
-        final WeakList<String> instance = new WeakList<String>();
38
+        final WeakList<String> instance = new WeakList<>();
39
         assertTrue(instance.isEmpty());
39
         assertTrue(instance.isEmpty());
40
         instance.add("test1");
40
         instance.add("test1");
41
         assertFalse(instance.isEmpty());
41
         assertFalse(instance.isEmpty());
43
 
43
 
44
     @Test
44
     @Test
45
     public void testAdd() {
45
     public void testAdd() {
46
-        final WeakList<String> instance = new WeakList<String>();
46
+        final WeakList<String> instance = new WeakList<>();
47
         assertTrue(instance.add("test1"));
47
         assertTrue(instance.add("test1"));
48
         assertFalse(instance.isEmpty());
48
         assertFalse(instance.isEmpty());
49
     }
49
     }
50
 
50
 
51
     @Test
51
     @Test
52
     public void testAdd_Int() {
52
     public void testAdd_Int() {
53
-        final WeakList<String> instance = new WeakList<String>();
53
+        final WeakList<String> instance = new WeakList<>();
54
         assertTrue(instance.add("test1"));
54
         assertTrue(instance.add("test1"));
55
         instance.add(0, "test2");
55
         instance.add(0, "test2");
56
         assertEquals("test2", instance.get(0));
56
         assertEquals("test2", instance.get(0));
58
 
58
 
59
     @Test
59
     @Test
60
     public void testRemove() {
60
     public void testRemove() {
61
-        final WeakList<String> instance = new WeakList<String>();
61
+        final WeakList<String> instance = new WeakList<>();
62
         instance.add("test1");
62
         instance.add("test1");
63
         assertFalse(instance.isEmpty());
63
         assertFalse(instance.isEmpty());
64
         assertTrue(instance.remove("test1"));
64
         assertTrue(instance.remove("test1"));
67
 
67
 
68
     @Test
68
     @Test
69
     public void testRemove_Int() {
69
     public void testRemove_Int() {
70
-        final WeakList<String> instance = new WeakList<String>();
70
+        final WeakList<String> instance = new WeakList<>();
71
         assertTrue(instance.isEmpty());
71
         assertTrue(instance.isEmpty());
72
         instance.add("test1");
72
         instance.add("test1");
73
         instance.add("test2");
73
         instance.add("test2");
79
 
79
 
80
     @Test
80
     @Test
81
     public void testGet() {
81
     public void testGet() {
82
-        final WeakList<String> instance = new WeakList<String>();
82
+        final WeakList<String> instance = new WeakList<>();
83
         instance.add("test1");
83
         instance.add("test1");
84
         instance.add("test2");
84
         instance.add("test2");
85
         assertEquals("test1", instance.get(0));
85
         assertEquals("test1", instance.get(0));
88
 
88
 
89
     @Test
89
     @Test
90
     public void testContains() {
90
     public void testContains() {
91
-        final WeakList<String> instance = new WeakList<String>();
91
+        final WeakList<String> instance = new WeakList<>();
92
         assertFalse(instance.contains("test1"));
92
         assertFalse(instance.contains("test1"));
93
         instance.add("test1");
93
         instance.add("test1");
94
         assertTrue(instance.contains("test1"));
94
         assertTrue(instance.contains("test1"));
99
      */
99
      */
100
     @Test
100
     @Test
101
     public void testToArray_0args() {
101
     public void testToArray_0args() {
102
-        final WeakList<String> instance = new WeakList<String>();
102
+        final WeakList<String> instance = new WeakList<>();
103
         assertEquals(0, instance.toArray().length);
103
         assertEquals(0, instance.toArray().length);
104
         instance.add("test1");
104
         instance.add("test1");
105
         instance.add("test2");
105
         instance.add("test2");
114
      */
114
      */
115
     @Test
115
     @Test
116
     public void testToArray_GenericType() {
116
     public void testToArray_GenericType() {
117
-        final WeakList<String> instance = new WeakList<String>();
117
+        final WeakList<String> instance = new WeakList<>();
118
         assertEquals(0, instance.toArray(new String[0]).length);
118
         assertEquals(0, instance.toArray(new String[0]).length);
119
         instance.add("test1");
119
         instance.add("test1");
120
         instance.add("test2");
120
         instance.add("test2");
129
      */
129
      */
130
     @Test
130
     @Test
131
     public void testContainsAllAddAll() {
131
     public void testContainsAllAddAll() {
132
-        final List<String> list = new ArrayList<String>();
132
+        final List<String> list = new ArrayList<>();
133
         list.add("test1");
133
         list.add("test1");
134
         list.add("test2");
134
         list.add("test2");
135
-        final WeakList<String> instance = new WeakList<String>();
135
+        final WeakList<String> instance = new WeakList<>();
136
         assertFalse(instance.containsAll(list));
136
         assertFalse(instance.containsAll(list));
137
         instance.addAll(list);
137
         instance.addAll(list);
138
         assertTrue(instance.contains("test1"));
138
         assertTrue(instance.contains("test1"));
142
 
142
 
143
     @Test
143
     @Test
144
     public void testAddAll_int_Collection() {
144
     public void testAddAll_int_Collection() {
145
-        final List<String> list = new ArrayList<String>();
145
+        final List<String> list = new ArrayList<>();
146
         list.add("test1");
146
         list.add("test1");
147
         list.add("test2");
147
         list.add("test2");
148
-        final WeakList<String> instance = new WeakList<String>();
148
+        final WeakList<String> instance = new WeakList<>();
149
         instance.add("test3");
149
         instance.add("test3");
150
         System.out.println(instance);
150
         System.out.println(instance);
151
         assertEquals("test3", instance.get(0));
151
         assertEquals("test3", instance.get(0));
159
     public void testIndexOf() {
159
     public void testIndexOf() {
160
         final String one = "test1";
160
         final String one = "test1";
161
         final String two = "test2";
161
         final String two = "test2";
162
-        final WeakList<String> instance = new WeakList<String>();
162
+        final WeakList<String> instance = new WeakList<>();
163
         instance.add(one);
163
         instance.add(one);
164
         instance.add(two);
164
         instance.add(two);
165
         assertEquals(2, instance.size());
165
         assertEquals(2, instance.size());
171
     public void testLastIndexOf() {
171
     public void testLastIndexOf() {
172
         final String one = "test1";
172
         final String one = "test1";
173
         final String two = "test2";
173
         final String two = "test2";
174
-        final WeakList<String> instance = new WeakList<String>();
174
+        final WeakList<String> instance = new WeakList<>();
175
         instance.add(one);
175
         instance.add(one);
176
         instance.add(two);
176
         instance.add(two);
177
         instance.add(one);
177
         instance.add(one);
181
 
181
 
182
     @Test
182
     @Test
183
     public void testRemoveAll() {
183
     public void testRemoveAll() {
184
-        final List<String> list = new ArrayList<String>();
184
+        final List<String> list = new ArrayList<>();
185
         list.add("test1");
185
         list.add("test1");
186
         list.add("test2");
186
         list.add("test2");
187
-        final WeakList<String> instance = new WeakList<String>();
187
+        final WeakList<String> instance = new WeakList<>();
188
         instance.addAll(list);
188
         instance.addAll(list);
189
         assertFalse(instance.isEmpty());
189
         assertFalse(instance.isEmpty());
190
         instance.removeAll(list);
190
         instance.removeAll(list);
193
 
193
 
194
     @Test
194
     @Test
195
     public void testRetainAll() {
195
     public void testRetainAll() {
196
-        final List<String> list = new ArrayList<String>();
196
+        final List<String> list = new ArrayList<>();
197
         list.add("test1");
197
         list.add("test1");
198
         list.add("test2");
198
         list.add("test2");
199
-        final WeakList<String> instance = new WeakList<String>();
199
+        final WeakList<String> instance = new WeakList<>();
200
         instance.addAll(list);
200
         instance.addAll(list);
201
         instance.add("test3");
201
         instance.add("test3");
202
         instance.add("test4");
202
         instance.add("test4");
207
 
207
 
208
     @Test
208
     @Test
209
     public void testClear() {
209
     public void testClear() {
210
-        final List<String> list = new ArrayList<String>();
210
+        final List<String> list = new ArrayList<>();
211
         list.add("test1");
211
         list.add("test1");
212
         list.add("test2");
212
         list.add("test2");
213
-        final WeakList<String> instance = new WeakList<String>();
213
+        final WeakList<String> instance = new WeakList<>();
214
         instance.addAll(list);
214
         instance.addAll(list);
215
         assertFalse(instance.isEmpty());
215
         assertFalse(instance.isEmpty());
216
         instance.clear();
216
         instance.clear();
219
 
219
 
220
     @Test
220
     @Test
221
     public void testSet() {
221
     public void testSet() {
222
-        final WeakList<String> instance = new WeakList<String>();
222
+        final WeakList<String> instance = new WeakList<>();
223
         instance.add("test1");
223
         instance.add("test1");
224
         assertEquals("test1", instance.get(0));
224
         assertEquals("test1", instance.get(0));
225
         instance.set(0, "test2");
225
         instance.set(0, "test2");
228
 
228
 
229
     @Test
229
     @Test
230
     public void testIterator() {
230
     public void testIterator() {
231
-        final WeakList<String> instance = new WeakList<String>();
231
+        final WeakList<String> instance = new WeakList<>();
232
         Iterator result = instance.iterator();
232
         Iterator result = instance.iterator();
233
         assertFalse(result.hasNext());
233
         assertFalse(result.hasNext());
234
         instance.add("test1");
234
         instance.add("test1");
241
 
241
 
242
     @Test
242
     @Test
243
     public void testListIterator_0args() {
243
     public void testListIterator_0args() {
244
-        final WeakList<String> instance = new WeakList<String>();
244
+        final WeakList<String> instance = new WeakList<>();
245
         ListIterator result = instance.listIterator();
245
         ListIterator result = instance.listIterator();
246
         assertFalse(result.hasNext());
246
         assertFalse(result.hasNext());
247
         instance.add("test1");
247
         instance.add("test1");
254
 
254
 
255
     @Test(expected=IndexOutOfBoundsException.class)
255
     @Test(expected=IndexOutOfBoundsException.class)
256
     public void testListIterator_int() {
256
     public void testListIterator_int() {
257
-        final WeakList<String> instance = new WeakList<String>();
257
+        final WeakList<String> instance = new WeakList<>();
258
         ListIterator result = instance.listIterator(1);
258
         ListIterator result = instance.listIterator(1);
259
         assertFalse(result.hasNext());
259
         assertFalse(result.hasNext());
260
         instance.add("test1");
260
         instance.add("test1");
269
 
269
 
270
     @Test
270
     @Test
271
     public void testSubList() {
271
     public void testSubList() {
272
-        final WeakList<String> instance = new WeakList<String>();
272
+        final WeakList<String> instance = new WeakList<>();
273
         instance.add("test1");
273
         instance.add("test1");
274
         instance.add("test2");
274
         instance.add("test2");
275
         instance.add("test3");
275
         instance.add("test3");

+ 5
- 5
test/com/dmdirc/util/io/ConfigFileTest.java View File

100
     public void testColons() throws IOException, InvalidConfigFileException {
100
     public void testColons() throws IOException, InvalidConfigFileException {
101
         final File file = File.createTempFile("DMDirc.unittest", null);
101
         final File file = File.createTempFile("DMDirc.unittest", null);
102
         ConfigFile config = new ConfigFile(file);
102
         ConfigFile config = new ConfigFile(file);
103
-        Map<String, String> data = new HashMap<String, String>();
103
+        Map<String, String> data = new HashMap<>();
104
         data.put("test1", "hello");
104
         data.put("test1", "hello");
105
         data.put("test:2", "hello");
105
         data.put("test:2", "hello");
106
         data.put("test3", "hello:");
106
         data.put("test3", "hello:");
121
     public void testEquals() throws IOException, InvalidConfigFileException {
121
     public void testEquals() throws IOException, InvalidConfigFileException {
122
         final File file = File.createTempFile("DMDirc.unittest", null);
122
         final File file = File.createTempFile("DMDirc.unittest", null);
123
         ConfigFile config = new ConfigFile(file);
123
         ConfigFile config = new ConfigFile(file);
124
-        Map<String, String> data = new HashMap<String, String>();
124
+        Map<String, String> data = new HashMap<>();
125
         data.put("test1", "hello");
125
         data.put("test1", "hello");
126
         data.put("test=2", "hello");
126
         data.put("test=2", "hello");
127
         data.put("test3", "hello=");
127
         data.put("test3", "hello=");
142
     public void testNewlines() throws IOException, InvalidConfigFileException {
142
     public void testNewlines() throws IOException, InvalidConfigFileException {
143
         final File file = File.createTempFile("DMDirc.unittest", null);
143
         final File file = File.createTempFile("DMDirc.unittest", null);
144
         ConfigFile config = new ConfigFile(file);
144
         ConfigFile config = new ConfigFile(file);
145
-        Map<String, String> data = new HashMap<String, String>();
145
+        Map<String, String> data = new HashMap<>();
146
         data.put("test1", "hello");
146
         data.put("test1", "hello");
147
         data.put("test2", "hello\ngoodbye");
147
         data.put("test2", "hello\ngoodbye");
148
         data.put("test3", "hello\n");
148
         data.put("test3", "hello\n");
165
     public void testBackslash() throws IOException, InvalidConfigFileException {
165
     public void testBackslash() throws IOException, InvalidConfigFileException {
166
         final File file = File.createTempFile("DMDirc.unittest", null);
166
         final File file = File.createTempFile("DMDirc.unittest", null);
167
         ConfigFile config = new ConfigFile(file);
167
         ConfigFile config = new ConfigFile(file);
168
-        Map<String, String> data = new HashMap<String, String>();
168
+        Map<String, String> data = new HashMap<>();
169
         data.put("test1", "hello\\");
169
         data.put("test1", "hello\\");
170
         data.put("test2", "\\nhello");
170
         data.put("test2", "\\nhello");
171
         data.put("test3\\", "hello");
171
         data.put("test3\\", "hello");
186
     public void testHash() throws IOException, InvalidConfigFileException {
186
     public void testHash() throws IOException, InvalidConfigFileException {
187
         final File file = File.createTempFile("DMDirc.unittest", null);
187
         final File file = File.createTempFile("DMDirc.unittest", null);
188
         ConfigFile config = new ConfigFile(file);
188
         ConfigFile config = new ConfigFile(file);
189
-        Map<String, String> data = new HashMap<String, String>();
189
+        Map<String, String> data = new HashMap<>();
190
         data.put("test1#", "hello");
190
         data.put("test1#", "hello");
191
         data.put("#test2", "hello");
191
         data.put("#test2", "hello");
192
         data.put("test3", "#hello");
192
         data.put("test3", "#hello");

+ 1
- 1
test/com/dmdirc/util/validators/OptionalValidatorTest.java View File

29
 
29
 
30
     @Test
30
     @Test
31
     public void testGetValidator() {
31
     public void testGetValidator() {
32
-        final Validator<String> validator = new PermissiveValidator<String>();
32
+        final Validator<String> validator = new PermissiveValidator<>();
33
         final OptionalValidator instance = new OptionalValidator(validator);
33
         final OptionalValidator instance = new OptionalValidator(validator);
34
         assertEquals(validator, instance.getValidator());
34
         assertEquals(validator, instance.getValidator());
35
     }
35
     }

+ 1
- 1
test/com/dmdirc/util/validators/ValidatorChainTest.java View File

33
     @Test
33
     @Test
34
     public void testValidate() {
34
     public void testValidate() {
35
         @SuppressWarnings("unchecked")
35
         @SuppressWarnings("unchecked")
36
-        final ValidatorChain<String> chain = new ValidatorChain<String>(
36
+        final ValidatorChain<String> chain = new ValidatorChain<>(
37
                 new NotEmptyValidator(), new RegexStringValidator("[a-z]*", "abc"));
37
                 new NotEmptyValidator(), new RegexStringValidator("[a-z]*", "abc"));
38
         
38
         
39
         assertTrue(chain.validate("").isFailure());
39
         assertTrue(chain.validate("").isFailure());

Loading…
Cancel
Save