* container, starting with the item id at <code>startIndex</code>. <br>
* <br>
*
- * Implementations should return the exact number of item ids given by
- * <code>numberOfItems</code>. The returned list must hence contain all
- * of the item ids from the range: <br>
+ * Implementations should return at most <code>numberOfItems</code> item
+ * ids, but can contain less if the container has less items than
+ * required to fulfill the request. The returned list must hence contain
+ * all of the item ids from the range: <br>
* <br>
* <code>startIndex</code> to
- * <code>startIndex + (numberOfItems-1)</code>. <br>
- * <br>
- *
- * The returned list must contain all of the requested item ids or throw
- * a {@link RangeOutOfContainerBoundsException} to indicate that the
- * container does not contain all the requested item ids.<br>
+ * <code>max(startIndex + (numberOfItems-1), container.size()-1)</code>. <br>
* <br>
* For quick migration to new API see:
* {@link ContainerHelpers#getItemIdsUsingGetIdByIndex(int, int, Indexed)}
* <br>
* <b>Throws:</b> {@link IllegalArgumentException} if
* <code>numberOfItems</code> is < 0 <br>
- * <b>Throws:</b> {@link RangeOutOfContainerBoundsException} if all of
- * the requested item ids cannot be fetched <br>
* <b>Throws:</b> {@link IndexOutOfBoundsException} if
* <code>startIndex</code> is outside the range of the container. (i.e.
* <code>startIndex < 0 || container.size()-1 < startIndex</code>)
* @param numberOfItems
* the number of consecutive item ids to get from the given
* start index, must be >= 0
- * @return List containing all of the requested item ids or empty list
- * if <code>numberOfItems</code> == 0; not null
+ * @return List containing the requested item ids or empty list if
+ * <code>numberOfItems</code> == 0; not null
*
* @since 7.0
*/
int endIndex = startIndex + numberOfIds;
if (endIndex > container.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, container.size());
+ endIndex = container.size();
}
ArrayList<Object> rangeOfIds = new ArrayList<Object>();
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;
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());
+ endIndex = getVisibleItemIds().size();
}
return Collections.unmodifiableList(getVisibleItemIds().subList(
import java.util.List;
+import junit.framework.Assert;
+
import com.vaadin.data.Item;
-import com.vaadin.data.RangeOutOfContainerBoundsException;
public class TestIndexedContainer extends AbstractInMemoryContainerTest {
public void testGetItemIdsRangeIndexOutOfBoundsDueToSizeChange() {
IndexedContainer ic = new IndexedContainer();
ic.addItem(new Object());
- try {
- ic.getItemIds(0, 10);
- fail("Container returned items when the range was >> container size");
- } catch (RangeOutOfContainerBoundsException e) {
- // This is expected...
- assertTrue(e.isAdditionalParametersSet());
- assertEquals(0, e.getStartIndex());
- assertEquals(10, e.getNumberOfIds());
- assertEquals(1, e.getContainerCurrentSize());
-
- } catch (IndexOutOfBoundsException e) {
- fail("Container threw wrong exception when the range exceeded container size... ");
- } catch (Exception e) {
- // Should not happen!
- fail("Container threw unspecified exception when fetching a range of items and the range started from -1");
- }
+ Assert.assertEquals(
+ "Container returned too many items when the range was >> container size",
+ 1, ic.getItemIds(0, 10).size());
}
// Ticket 8028