ListItem implements ListContainer { public int getIndex() { Node firstNode = listItemElement.getParentNode().getFirstChild(); int i = 0; while (firstNode != null) { if (firstNode instanceof TextListItemElement) { if (firstNode == listItemElement) { break; } else { i++; } } firstNode = firstNode.getNextSibling(); } return i; } ListItem(TextListItemElement element);   ListItem(TextListItemElement element, String content); TextListItemElement getOdfElement(); String getTextContent(); void setTextContent(String content); void remove(); Integer getStartNumber(); void setStartNumber(Integer number); String getNumberFormat(); void setNumberFormat(String format); int getIndex(); List getOwnerList(); @Override String toString(); OdfElement getListContainerElement(); List addList(); List addList(ListDecorator decorator); void clearList(); Iterator<List> getListIterator(); boolean removeList(List list);  }
@Test public void testGetIndex() { try { TextDocument odtdoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities .getTestResourceAsStream(SAMPLE_LIST_DOCUMENT)); Iterator<List> listIterator = odtdoc.getListIterator(); if (listIterator.hasNext()) { List list = listIterator.next(); java.util.List<ListItem> items = list.getItems(); int i = 0; for (ListItem item : items) { Assert.assertEquals(i, item.getIndex()); i++; } } else { Assert.fail("list iterate fail."); } } catch (Exception e) { Logger.getLogger(ListItemTest.class.getName()).log(Level.SEVERE, null, e); Assert.fail(e.getMessage()); } }