diff --git a/app/src/main/java/ch/nuth/zhaw/exbox/MyList.java b/app/src/main/java/ch/nuth/zhaw/exbox/MyList.java index 718011a..1ce3e6e 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/MyList.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/MyList.java @@ -188,11 +188,24 @@ public class MyList extends AbstractList { return anchor; } + /** + * Inserts the specified `item` after the specified `node`. + * + * @param node + * The node to insert the `item` after. + * + * @param item + * The item to insert. + */ + protected void insertAfter(IListNode node, Object item) { + IListNode newNode = new ListNode(item, node, node.getNextNode()); + node.setNextNode(newNode); + newNode.getNextNode().setPreviousNode(newNode); + } + @Override public boolean add(Object e) { - IListNode newNode = new ListNode(e, getAnchor(), getAnchor().getPreviousNode()); - getAnchor().getPreviousNode().setNextNode(newNode); - getAnchor().setPreviousNode(newNode); + insertAfter(getAnchor().getPreviousNode(), e); return true; }