Simplify remove method

This commit is contained in:
Manuel Thalmann 2022-09-28 09:53:01 +02:00
parent aee1199bee
commit 83700823d0

View file

@ -197,18 +197,9 @@ public class MyList extends AbstractList<Object> {
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public boolean remove(Object o) {
for (IListNode node = getAnchor().getNextNode(); node != getAnchor(); node = node.getNextNode()) {
boolean isEqual = false;
try {
isEqual = ((Comparable) o).compareTo((node.getItem())) == 0;
} catch (Exception e) {
isEqual = node.getItem() == o;
}
if (isEqual) {
if (node.getItem().equals(o)) {
node.getPreviousNode().setNextNode(node.getNextNode());
node.getNextNode().setPreviousNode(node.getPreviousNode());
return true;