public final void moveToEnd(E element) {
        if (element.prev() == INVALID_INDEX || element.next() == INVALID_INDEX) {
            throw new RuntimeException("Element " + element + " is not in the collection.");
        }
        Element prevElement = indexToElement(head, elements, element.prev());
        Element nextElement = indexToElement(head, elements, element.next());
        int slot = prevElement.next();
        prevElement.setNext(element.next());
        nextElement.setPrev(element.prev());
        addToListTail(head, elements, slot);
    }
@Test
    public void testMoveToEnd() {
        ImplicitLinkedHashCollection<TestElement> coll = new ImplicitLinkedHashCollection<>();
        TestElement e1 = new TestElement(1, 1);
        TestElement e2 = new TestElement(2, 2);
        TestElement e3 = new TestElement(3, 3);
        assertTrue(coll.add(e1));
        assertTrue(coll.add(e2));
        assertTrue(coll.add(e3));
        coll.moveToEnd(e1);
        expectTraversal(coll.iterator(), 2, 3, 1);
        assertThrows(RuntimeException.class, () -> coll.moveToEnd(new TestElement(4, 4)));
    }