Quote (ROM @ Oct 25 2015 11:36am)
Code
System.out.printf("\nDetect Duplicates:\n");
ListIterator recordIterator = recordLinkedList.listIterator();
while(recordIterator.hasNext())
{
if(recordIterator.hasPrevious())
{
if(recordIterator.next()==recordIterator.previous())
{
System.out.println("There is a duplicate");
}
else if(recordIterator.next()!=recordIterator.previous())
{
System.out.println("There are no duplicates");
}
}
recordIterator.next();
}
Stuck :lol:
None of the records are the same integer and all I get is There are duplicates four times.
I've tried
Code
if (recordIterator.next().equals(recordIterator.previous()))
and get the same result.
I don't see any logging bro.
I suggest creating a wrapper around the iterator. then every time you call next() or previous() it will log what value is getting returned and the cursor position.
eg:
Code
ListIterator recordIterator = new ListIteratorWithLogging(recordLinkedList.listIterator());
where:
Code
class ListIteratorWithLogging implements ListIterator{
ListIterator _source = null;
Object _current = null;
public ListIteratorWithLogging(ListIterator source){
_source = source;
}
public Object next(){
Object nextValue = _source.next();
log.debug("next() moved from " + _current + " to " + nextValue);
_current = nextValue;
return nextValue;
}
// other methods
}
that way when you're ready to turn in your assignment, you simply change one line of code where you use your wrapper and dont have to worry about removing logging or extraneous variables.
This post was edited by carteblanche on Oct 25 2015 09:54am