Simplify remove
method
This commit is contained in:
parent
aee1199bee
commit
83700823d0
1 changed files with 1 additions and 10 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue