package com.baeldung.lrucache; /** * Created by arash on 09.07.21. */ public class Node implements LinkedListNode { private T value; private DoublyLinkedList list; private LinkedListNode next; private LinkedListNode prev; public Node(T value, LinkedListNode next, DoublyLinkedList 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 getListReference() { return this.list; } @Override public LinkedListNode setPrev(LinkedListNode prev) { this.prev = prev; return this; } @Override public LinkedListNode setNext(LinkedListNode next) { this.next = next; return this; } @Override public LinkedListNode getPrev() { return this.prev; } @Override public LinkedListNode getNext() { return this.next; } @Override public LinkedListNode search(T value) { return this.getElement() == value ? this : this.getNext().search(value); } }