/** * Consumes (removes) <tt>numberOfItems</tt> at once. * <p> * Removes the given number of items from the stream. * * @param numberOfItems the number of items to remove */ public void consume(int numberOfItems) { if (numberOfItems < 0) { throw new IllegalArgumentException("numberOfItems < 0"); } while (numberOfItems-- > 0) { if (!itemBuffer.isEmpty()) { itemBuffer.remove(0); } else { if (endReached) { return; } T item = fetch(); if (item == null) { endReached = true; } } } }
/** * Consumes (removes) <tt>numberOfItems</tt> at once. * <p> * Removes the given number of items from the stream. * * @param numberOfItems the number of items to remove */ public void consume(int numberOfItems) { if (numberOfItems < 0) { throw new IllegalArgumentException("numberOfItems < 0"); } while (numberOfItems-- > 0) { if (!itemBuffer.isEmpty()) { itemBuffer.remove(0); } else { if (endReached) { return; } T item = fetch(); if (item == null) { endReached = true; } } } }
T item = fetch(); if (item != null) { itemBuffer.add(item);
T item = fetch(); if (item != null) { itemBuffer.add(item);