Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d6fc28e

Browse filesBrowse files
committed
Changing code to use interfaces instead of implementations.
1 parent 6292690 commit d6fc28e
Copy full SHA for d6fc28e

24 files changed

+346-13Lines changed: 346 additions & 13 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: caching/src/main/java/com/iluwatar/caching/LruCache.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void clear() {
167167
* Returns cache data in list form.
168168
*/
169169
public List<UserAccount> getCacheDataInListForm() {
170-
ArrayList<UserAccount> listOfCacheData = new ArrayList<>();
170+
List<UserAccount> listOfCacheData = new ArrayList<>();
171171
Node temp = head;
172172
while (temp != null) {
173173
listOfCacheData.add(temp.userAccount);
Collapse file

‎factory-kit/src/main/java/com/iluwatar/factorykit/WeaponFactory.java‎

Copy file name to clipboardExpand all lines: factory-kit/src/main/java/com/iluwatar/factorykit/WeaponFactory.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.iluwatar.factorykit;
2424

2525
import java.util.HashMap;
26+
import java.util.Map;
2627
import java.util.function.Consumer;
2728
import java.util.function.Supplier;
2829

@@ -48,7 +49,7 @@ public interface WeaponFactory {
4849
* @return factory with specified {@link Builder}s
4950
*/
5051
static WeaponFactory factory(Consumer<Builder> consumer) {
51-
HashMap<WeaponType, Supplier<Weapon>> map = new HashMap<>();
52+
Map<WeaponType, Supplier<Weapon>> map = new HashMap<>();
5253
consumer.accept(map::put);
5354
return name -> map.get(name).get();
5455
}
Collapse file

‎hexagonal/src/main/java/com/iluwatar/hexagonal/banking/MongoBank.java‎

Copy file name to clipboardExpand all lines: hexagonal/src/main/java/com/iluwatar/hexagonal/banking/MongoBank.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.bson.Document;
3030

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

3334
/**
3435
* Mongo based banking adapter
@@ -110,7 +111,7 @@ public void setFunds(String bankAccount, int amount) {
110111
@Override
111112
public int getFunds(String bankAccount) {
112113
Document search = new Document("_id", bankAccount);
113-
ArrayList<Document> results = accountsCollection.find(search).limit(1).into(new ArrayList<Document>());
114+
List<Document> results = accountsCollection.find(search).limit(1).into(new ArrayList<Document>());
114115
if (results.size() > 0) {
115116
return results.get(0).getInteger("funds");
116117
} else {
Collapse file

‎hexagonal/src/main/java/com/iluwatar/hexagonal/database/MongoTicketRepository.java‎

Copy file name to clipboardExpand all lines: hexagonal/src/main/java/com/iluwatar/hexagonal/database/MongoTicketRepository.java
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
import java.util.Arrays;
3636
import java.util.HashMap;
3737
import java.util.HashSet;
38+
import java.util.List;
3839
import java.util.Map;
3940
import java.util.Optional;
41+
import java.util.Set;
4042

4143
/**
4244
* Mongo lottery ticket database
@@ -142,7 +144,7 @@ public MongoCollection<Document> getCountersCollection() {
142144
@Override
143145
public Optional<LotteryTicket> findById(LotteryTicketId id) {
144146
Document find = new Document("ticketId", id.getId());
145-
ArrayList<Document> results = ticketsCollection.find(find).limit(1).into(new ArrayList<Document>());
147+
List<Document> results = ticketsCollection.find(find).limit(1).into(new ArrayList<Document>());
146148
if (results.size() > 0) {
147149
LotteryTicket lotteryTicket = docToTicket(results.get(0));
148150
return Optional.of(lotteryTicket);
@@ -166,7 +168,7 @@ public Optional<LotteryTicketId> save(LotteryTicket ticket) {
166168
@Override
167169
public Map<LotteryTicketId, LotteryTicket> findAll() {
168170
Map<LotteryTicketId, LotteryTicket> map = new HashMap<>();
169-
ArrayList<Document> docs = ticketsCollection.find(new Document()).into(new ArrayList<Document>());
171+
List<Document> docs = ticketsCollection.find(new Document()).into(new ArrayList<Document>());
170172
for (Document doc: docs) {
171173
LotteryTicket lotteryTicket = docToTicket(doc);
172174
map.put(lotteryTicket.getId(), lotteryTicket);
@@ -183,7 +185,7 @@ private LotteryTicket docToTicket(Document doc) {
183185
PlayerDetails playerDetails = new PlayerDetails(doc.getString("email"), doc.getString("bank"),
184186
doc.getString("phone"));
185187
int[] numArray = Arrays.asList(doc.getString("numbers").split(",")).stream().mapToInt(Integer::parseInt).toArray();
186-
HashSet<Integer> numbers = new HashSet<>();
188+
Set<Integer> numbers = new HashSet<>();
187189
for (int num: numArray) {
188190
numbers.add(num);
189191
}
Collapse file

‎layers/src/main/java/com/iluwatar/layers/CakeBakingServiceImpl.java‎

Copy file name to clipboardExpand all lines: layers/src/main/java/com/iluwatar/layers/CakeBakingServiceImpl.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public List<CakeInfo> getAllCakes() {
163163
CakeToppingInfo cakeToppingInfo =
164164
new CakeToppingInfo(cake.getTopping().getId(), cake.getTopping().getName(), cake
165165
.getTopping().getCalories());
166-
ArrayList<CakeLayerInfo> cakeLayerInfos = new ArrayList<>();
166+
List<CakeLayerInfo> cakeLayerInfos = new ArrayList<>();
167167
for (CakeLayer layer : cake.getLayers()) {
168168
cakeLayerInfos.add(new CakeLayerInfo(layer.getId(), layer.getName(), layer.getCalories()));
169169
}
Collapse file

‎memory-dao-test/.springBeans‎

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beansProjectDescription>
3+
<version>1</version>
4+
<pluginVersion><![CDATA[3.8.2.201610040608-RELEASE]]></pluginVersion>
5+
<configSuffixes>
6+
<configSuffix><![CDATA[xml]]></configSuffix>
7+
</configSuffixes>
8+
<enableImports><![CDATA[false]]></enableImports>
9+
<configs>
10+
<config>src/main/resources/beans.xml</config>
11+
</configs>
12+
<autoconfigs>
13+
</autoconfigs>
14+
<configSets>
15+
</configSets>
16+
</beansProjectDescription>
Collapse file

‎memory-dao-test/pom.xml‎

Copy file name to clipboard
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.memory.dao</groupId>
5+
<artifactId>memory-dao-test</artifactId>
6+
<version>0.0.1</version>
7+
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>1.7</maven.compiler.source>
11+
<maven.compiler.target>1.7</maven.compiler.target>
12+
</properties>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>junit</groupId>
17+
<artifactId>junit</artifactId>
18+
<version>4.12</version>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.apache.commons</groupId>
23+
<artifactId>commons-lang3</artifactId>
24+
<version>3.0</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>mysql</groupId>
29+
<artifactId>mysql-connector-java</artifactId>
30+
<version>5.1.25</version>
31+
</dependency>
32+
33+
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
34+
<dependency>
35+
<groupId>com.h2database</groupId>
36+
<artifactId>h2</artifactId>
37+
<version>1.4.193</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.springframework</groupId>
42+
<artifactId>spring-core</artifactId>
43+
<version>4.2.5.RELEASE</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework</groupId>
47+
<artifactId>spring-beans</artifactId>
48+
<version>4.2.5.RELEASE</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework</groupId>
52+
<artifactId>spring-context</artifactId>
53+
<version>4.2.5.RELEASE</version>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>org.springframework</groupId>
58+
<artifactId>spring-jdbc</artifactId>
59+
<version>4.2.5.RELEASE</version>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.springframework</groupId>
64+
<artifactId>spring-test</artifactId>
65+
<version>4.2.5.RELEASE</version>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
</dependencies>
70+
71+
</project>
Collapse file
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.memory.dao;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5+
6+
import com.memory.dao.db.UserDAO;
7+
import com.memory.dao.pojo.User;
8+
9+
public class App {
10+
public static void main(String[] args) {
11+
12+
final ApplicationContext context = new ClassPathXmlApplicationContext(
13+
"file:src/main/resources/beans.xml");
14+
15+
final UserDAO dao = (UserDAO)context.getBean("userDao");
16+
for (final User user : dao.findAll()) {
17+
System.out.println(user);
18+
}
19+
20+
((ClassPathXmlApplicationContext)context).close();
21+
}
22+
}
Collapse file
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.memory.dao;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
@ComponentScan(basePackages = {"com.memory.dao"})
8+
public class AppConfig {
9+
}
Collapse file
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.memory.dao.db;
2+
3+
public enum Queries {
4+
5+
GET_USER("SELECT * FROM users WHERE name = :name"),
6+
GET_ALL_USERS("SELECT * FROM users")
7+
;
8+
9+
private final String query;
10+
11+
Queries(final String query) {
12+
this.query = query;
13+
}
14+
15+
public String get() {
16+
return this.query;
17+
}
18+
19+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.