Skip to main content
2 of 4
Codereview not necessary in title
Caridorc
  • 27.6k
  • 7
  • 54
  • 135

Generic Linked List Implementation in Java

I am looking for feedback on my Doubly Linked List implementation that I have written in Java. I am looking for specific feedback on the efficiency of my code, as well as my usage of generics. I am pretty new to using generics in Java, and I'm not quite sure that I am using them correctly yet.

My node class is pretty basic, but I'd like to revisit my Equals and Hashcode. Am I implementing these correctly? See snippet below:

My node class's equals/hashcode:

@Override
public boolean equals(Object that){
    if(this == that)
        return true;
    if(!(that instanceof LLNode))
        return false;
    
    return this.data.equals(((LLNode)that).getData());
}

@Override
public int hashCode(){
    return (this.data == null ? 0 : this.data.hashCode());
}     

The DoublyLinkedList class, where the linked list is actually implemented can be found below, as there is too much to post here I think. Am I missing any major functionality? Are generics used properly? https://github.com/matt-y/DataStructures/blob/master/src/JavaDataStructures/DoublyLinkedList.java

If possible I'd also like to have my test cases reviewed to see if they are strong enough, and at least somewhat well designed. Those are here: https://github.com/matt-y/DataStructures/tree/master/test/JavaDataStructures

I was unsure of how to test certain things - specifically cases where I am expecting exceptions to be thrown.

mabufo
  • 301
  • 2
  • 6