[SOLVED] Needing a little advice on a method in my circular linked list.

Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Needing a little advice on a method in my circular linked list.

So, the method that I'm having problems with at the moment is my insertAt method, which takes an integer and an item as parameters and then adds the item to the circular linked list at the index of the list that the integer specifies. If the index passed through is less than 0 or greater than the number of elements in the list then it throws a new Index Out of Bounds Exception. I can't seem to figure out what the problem is with this method. Any advice would be greatly appreciated. The error I'm getting is this:

publicclass CLinkedListTest {publicstaticvoid main(String[] args){
CLinkedListTest me =new CLinkedListTest();
me.run();}publicvoid run(){
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
test9();
test10();
test11();
test12();
test13();
test14();
test15();
test16();
test17();
test18();
test19();
test20();
test21();}//Test to see that the initial list is empty.publicvoid test1(){
CLinkedList test =new CLinkedList();assert0== test.size();}//Test to see if append works on an empty CLL.publicvoid test2(){
CLinkedList<String> test =new CLinkedList<String>();
test.append("A");assert1== test.size();}//Test to see if append is working on a non-empty CLL.publicvoid test3(){
CLinkedList<String> test =new CLinkedList<String>();
test.append("A");
test.append("B");assert2== test.size();}//Test to see if add is working on an empty CLL.publicvoid test4(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");assert1== test.size();}//Test to see if add is working on a non-empty CLL.publicvoid test5(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.add("B");assert2== test.size();}//Test to see if remove is working on an empty CLL.publicvoid test6(){
CLinkedList<String> test =new CLinkedList<String>();
test.remove("A");assert0== test.size();assert(test.remove("A")==false);}//Test to see if remove is working on a non-empty CLL.publicvoid test7(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.remove("A");assert0== test.size();assert(test.remove("A")==true);}//Test to see if insertAt is working on an empty CLL.publicvoid test8(){
CLinkedList<String> test =new CLinkedList<String>();
test.insertAt(0, "A");assert1== test.size();}//Test to see if insertAt is working on a non-empty CLL.publicvoid test9(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.add("B");
test.add("C");
test.insertAt(1, "D");assert4== test.size();}//Test to see if insertAt throws an out OutOfBoundsException.publicvoid test10(){
CLinkedList<String> test =new CLinkedList<String>();
test.insertAt(-1, "A");assert0== test.size();}//Test to see if removeAt is working on an empty CLL.publicvoid test11(){
CLinkedList<String> test =new CLinkedList<String>();
test.removeAt(0);assert0== test.size();}//Test to see if removeAt is working on a non-empty CLL.publicvoid test12(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.add("B");
test.add("C");
test.removeAt(2);assert2== test.size();}//Test to see if removeAt throws an OutOfBoundsException.publicvoid test13(){
CLinkedList<String> test =new CLinkedList<String>();
test.removeAt(-1);assert0== test.size();}//Test to see if setAt overwrites index location in an empty CLL.publicvoid test14(){
CLinkedList<String> test =new CLinkedList<String>();
test.setAt("A", 0);assert1== test.size();}//Test to see if setAt overwrites index location in a non-empty CLL.publicvoid test15(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.add("B");
test.add("C");
test.setAt("D", 1);assert3== test.size();}//Test to see if setAt throws an OutOfBoundsException.publicvoid test16(){
CLinkedList<String> test =new CLinkedList<String>();
test.setAt("A", -1);assert0== test.size();}//Test to see if getAt is working on a non-empty CLL.publicvoid test17(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.add("B");
test.getAt(1);assert2== test.size();}//Test to see if getAt throws an OutOfBoundsException.publicvoid test18(){
CLinkedList<String> test =new CLinkedList<String>();
test.getAt(-1);assert0== test.size();}//Test to see if indexOf is working in a non-empty CLL.publicvoid test19(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.add("B");
test.add("C");
test.indexOf("B");assert3== test.size();assert(test.indexOf("B")==1);}//Test to see if isEmpty is working on an empty CLL.publicvoid test20(){
CLinkedList<String> test =new CLinkedList<String>();
test.isEmpty();assert0== test.size();assert(test.isEmpty()==true);}//Test to see if isEmpty is working on a non-empty CLL.publicvoid test21(){
CLinkedList<String> test =new CLinkedList<String>();
test.add("A");
test.isEmpty();assert1== test.size();assert(test.isEmpty()==false);}}

Re: Needing a little advice on a method in my circular linked list.

I figured it out. I was purposely passing the -1 index value to test if the method threw the exception, but it seems that would be unnecessary because its tested in the other test methods. Thanks for the help.