throw new IndexOutOfBoundsException("Index is negative! index="
+ index);
}
-
+ // make sure the size field is valid
+ updateCount();
if (index < size) {
if (itemIndexes.keySet().contains(index)) {
return itemIndexes.get(index);
} else {
// The index is in the added items
int offset = index - size;
- return addedItems.get(offset).getId();
+ // TODO this is very inefficient if looping - should improve
+ // getItemIds(int, int)
+ return getFilteredAddedItems().get(offset).getId();
}
}
@Override
public Object nextItemId(Object itemId) {
- return getIdByIndex(indexOfId(itemId) + 1);
+ int index = indexOfId(itemId) + 1;
+ try {
+ return getIdByIndex(index);
+ } catch (IndexOutOfBoundsException e) {
+ return null;
+ }
}
/*
container.getContainerProperty(container.getIdByIndex(3),
"NAME").getValue());
- Assert.assertNull(container.getIdByIndex(4));
+ try {
+ container.getIdByIndex(4);
+ Assert.fail("SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container");
+ } catch (IndexOutOfBoundsException e) {
+ // should throw exception - item is filtered out
+ }
Assert.assertNull(container.nextItemId(container.getIdByIndex(3)));
Assert.assertFalse(container.containsId(id2));
container.getContainerProperty(container.getIdByIndex(3),
"NAME").getValue());
- Assert.assertNull(container.getIdByIndex(4));
- Assert.assertNull(container.nextItemId(container.getIdByIndex(3)));
+ try {
+ container.getIdByIndex(4);
+ Assert.fail("SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container");
+ } catch (IndexOutOfBoundsException e) {
+ // should throw exception - item is filtered out
+ }
+ container.nextItemId(container.getIdByIndex(3));
Assert.assertFalse(container.containsId(id2));
Assert.assertFalse(container.getItemIds().contains(id2));