Example;
compactar({2,2,2,2})>>>> {2}
compactar({2,2,null,null,2,3})>>>>{2,null,2,3}
compactar({2,2,1,2})>>>>{2,1,2}
compactar({})>>>>{}
compactar({1,2,3,null,null})>>>>{1,2,3,null}
compactar({null})>>>>{null}
compactar(null)>>>>IllegalArgumentException
"The method returns [] instead of [1] when invoked with [1]."
I only get this error but I still do not know why, I made several changes but I can not find the result. The method basically seeks to compact the consecutive elements equal to a single appearance.
public <E> PositionList<E> compactar (PositionList<E> lista) {
PositionList<E> list= new NodePositionList<E>();
Position<E> cursor=list.first();
if(lista==null ) {
throw new IllegalArgumentException();
}// de if
Position <E> cursor1= list.last();
while(cursor!=null) {
if(cursor.equals(lista.next(cursor))) {
Position<E> borrar=cursor;
cursor=lista.next(cursor);
lista.remove(borrar);
list.addLast(cursor.element());
}// de if 2
}// de bucle for
return list;
}// de compactar