Skip to content

Commit f135ef6

Browse files
committed
Merge pull request iluwatar#389 from DevFactory/release/Declarations-should-use-Java-collection-interfaces-such-as-List-rather-than-specific-implementation-classes-such-as-LinkedList-fix-1
squid:S1319 - Declarations should use Java collection interfaces such…
2 parents ab19c47 + e4c34b1 commit f135ef6

File tree

11 files changed

+23
-15
lines changed

11 files changed

+23
-15
lines changed

caching/src/main/java/com/iluwatar/caching/CacheStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
package com.iluwatar.caching;
2424

25-
import java.util.ArrayList;
25+
import java.util.List;
2626

2727
/**
2828
*
@@ -134,7 +134,7 @@ public static void flushCache() {
134134
if (null == cache) {
135135
return;
136136
}
137-
ArrayList<UserAccount> listOfUserAccounts = cache.getCacheDataInListForm();
137+
List<UserAccount> listOfUserAccounts = cache.getCacheDataInListForm();
138138
for (UserAccount userAccount : listOfUserAccounts) {
139139
DbManager.upsertDb(userAccount);
140140
}
@@ -144,7 +144,7 @@ public static void flushCache() {
144144
* Print user accounts
145145
*/
146146
public static String print() {
147-
ArrayList<UserAccount> listOfUserAccounts = cache.getCacheDataInListForm();
147+
List<UserAccount> listOfUserAccounts = cache.getCacheDataInListForm();
148148
StringBuilder sb = new StringBuilder();
149149
sb.append("\n--CACHE CONTENT--\n");
150150
for (UserAccount userAccount : listOfUserAccounts) {

caching/src/main/java/com/iluwatar/caching/DbManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.text.ParseException;
2626
import java.util.HashMap;
27+
import java.util.Map;
2728

2829
import org.bson.Document;
2930

@@ -49,7 +50,7 @@ public final class DbManager {
4950
private static MongoDatabase db;
5051
private static boolean useMongoDB;
5152

52-
private static HashMap<String, UserAccount> virtualDB;
53+
private static Map<String, UserAccount> virtualDB;
5354

5455
private DbManager() {
5556
}

caching/src/main/java/com/iluwatar/caching/LruCache.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import java.util.ArrayList;
2626
import java.util.HashMap;
27+
import java.util.List;
28+
import java.util.Map;
2729

2830
/**
2931
*
@@ -49,7 +51,7 @@ public Node(String userId, UserAccount userAccount) {
4951
}
5052

5153
int capacity;
52-
HashMap<String, Node> cache = new HashMap<>();
54+
Map<String, Node> cache = new HashMap<>();
5355
Node head;
5456
Node end;
5557

@@ -161,7 +163,7 @@ public void clear() {
161163
*
162164
* Returns cache data in list form.
163165
*/
164-
public ArrayList<UserAccount> getCacheDataInListForm() {
166+
public List<UserAccount> getCacheDataInListForm() {
165167
ArrayList<UserAccount> listOfCacheData = new ArrayList<>();
166168
Node temp = head;
167169
while (temp != null) {

fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public interface FluentIterable<E> extends Iterable<E> {
101101
* @return a list with all objects of the given iterator
102102
*/
103103
static <E> List<E> copyToList(Iterable<E> iterable) {
104-
ArrayList<E> copy = new ArrayList<>();
104+
List<E> copy = new ArrayList<>();
105105
Iterator<E> iterator = iterable.iterator();
106106
while (iterator.hasNext()) {
107107
copy.add(iterator.next());

iterator/src/main/java/com/iluwatar/iterator/TreasureChest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ItemIterator iterator(ItemType itemType) {
5959
* Get all items
6060
*/
6161
public List<Item> getItems() {
62-
ArrayList<Item> list = new ArrayList<>();
62+
List<Item> list = new ArrayList<>();
6363
list.addAll(items);
6464
return list;
6565
}

observer/src/test/java/com/iluwatar/observer/HobbitsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.ArrayList;
2929
import java.util.Collection;
30+
import java.util.List;
3031

3132
/**
3233
* Date: 12/27/15 - 12:07 PM
@@ -38,7 +39,7 @@ public class HobbitsTest extends WeatherObserverTest<Hobbits> {
3839

3940
@Parameterized.Parameters
4041
public static Collection<Object[]> data() {
41-
final ArrayList<Object[]> testData = new ArrayList<>();
42+
final List<Object[]> testData = new ArrayList<>();
4243
testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."});
4344
testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."});
4445
testData.add(new Object[]{WeatherType.WINDY, "The hobbits hold their hats tightly in the windy weather."});

observer/src/test/java/com/iluwatar/observer/OrcsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.ArrayList;
2929
import java.util.Collection;
30+
import java.util.List;
3031

3132
/**
3233
* Date: 12/27/15 - 12:07 PM
@@ -38,7 +39,7 @@ public class OrcsTest extends WeatherObserverTest<Orcs> {
3839

3940
@Parameterized.Parameters
4041
public static Collection<Object[]> data() {
41-
final ArrayList<Object[]> testData = new ArrayList<>();
42+
final List<Object[]> testData = new ArrayList<>();
4243
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
4344
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
4445
testData.add(new Object[]{WeatherType.WINDY, "The orc smell almost vanishes in the wind."});

observer/src/test/java/com/iluwatar/observer/generic/GHobbitsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.util.ArrayList;
3333
import java.util.Collection;
34+
import java.util.List;
3435

3536
/**
3637
* Date: 12/27/15 - 12:07 PM
@@ -42,7 +43,7 @@ public class GHobbitsTest extends ObserverTest<GHobbits> {
4243

4344
@Parameterized.Parameters
4445
public static Collection<Object[]> data() {
45-
final ArrayList<Object[]> testData = new ArrayList<>();
46+
final List<Object[]> testData = new ArrayList<>();
4647
testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."});
4748
testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."});
4849
testData.add(new Object[]{WeatherType.WINDY, "The hobbits hold their hats tightly in the windy weather."});

observer/src/test/java/com/iluwatar/observer/generic/OrcsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.ArrayList;
3131
import java.util.Collection;
32+
import java.util.List;
3233

3334
/**
3435
* Date: 12/27/15 - 12:07 PM
@@ -40,7 +41,7 @@ public class OrcsTest extends ObserverTest<GOrcs> {
4041

4142
@Parameterized.Parameters
4243
public static Collection<Object[]> data() {
43-
final ArrayList<Object[]> testData = new ArrayList<>();
44+
final List<Object[]> testData = new ArrayList<>();
4445
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
4546
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
4647
testData.add(new Object[]{WeatherType.WINDY, "The orc smell almost vanishes in the wind."});

producer-consumer/src/main/java/com/iluwatar/producer/consumer/ItemQueue.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
*/
2323
package com.iluwatar.producer.consumer;
2424

25+
import java.util.concurrent.BlockingQueue;
2526
import java.util.concurrent.LinkedBlockingQueue;
2627

2728
/**
2829
* Class as a channel for {@link Producer}-{@link Consumer} exchange.
2930
*/
3031
public class ItemQueue {
3132

32-
private LinkedBlockingQueue<Item> queue;
33+
private BlockingQueue<Item> queue;
3334

3435
public ItemQueue() {
3536

0 commit comments

Comments
 (0)