Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitaff7ef8

Browse files
committed
Fix last errors in checkstyle.
1 parentc150e5f commitaff7ef8

File tree

10 files changed

+249
-65
lines changed

10 files changed

+249
-65
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,25 @@
3232
@AllArgsConstructor
3333
@Getter
3434
publicenumCachingPolicy {
35+
/**
36+
* Through.
37+
*/
3538
THROUGH("through"),
39+
/**
40+
* AROUND.
41+
*/
3642
AROUND("around"),
43+
/**
44+
* BEHIND.
45+
*/
3746
BEHIND("behind"),
47+
/**
48+
* ASIDE.
49+
*/
3850
ASIDE("aside");
3951

52+
/**
53+
* Policy value.
54+
*/
4055
privatefinalStringpolicy;
4156
}

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

Lines changed: 93 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,78 @@
3030
importlombok.extern.slf4j.Slf4j;
3131

3232
/**
33-
* Data structure/implementation of the application's cache. The data structure consists of a hash
34-
* table attached with a doubly linked-list. The linked-list helps in capturing and maintaining the
35-
* LRU data in the cache. When a data is queried (from the cache), added (to the cache), or updated,
36-
* the data is moved to the front of the list to depict itself as the most-recently-used data. The
37-
* LRU data is always at the end of the list.
33+
* Data structure/implementation of the application's cache. The data structure
34+
* consists of a hash table attached with a doubly linked-list. The linked-list
35+
* helps in capturing and maintaining the LRU data in the cache. When a data is
36+
* queried (from the cache), added (to the cache), or updated, the data is
37+
* moved to the front of the list to depict itself as the most-recently-used
38+
* data. The LRU data is always at the end of the list.
3839
*/
3940
@Slf4j
4041
publicclassLruCache {
41-
42+
/**
43+
* Static class Node.
44+
*/
4245
staticclassNode {
43-
StringuserId;
44-
UserAccountuserAccount;
45-
Nodeprevious;
46-
Nodenext;
47-
48-
publicNode(StringuserId,UserAccountuserAccount) {
49-
this.userId =userId;
50-
this.userAccount =userAccount;
46+
/**
47+
* user id.
48+
*/
49+
privatefinalStringuserId;
50+
/**
51+
* User Account.
52+
*/
53+
privateUserAccountuserAccount;
54+
/**
55+
* previous.
56+
*/
57+
privateNodeprevious;
58+
/**
59+
* next.
60+
*/
61+
privateNodenext;
62+
63+
/**
64+
* Node definition.
65+
* @param id String
66+
* @param account {@link UserAccount}
67+
*/
68+
Node(finalStringid,finalUserAccountaccount) {
69+
this.userId =id;
70+
this.userAccount =account;
5171
}
5272
}
5373

54-
intcapacity;
55-
Map<String,Node>cache =newHashMap<>();
56-
Nodehead;
57-
Nodeend;
74+
/**
75+
* Capacity of Cache.
76+
*/
77+
privateintcapacity;
78+
/**
79+
* Cache {@link HashMap}.
80+
*/
81+
privateMap<String,Node>cache =newHashMap<>();
82+
/**
83+
* Head.
84+
*/
85+
privateNodehead;
86+
/**
87+
* End.
88+
*/
89+
privateNodeend;
5890

59-
publicLruCache(intcapacity) {
60-
this.capacity =capacity;
91+
/**
92+
* Constructor.
93+
* @param cap Integer.
94+
*/
95+
publicLruCache(finalintcap) {
96+
this.capacity =cap;
6197
}
6298

6399
/**
64100
* Get user account.
101+
* @param userId String
102+
* @return {@link UserAccount}
65103
*/
66-
publicUserAccountget(StringuserId) {
104+
publicUserAccountget(finalStringuserId) {
67105
if (cache.containsKey(userId)) {
68106
varnode =cache.get(userId);
69107
remove(node);
@@ -75,8 +113,9 @@ public UserAccount get(String userId) {
75113

76114
/**
77115
* Remove node from linked list.
116+
* @param node {@link Node}
78117
*/
79-
publicvoidremove(Nodenode) {
118+
publicvoidremove(finalNodenode) {
80119
if (node.previous !=null) {
81120
node.previous.next =node.next;
82121
}else {
@@ -91,8 +130,9 @@ public void remove(Node node) {
91130

92131
/**
93132
* Move node to the front of the list.
133+
* @param node {@link Node}
94134
*/
95-
publicvoidsetHead(Nodenode) {
135+
publicvoidsetHead(finalNodenode) {
96136
node.next =head;
97137
node.previous =null;
98138
if (head !=null) {
@@ -106,8 +146,10 @@ public void setHead(Node node) {
106146

107147
/**
108148
* Set user account.
149+
* @param userAccount {@link UserAccount}
150+
* @param userId {@link String}
109151
*/
110-
publicvoidset(StringuserId,UserAccountuserAccount) {
152+
publicvoidset(finalStringuserId,finalUserAccountuserAccount) {
111153
if (cache.containsKey(userId)) {
112154
varold =cache.get(userId);
113155
old.userAccount =userAccount;
@@ -127,25 +169,40 @@ public void set(String userId, UserAccount userAccount) {
127169
}
128170
}
129171

130-
publicbooleancontains(StringuserId) {
172+
/**
173+
* Che if Cache cintains the userId.
174+
* @param userId {@link String}
175+
* @return boolean
176+
*/
177+
publicbooleancontains(finalStringuserId) {
131178
returncache.containsKey(userId);
132179
}
133180

134-
/**
135-
* Invalidate cache for user.
136-
*/
137-
publicvoidinvalidate(StringuserId) {
181+
/**
182+
* Invalidate cache for user.
183+
* @param userId {@link String}
184+
*/
185+
publicvoidinvalidate(finalStringuserId) {
138186
vartoBeRemoved =cache.remove(userId);
139187
if (toBeRemoved !=null) {
140-
LOGGER.info("# {} has been updated! Removing older version from cache...",userId);
188+
LOGGER.info("# {} has been updated! "
189+
+"Removing older version from cache...",userId);
141190
remove(toBeRemoved);
142191
}
143192
}
144193

194+
/**
195+
* Is cache full?
196+
* @return boolean
197+
*/
145198
publicbooleanisFull() {
146199
returncache.size() >=capacity;
147200
}
148201

202+
/**
203+
* Get LRU data.
204+
* @return {@link UserAccount}
205+
*/
149206
publicUserAccountgetLruData() {
150207
returnend.userAccount;
151208
}
@@ -161,6 +218,7 @@ public void clear() {
161218

162219
/**
163220
* Returns cache data in list form.
221+
* @return {@link List}
164222
*/
165223
publicList<UserAccount>getCacheDataInListForm() {
166224
varlistOfCacheData =newArrayList<UserAccount>();
@@ -174,10 +232,13 @@ public List<UserAccount> getCacheDataInListForm() {
174232

175233
/**
176234
* Set cache capacity.
235+
* @param newCapacity int
177236
*/
178-
publicvoidsetCapacity(intnewCapacity) {
237+
publicvoidsetCapacity(finalintnewCapacity) {
179238
if (capacity >newCapacity) {
180-
clear();// Behavior can be modified to accommodate for decrease in cache size. For now, we'll
239+
// Behavior can be modified to accommodate
240+
// for decrease in cache size. For now, we'll
241+
clear();
181242
// just clear the cache.
182243
}else {
183244
this.capacity =newCapacity;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@
3636
@AllArgsConstructor
3737
@ToString
3838
publicclassUserAccount {
39+
/**
40+
* User Id.
41+
*/
3942
privateStringuserId;
43+
/**
44+
* User Name.
45+
*/
4046
privateStringuserName;
47+
/**
48+
* Additional Info.
49+
*/
4150
privateStringadditionalInfo;
4251
}

‎caching/src/main/java/com/iluwatar/caching/constants/CachingConstants.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,27 @@
2626
/**
2727
* Constant class for defining constants.
2828
*/
29-
publicclassCachingConstants {
30-
29+
publicfinalclassCachingConstants {
30+
/**
31+
* User Account.
32+
*/
3133
publicstaticfinalStringUSER_ACCOUNT ="user_accounts";
34+
/**
35+
* User ID.
36+
*/
3237
publicstaticfinalStringUSER_ID ="userID";
38+
/**
39+
* User Name.
40+
*/
3341
publicstaticfinalStringUSER_NAME ="userName";
42+
/**
43+
* Additional Info.
44+
*/
3445
publicstaticfinalStringADD_INFO ="additionalInfo";
3546

47+
/**
48+
* Constructor.
49+
*/
50+
privateCachingConstants() {
51+
}
3652
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Constants.
3+
*/
4+
packagecom.iluwatar.caching.constants;

‎caching/src/main/java/com/iluwatar/caching/database/DbManagerFactory.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
packagecom.iluwatar.caching.database;
22

3-
publicclassDbManagerFactory {
4-
publicstaticDbManagerinitDb(booleanisMongo){
5-
if(isMongo){
3+
/**
4+
* Creates the database connection accroding the input parameter.
5+
*/
6+
publicfinalclassDbManagerFactory {
7+
/**
8+
* Private constructor.
9+
*/
10+
privateDbManagerFactory() {
11+
}
12+
13+
/**
14+
* Init database.
15+
*
16+
* @param isMongo boolean
17+
* @return {@link DbManager}
18+
*/
19+
publicstaticDbManagerinitDb(finalbooleanisMongo) {
20+
if (isMongo) {
621
returnnewMongoDb();
722
}
823
returnnewVirtualDb();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp