Simplify remove
method
This commit is contained in:
parent
aee1199bee
commit
83700823d0
|
@ -197,18 +197,9 @@ public class MyList extends AbstractList<Object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
for (IListNode node = getAnchor().getNextNode(); node != getAnchor(); node = node.getNextNode()) {
|
for (IListNode node = getAnchor().getNextNode(); node != getAnchor(); node = node.getNextNode()) {
|
||||||
boolean isEqual = false;
|
if (node.getItem().equals(o)) {
|
||||||
|
|
||||||
try {
|
|
||||||
isEqual = ((Comparable) o).compareTo((node.getItem())) == 0;
|
|
||||||
} catch (Exception e) {
|
|
||||||
isEqual = node.getItem() == o;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEqual) {
|
|
||||||
node.getPreviousNode().setNextNode(node.getNextNode());
|
node.getPreviousNode().setNextNode(node.getNextNode());
|
||||||
node.getNextNode().setPreviousNode(node.getPreviousNode());
|
node.getNextNode().setPreviousNode(node.getPreviousNode());
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue