diff options
Diffstat (limited to 'server/src/com/vaadin/data/util/AbstractInMemoryContainer.java')
-rw-r--r-- | server/src/com/vaadin/data/util/AbstractInMemoryContainer.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java index 6eea9cb421..dbfcad3982 100644 --- a/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java +++ b/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java @@ -26,6 +26,7 @@ import java.util.Set; import com.vaadin.data.Container; import com.vaadin.data.Container.ItemSetChangeNotifier; import com.vaadin.data.Item; +import com.vaadin.data.RangeOutOfContainerBoundsException; import com.vaadin.data.util.filter.SimpleStringFilter; import com.vaadin.data.util.filter.UnsupportedFilterException; @@ -251,6 +252,45 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE } @Override + public List<ITEMIDTYPE> getItemIds(int startIndex, int numberOfIds) { + if (startIndex < 0) { + throw new IndexOutOfBoundsException( + "Start index cannot be negative! startIndex=" + startIndex); + } + + if (startIndex > getVisibleItemIds().size()) { + throw new IndexOutOfBoundsException( + "Start index exceeds container size! startIndex=" + + startIndex + " containerLastItemIndex=" + + (getVisibleItemIds().size() - 1)); + } + + if (numberOfIds < 1) { + if (numberOfIds == 0) { + return Collections.emptyList(); + } + + throw new IllegalArgumentException( + "Cannot get negative amount of items! numberOfItems=" + + numberOfIds); + } + + int endIndex = startIndex + numberOfIds; + + if (endIndex > getVisibleItemIds().size()) { + throw new RangeOutOfContainerBoundsException( + "Cannot get all requested item ids from container. " + + "Container size might have changed, recalculate numberOfIds " + + "based on the actual container size!", + startIndex, numberOfIds, getVisibleItemIds().size()); + } + + return Collections.unmodifiableList(getVisibleItemIds().subList( + startIndex, endIndex)); + + } + + @Override public int indexOfId(Object itemId) { return getVisibleItemIds().indexOf(itemId); } |