Skip to content

Commit dabe4d2

Browse files
committed
Fix sonar issues
1 parent aff7ef8 commit dabe4d2

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ public static void main(final String[] args) {
8585
// installed and socket connection is open).
8686
App app = new App(isDbMongo(args));
8787
app.useReadAndWriteThroughStrategy();
88-
System.out.println("==============================================");
88+
String splitLine = "==============================================";
89+
LOGGER.info(splitLine);
8990
app.useReadThroughAndWriteAroundStrategy();
90-
System.out.println("==============================================");
91+
LOGGER.info(splitLine);
9192
app.useReadThroughAndWriteBehindStrategy();
92-
System.out.println("==============================================");
93+
LOGGER.info(splitLine);
9394
app.useCacheAsideStategy();
94-
System.out.println("==============================================");
95+
LOGGER.info(splitLine);
9596
}
9697

9798
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Optional;
2727

2828
import com.iluwatar.caching.database.DbManager;
29+
import lombok.Data;
2930
import lombok.extern.slf4j.Slf4j;
3031

3132
/**
@@ -37,11 +38,12 @@
3738
* appropriate function in the CacheStore class.
3839
*/
3940
@Slf4j
41+
@Data
4042
public class AppManager {
4143
/**
4244
* Caching Policy.
4345
*/
44-
private static CachingPolicy cachingPolicy;
46+
private CachingPolicy cachingPolicy;
4547
/**
4648
* Database Manager.
4749
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public class CacheStore {
4343
/**
4444
* Lru cache see {@link LruCache}.
4545
*/
46-
private static LruCache cache;
46+
private LruCache cache;
4747
/**
4848
* DbManager.
4949
*/
50-
private DbManager dbManager;
50+
private final DbManager dbManager;
5151

5252
/**
5353
* Cache Store.

caching/src/main/java/com/iluwatar/caching/database/MongoDb.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public UserAccount readFromDb(final String userId) {
4545
var iterable = db
4646
.getCollection(CachingConstants.USER_ACCOUNT)
4747
.find(new Document(USER_ID, userId));
48-
if (iterable == null) {
48+
if (iterable.first()==null) {
4949
return null;
5050
}
5151
Document doc = iterable.first();

caching/src/main/java/com/iluwatar/caching/database/VirtualDb.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public class VirtualDb implements DbManager {
1313
/**
1414
* Virtual DataBase.
1515
*/
16-
private Map<String, UserAccount> virtualDB;
16+
private Map<String, UserAccount> db;
1717

1818
/**
1919
* Creates new HashMap.
2020
*/
2121
@Override
2222
public void connect() {
23-
virtualDB = new HashMap<>();
23+
db = new HashMap<>();
2424
}
2525

2626
/**
@@ -30,8 +30,8 @@ public void connect() {
3030
*/
3131
@Override
3232
public UserAccount readFromDb(final String userId) {
33-
if (virtualDB.containsKey(userId)) {
34-
return virtualDB.get(userId);
33+
if (db.containsKey(userId)) {
34+
return db.get(userId);
3535
}
3636
return null;
3737
}
@@ -43,7 +43,7 @@ public UserAccount readFromDb(final String userId) {
4343
*/
4444
@Override
4545
public UserAccount writeToDb(final UserAccount userAccount) {
46-
virtualDB.put(userAccount.getUserId(), userAccount);
46+
db.put(userAccount.getUserId(), userAccount);
4747
return userAccount;
4848
}
4949

@@ -54,8 +54,7 @@ public UserAccount writeToDb(final UserAccount userAccount) {
5454
*/
5555
@Override
5656
public UserAccount updateDb(final UserAccount userAccount) {
57-
virtualDB.put(userAccount.getUserId(), userAccount);
58-
return userAccount;
57+
return writeToDb(userAccount);
5958
}
6059

6160
/**

0 commit comments

Comments
 (0)