Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/main/java/com/uditagarwal/algoritms/DoublyLinkedList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.uditagarwal.algoritms;

import com.uditagarwal.algoritms.exceptions.InvalidElementException;
import lombok.Getter;

import java.util.NoSuchElementException;

Expand Down Expand Up @@ -48,7 +47,7 @@ public void detachNode(DoublyLinkedListNode<E> node) {
* @param node Node to be added.
*/
public void addNodeAtLast(DoublyLinkedListNode<E> node) {
DoublyLinkedListNode tailPrev = dummyTail.prev;
DoublyLinkedListNode<E> tailPrev = dummyTail.prev;
tailPrev.next = node;
node.next = dummyTail;
dummyTail.prev = node;
Expand All @@ -74,16 +73,14 @@ public boolean isItemPresent() {
return dummyHead.next != dummyTail;
}

public DoublyLinkedListNode getFirstNode() throws NoSuchElementException {
DoublyLinkedListNode item = null;
public DoublyLinkedListNode<E> getFirstNode() throws NoSuchElementException {
if (!isItemPresent()) {
return null;
}
return dummyHead.next;
}

public DoublyLinkedListNode getLastNode() throws NoSuchElementException {
DoublyLinkedListNode item = null;
public DoublyLinkedListNode<E> getLastNode() throws NoSuchElementException {
if (!isItemPresent()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public DoublyLinkedListNode(E element) {
this.next = null;
this.prev = null;
}

public E getElement() {
return this.element;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (c) 2019, lld-cache.
* All rights reserved.
*/
public class CacheTest {
public class TestCacheTest {

Cache<Integer, Integer> cache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static org.junit.jupiter.api.Assertions.*;

class DoublyLinkedListTest {
class TestDoublyLinkedListTest {

@Test
void testDLLAddition() {
Expand Down Expand Up @@ -39,9 +39,7 @@ void testDLLNodeDetachment() {
DoublyLinkedList<Integer> dll = new DoublyLinkedList<>();

DoublyLinkedListNode<Integer> node1 = dll.addElementAtLast(1);
DoublyLinkedListNode<Integer> node2 = dll.addElementAtLast(2);
DoublyLinkedListNode<Integer> node3 = dll.addElementAtLast(3);
DoublyLinkedListNode<Integer> node4 = dll.addElementAtLast(4);
DoublyLinkedListNode<Integer> node5 = dll.addElementAtLast(5);

verifyDLL(dll, ImmutableList.of(1, 2, 3, 4, 5));
Expand All @@ -67,7 +65,7 @@ void verifyDLL(DoublyLinkedList<Integer> dll, List<Integer> expectedListElements
for (Integer expectedListElement : expectedListElements) {
assertNotNull(currentNode);
assertEquals(expectedListElement, currentNode.getElement());
currentNode = currentNode.getNext();
currentNode = currentNode.next;
}
assertNull(currentNode.next);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import static org.junit.jupiter.api.Assertions.*;

class LRUEvictionPolicyTest {
class TestLRUEvictionPolicyTest {
private LRUEvictionPolicy<Integer> lruEvictionPolicy;

@BeforeEach
Expand Down