public void testCantRemoveAfterPeek() { List<String> list = Lists.newArrayList("A", "B", "C"); Iterator<String> iterator = list.iterator(); PeekingIterator<?> peekingIterator = Iterators.peekingIterator(iterator); assertEquals("A", peekingIterator.next()); assertEquals("B", peekingIterator.peek()); /* Should complain on attempt to remove() after peek(). */ try { peekingIterator.remove(); fail("remove() should throw IllegalStateException after a peek()"); } catch (IllegalStateException e) { /* expected */ } assertEquals( "After remove() throws exception, peek should still be ok", "B", peekingIterator.peek()); /* Should recover to be able to remove() after next(). */ assertEquals("B", peekingIterator.next()); peekingIterator.remove(); assertEquals("Should have removed an element", 2, list.size()); assertFalse("Second element should be gone", list.contains("B")); }
@Override public void remove() { iterator.remove(); }
@Override public void remove() { iterator.remove(); }
@Override public void remove() { iterator.remove(); }
protected void confirmDeletesFromReplication( Iterator<Entry<String,Status>> replicationNeededIterator, Iterator<Entry<String,String>> candidateMapIterator) { PeekingIterator<Entry<String,Status>> pendingReplication = Iterators .peekingIterator(replicationNeededIterator); PeekingIterator<Entry<String,String>> candidates = Iterators .peekingIterator(candidateMapIterator); while (pendingReplication.hasNext() && candidates.hasNext()) { Entry<String,Status> pendingReplica = pendingReplication.peek(); Entry<String,String> candidate = candidates.peek(); String filePendingReplication = pendingReplica.getKey(); String fullPathCandidate = candidate.getValue(); int comparison = filePendingReplication.compareTo(fullPathCandidate); if (comparison < 0) { pendingReplication.next(); } else if (comparison > 1) { candidates.next(); } else { // We want to advance both, and try to delete the candidate if we can candidates.next(); pendingReplication.next(); // We cannot delete a file if it is still needed for replication if (!StatusUtil.isSafeForRemoval(pendingReplica.getValue())) { // If it must be replicated, we must remove it from the candidate set to prevent deletion candidates.remove(); } } } }
@Override public void remove() { iterator.remove(); }
@Override public void remove() { iter.remove(); }
@Override public void remove() { iter.remove(); }
@Override public void remove() { iterator.remove(); }
@Override public void remove() { iterator.remove(); }
@Override public void remove() { peeking.remove(); }
private void _ensureNextEventIsConsumable() { if (delegatePeekingIterator.hasNext()) { Object nextEvent = delegatePeekingIterator.peek(); if (!EventBusUtils.applyFilters(nextEvent, filters, stats.filterStats, "subscriber: " + delegateSubscriber.toGenericString(), LOGGER)) { // If next event is not consumable i.e. filtered, remove and see next. delegatePeekingIterator.next(); delegatePeekingIterator.remove(); _ensureNextEventIsConsumable(); } } } }
protected void confirmDeletesFromReplication( Iterator<Entry<String,Status>> replicationNeededIterator, Iterator<Entry<String,String>> candidateMapIterator) { PeekingIterator<Entry<String,Status>> pendingReplication = Iterators .peekingIterator(replicationNeededIterator); PeekingIterator<Entry<String,String>> candidates = Iterators .peekingIterator(candidateMapIterator); while (pendingReplication.hasNext() && candidates.hasNext()) { Entry<String,Status> pendingReplica = pendingReplication.peek(); Entry<String,String> candidate = candidates.peek(); String filePendingReplication = pendingReplica.getKey(); String fullPathCandidate = candidate.getValue(); int comparison = filePendingReplication.compareTo(fullPathCandidate); if (comparison < 0) { pendingReplication.next(); } else if (comparison > 1) { candidates.next(); } else { // We want to advance both, and try to delete the candidate if we can candidates.next(); pendingReplication.next(); // We cannot delete a file if it is still needed for replication if (!StatusUtil.isSafeForRemoval(pendingReplica.getValue())) { // If it must be replicated, we must remove it from the candidate set to prevent deletion candidates.remove(); } } } }
public void testCantRemoveAfterPeek() { List<String> list = Lists.newArrayList("A", "B", "C"); Iterator<String> iterator = list.iterator(); PeekingIterator<?> peekingIterator = Iterators.peekingIterator(iterator); assertEquals("A", peekingIterator.next()); assertEquals("B", peekingIterator.peek()); /* Should complain on attempt to remove() after peek(). */ try { peekingIterator.remove(); fail("remove() should throw IllegalStateException after a peek()"); } catch (IllegalStateException e) { /* expected */ } assertEquals("After remove() throws exception, peek should still be ok", "B", peekingIterator.peek()); /* Should recover to be able to remove() after next(). */ assertEquals("B", peekingIterator.next()); peekingIterator.remove(); assertEquals("Should have removed an element", 2, list.size()); assertFalse("Second element should be gone", list.contains("B")); }
private void updateForRow(PeekingIterator<PartitionUpdate.CounterMark> markIter, Row row, ColumnFamilyStore cfs) { int cmp = 0; // If the mark is before the row, we have no value for this mark, just consume it while (markIter.hasNext() && (cmp = compare(markIter.peek().clustering(), row.clustering(), cfs)) < 0) markIter.next(); if (!markIter.hasNext()) return; while (cmp == 0) { PartitionUpdate.CounterMark mark = markIter.next(); Cell cell = mark.path() == null ? row.getCell(mark.column()) : row.getCell(mark.column(), mark.path()); if (cell != null) { updateWithCurrentValue(mark, CounterContext.instance().getLocalClockAndCount(cell.value()), cfs); markIter.remove(); } if (!markIter.hasNext()) return; cmp = compare(markIter.peek().clustering(), row.clustering(), cfs); } }
private void updateForRow(PeekingIterator<PartitionUpdate.CounterMark> markIter, Row row, ColumnFamilyStore cfs) { int cmp = 0; // If the mark is before the row, we have no value for this mark, just consume it while (markIter.hasNext() && (cmp = compare(markIter.peek().clustering(), row.clustering(), cfs)) < 0) markIter.next(); if (!markIter.hasNext()) return; while (cmp == 0) { PartitionUpdate.CounterMark mark = markIter.next(); Cell cell = mark.path() == null ? row.getCell(mark.column()) : row.getCell(mark.column(), mark.path()); if (cell != null) { updateWithCurrentValue(mark, CounterContext.instance().getLocalClockAndCount(cell.value()), cfs); markIter.remove(); } if (!markIter.hasNext()) return; cmp = compare(markIter.peek().clustering(), row.clustering(), cfs); } }