BAEL-4464 : how to implement LRU-Cache in java codes added (#11036)
* BAEL-4464 : how to implement LRU-Cache in java codes added * BAEL-4464 : how to implement LRU-Cache in java codes added - package named fixed * BAEL-4464 : how to implement LRU-Cache in java codes added - package named changed * BAEL-4464 : how to implement LRU-Cache in java codes added - unitTest fixed
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.baeldung.lrucache;
|
||||
|
||||
/**
|
||||
* Created by arash on 09.07.21.
|
||||
*/
|
||||
public class Node<T> implements LinkedListNode<T> {
|
||||
private T value;
|
||||
private DoublyLinkedList<T> list;
|
||||
private LinkedListNode next;
|
||||
private LinkedListNode prev;
|
||||
|
||||
public Node(T value, LinkedListNode<T> next, DoublyLinkedList<T> list) {
|
||||
this.value = value;
|
||||
this.next = next;
|
||||
this.setPrev(next.getPrev());
|
||||
this.prev.setNext(this);
|
||||
this.next.setPrev(this);
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasElement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public T getElement() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
this.prev.setNext(this.getNext());
|
||||
this.next.setPrev(this.getPrev());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoublyLinkedList<T> getListReference() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedListNode<T> setPrev(LinkedListNode<T> prev) {
|
||||
this.prev = prev;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedListNode<T> setNext(LinkedListNode<T> next) {
|
||||
this.next = next;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedListNode<T> getPrev() {
|
||||
return this.prev;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedListNode<T> getNext() {
|
||||
return this.next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedListNode<T> search(T value) {
|
||||
return this.getElement() == value ? this : this.getNext().search(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user