📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@ -23,8 +23,7 @@
|
||||
|
||||
package com.iluwatar.caching;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The Caching pattern describes how to avoid expensive re-acquisition of resources by not releasing
|
||||
@ -60,11 +59,9 @@ import org.slf4j.LoggerFactory;
|
||||
* @see LruCache
|
||||
* @see CachingPolicy
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
|
@ -26,16 +26,14 @@ package com.iluwatar.caching;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The caching strategies are implemented in this class.
|
||||
*/
|
||||
@Slf4j
|
||||
public class CacheStore {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CacheStore.class);
|
||||
|
||||
private static LruCache cache;
|
||||
|
||||
private CacheStore() {
|
||||
|
@ -23,19 +23,19 @@
|
||||
|
||||
package com.iluwatar.caching;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Enum class containing the four caching strategies implemented in the pattern.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CachingPolicy {
|
||||
THROUGH("through"), AROUND("around"), BEHIND("behind"), ASIDE("aside");
|
||||
THROUGH("through"),
|
||||
AROUND("around"),
|
||||
BEHIND("behind"),
|
||||
ASIDE("aside");
|
||||
|
||||
private final String policy;
|
||||
|
||||
CachingPolicy(String policy) {
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public String getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Data structure/implementation of the application's cache. The data structure consists of a hash
|
||||
@ -37,11 +36,10 @@ import org.slf4j.LoggerFactory;
|
||||
* the data is moved to the front of the list to depict itself as the most-recently-used data. The
|
||||
* LRU data is always at the end of the list.
|
||||
*/
|
||||
@Slf4j
|
||||
public class LruCache {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LruCache.class);
|
||||
|
||||
class Node {
|
||||
static class Node {
|
||||
String userId;
|
||||
UserAccount userAccount;
|
||||
Node previous;
|
||||
|
@ -23,49 +23,20 @@
|
||||
|
||||
package com.iluwatar.caching;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Entity class (stored in cache and DB) used in the application.
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class UserAccount {
|
||||
private String userId;
|
||||
private String userName;
|
||||
private String additionalInfo;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public UserAccount(String userId, String userName, String additionalInfo) {
|
||||
this.userId = userId;
|
||||
this.userName = userName;
|
||||
this.additionalInfo = additionalInfo;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getAdditionalInfo() {
|
||||
return additionalInfo;
|
||||
}
|
||||
|
||||
public void setAdditionalInfo(String additionalInfo) {
|
||||
this.additionalInfo = additionalInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return userId + ", " + userName + ", " + additionalInfo;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user