Skip to content

Commit c150e5f

Browse files
committed
Fix CacheStore errors from checkstyle plugin 107 left
1 parent 3c213fc commit c150e5f

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

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

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,34 @@
3535
*/
3636
@Slf4j
3737
public class CacheStore {
38+
/**
39+
* Cach capacity.
40+
*/
3841
private static final int CAPACITY = 3;
3942

43+
/**
44+
* Lru cache see {@link LruCache}.
45+
*/
4046
private static LruCache cache;
47+
/**
48+
* DbManager.
49+
*/
4150
private DbManager dbManager;
4251

43-
public CacheStore(DbManager dbManager) {
44-
this.dbManager = dbManager;
52+
/**
53+
* Cache Store.
54+
* @param dataBaseManager {@link DbManager}
55+
*/
56+
public CacheStore(final DbManager dataBaseManager) {
57+
this.dbManager = dataBaseManager;
4558
initCapacity(CAPACITY);
4659
}
4760

4861
/**
4962
* Init cache capacity.
63+
* @param capacity int
5064
*/
51-
public void initCapacity(int capacity) {
65+
public void initCapacity(final int capacity) {
5266
if (cache == null) {
5367
cache = new LruCache(capacity);
5468
} else {
@@ -58,8 +72,10 @@ public void initCapacity(int capacity) {
5872

5973
/**
6074
* Get user account using read-through cache.
75+
* @param userId {@link String}
76+
* @return {@link UserAccount}
6177
*/
62-
public UserAccount readThrough(String userId) {
78+
public UserAccount readThrough(final String userId) {
6379
if (cache.contains(userId)) {
6480
LOGGER.info("# Found in Cache!");
6581
return cache.get(userId);
@@ -72,8 +88,9 @@ public UserAccount readThrough(String userId) {
7288

7389
/**
7490
* Get user account using write-through cache.
91+
* @param userAccount {@link UserAccount}
7592
*/
76-
public void writeThrough(UserAccount userAccount) {
93+
public void writeThrough(final UserAccount userAccount) {
7794
if (cache.contains(userAccount.getUserId())) {
7895
dbManager.updateDb(userAccount);
7996
} else {
@@ -84,11 +101,13 @@ public void writeThrough(UserAccount userAccount) {
84101

85102
/**
86103
* Get user account using write-around cache.
104+
* @param userAccount {@link UserAccount}
87105
*/
88-
public void writeAround(UserAccount userAccount) {
106+
public void writeAround(final UserAccount userAccount) {
89107
if (cache.contains(userAccount.getUserId())) {
90108
dbManager.updateDb(userAccount);
91-
cache.invalidate(userAccount.getUserId()); // Cache data has been updated -- remove older
109+
// Cache data has been updated -- remove older
110+
cache.invalidate(userAccount.getUserId());
92111
// version from cache.
93112
} else {
94113
dbManager.writeToDb(userAccount);
@@ -97,8 +116,10 @@ public void writeAround(UserAccount userAccount) {
97116

98117
/**
99118
* Get user account using read-through cache with write-back policy.
119+
* @param userId {@link String}
120+
* @return {@link UserAccount}
100121
*/
101-
public UserAccount readThroughWithWriteBackPolicy(String userId) {
122+
public UserAccount readThroughWithWriteBackPolicy(final String userId) {
102123
if (cache.contains(userId)) {
103124
LOGGER.info("# Found in cache!");
104125
return cache.get(userId);
@@ -116,8 +137,9 @@ public UserAccount readThroughWithWriteBackPolicy(String userId) {
116137

117138
/**
118139
* Set user account.
140+
* @param userAccount {@link UserAccount}
119141
*/
120-
public void writeBehind(UserAccount userAccount) {
142+
public void writeBehind(final UserAccount userAccount) {
121143
if (cache.isFull() && !cache.contains(userAccount.getUserId())) {
122144
LOGGER.info("# Cache is FULL! Writing LRU data to DB...");
123145
UserAccount toBeWrittenToDb = cache.getLruData();
@@ -148,6 +170,7 @@ public void flushCache() {
148170

149171
/**
150172
* Print user accounts.
173+
* @return {@link String}
151174
*/
152175
public String print() {
153176
return Optional.ofNullable(cache)
@@ -160,22 +183,27 @@ public String print() {
160183

161184
/**
162185
* Delegate to backing cache store.
186+
* @param userId {@link String}
187+
* @return {@link UserAccount}
163188
*/
164-
public UserAccount get(String userId) {
189+
public UserAccount get(final String userId) {
165190
return cache.get(userId);
166191
}
167192

168193
/**
169194
* Delegate to backing cache store.
195+
* @param userId {@link String}
196+
* @param userAccount {@link UserAccount}
170197
*/
171-
public void set(String userId, UserAccount userAccount) {
198+
public void set(final String userId, final UserAccount userAccount) {
172199
cache.set(userId, userAccount);
173200
}
174201

175202
/**
176203
* Delegate to backing cache store.
204+
* @param userId {@link String}
177205
*/
178-
public void invalidate(String userId) {
206+
public void invalidate(final String userId) {
179207
cache.invalidate(userId);
180208
}
181209
}

0 commit comments

Comments
 (0)