Fix issues in VALIDATE phase
This commit is contained in:
parent
dabe4d2022
commit
49039843e5
@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
package com.iluwatar.caching;
|
package com.iluwatar.caching;
|
||||||
|
|
||||||
|
import com.iluwatar.caching.database.DbManager;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.iluwatar.caching.database.DbManager;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@ -23,11 +23,11 @@
|
|||||||
|
|
||||||
package com.iluwatar.caching;
|
package com.iluwatar.caching;
|
||||||
|
|
||||||
|
import com.iluwatar.caching.database.DbManager;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.iluwatar.caching.database.DbManager;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data structure/implementation of the application's cache. The data structure
|
* Data structure/implementation of the application's cache. The data structure
|
||||||
* consists of a hash table attached with a doubly linked-list. The linked-list
|
* consists of a hash table attached with a doubly linked-list. The linked-list
|
||||||
@ -62,6 +63,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Node definition.
|
* Node definition.
|
||||||
|
*
|
||||||
* @param id String
|
* @param id String
|
||||||
* @param account {@link UserAccount}
|
* @param account {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
@ -90,6 +92,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
*
|
||||||
* @param cap Integer.
|
* @param cap Integer.
|
||||||
*/
|
*/
|
||||||
public LruCache(final int cap) {
|
public LruCache(final int cap) {
|
||||||
@ -98,6 +101,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user account.
|
* Get user account.
|
||||||
|
*
|
||||||
* @param userId String
|
* @param userId String
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
@ -113,6 +117,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove node from linked list.
|
* Remove node from linked list.
|
||||||
|
*
|
||||||
* @param node {@link Node}
|
* @param node {@link Node}
|
||||||
*/
|
*/
|
||||||
public void remove(final Node node) {
|
public void remove(final Node node) {
|
||||||
@ -130,6 +135,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Move node to the front of the list.
|
* Move node to the front of the list.
|
||||||
|
*
|
||||||
* @param node {@link Node}
|
* @param node {@link Node}
|
||||||
*/
|
*/
|
||||||
public void setHead(final Node node) {
|
public void setHead(final Node node) {
|
||||||
@ -146,6 +152,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set user account.
|
* Set user account.
|
||||||
|
*
|
||||||
* @param userAccount {@link UserAccount}
|
* @param userAccount {@link UserAccount}
|
||||||
* @param userId {@link String}
|
* @param userId {@link String}
|
||||||
*/
|
*/
|
||||||
@ -171,6 +178,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Che if Cache cintains the userId.
|
* Che if Cache cintains the userId.
|
||||||
|
*
|
||||||
* @param userId {@link String}
|
* @param userId {@link String}
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@ -180,6 +188,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidate cache for user.
|
* Invalidate cache for user.
|
||||||
|
*
|
||||||
* @param userId {@link String}
|
* @param userId {@link String}
|
||||||
*/
|
*/
|
||||||
public void invalidate(final String userId) {
|
public void invalidate(final String userId) {
|
||||||
@ -192,7 +201,7 @@ public class LruCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is cache full?
|
* Check if the cache is full.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean isFull() {
|
public boolean isFull() {
|
||||||
@ -201,6 +210,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get LRU data.
|
* Get LRU data.
|
||||||
|
*
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
public UserAccount getLruData() {
|
public UserAccount getLruData() {
|
||||||
@ -218,6 +228,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns cache data in list form.
|
* Returns cache data in list form.
|
||||||
|
*
|
||||||
* @return {@link List}
|
* @return {@link List}
|
||||||
*/
|
*/
|
||||||
public List<UserAccount> getCacheDataInListForm() {
|
public List<UserAccount> getCacheDataInListForm() {
|
||||||
@ -232,6 +243,7 @@ public class LruCache {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set cache capacity.
|
* Set cache capacity.
|
||||||
|
*
|
||||||
* @param newCapacity int
|
* @param newCapacity int
|
||||||
*/
|
*/
|
||||||
public void setCapacity(final int newCapacity) {
|
public void setCapacity(final int newCapacity) {
|
||||||
|
@ -19,18 +19,21 @@ public interface DbManager {
|
|||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
UserAccount readFromDb(String userId);
|
UserAccount readFromDb(String userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write to DB.
|
* Write to DB.
|
||||||
* @param userAccount {@link UserAccount}
|
* @param userAccount {@link UserAccount}
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
UserAccount writeToDb(UserAccount userAccount);
|
UserAccount writeToDb(UserAccount userAccount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update record.
|
* Update record.
|
||||||
* @param userAccount {@link UserAccount}
|
* @param userAccount {@link UserAccount}
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
UserAccount updateDb(UserAccount userAccount);
|
UserAccount updateDb(UserAccount userAccount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update record or Insert if not exists.
|
* Update record or Insert if not exists.
|
||||||
* @param userAccount {@link UserAccount}
|
* @param userAccount {@link UserAccount}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.iluwatar.caching.database;
|
package com.iluwatar.caching.database;
|
||||||
|
|
||||||
|
import static com.iluwatar.caching.constants.CachingConstants.ADD_INFO;
|
||||||
|
import static com.iluwatar.caching.constants.CachingConstants.USER_ACCOUNT;
|
||||||
|
import static com.iluwatar.caching.constants.CachingConstants.USER_ID;
|
||||||
|
import static com.iluwatar.caching.constants.CachingConstants.USER_NAME;
|
||||||
|
|
||||||
import com.iluwatar.caching.UserAccount;
|
import com.iluwatar.caching.UserAccount;
|
||||||
import com.iluwatar.caching.constants.CachingConstants;
|
import com.iluwatar.caching.constants.CachingConstants;
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
@ -7,11 +12,6 @@ import com.mongodb.client.MongoDatabase;
|
|||||||
import com.mongodb.client.model.UpdateOptions;
|
import com.mongodb.client.model.UpdateOptions;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
|
||||||
import static com.iluwatar.caching.constants.CachingConstants.USER_NAME;
|
|
||||||
import static com.iluwatar.caching.constants.CachingConstants.ADD_INFO;
|
|
||||||
import static com.iluwatar.caching.constants.CachingConstants.USER_ID;
|
|
||||||
import static com.iluwatar.caching.constants.CachingConstants.USER_ACCOUNT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of DatabaseManager.
|
* Implementation of DatabaseManager.
|
||||||
* implements base methods to work with MongoDb.
|
* implements base methods to work with MongoDb.
|
||||||
|
@ -25,6 +25,7 @@ public class VirtualDb implements DbManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Read from Db.
|
* Read from Db.
|
||||||
|
*
|
||||||
* @param userId {@link String}
|
* @param userId {@link String}
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
@ -38,6 +39,7 @@ public class VirtualDb implements DbManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Write to DB.
|
* Write to DB.
|
||||||
|
*
|
||||||
* @param userAccount {@link UserAccount}
|
* @param userAccount {@link UserAccount}
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
@ -49,6 +51,7 @@ public class VirtualDb implements DbManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update reecord in DB.
|
* Update reecord in DB.
|
||||||
|
*
|
||||||
* @param userAccount {@link UserAccount}
|
* @param userAccount {@link UserAccount}
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
@ -59,6 +62,7 @@ public class VirtualDb implements DbManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update.
|
* Update.
|
||||||
|
*
|
||||||
* @param userAccount {@link UserAccount}
|
* @param userAccount {@link UserAccount}
|
||||||
* @return {@link UserAccount}
|
* @return {@link UserAccount}
|
||||||
*/
|
*/
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright © 2014-2021 Ilkka Seppälä
|
* Copyright © 2014-2021 Ilkka Seppälä
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user