Coverage Summary for Class: ConsumingQueueIterator (com.google.common.collect)

Class Class, % Method, % Line, %
ConsumingQueueIterator 0% (0/1) 0% (0/3) 0% (0/6)


1 /* 2  * Copyright (C) 2015 The Guava Authors 3  * 4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5  * in compliance with the License. You may obtain a copy of the License at 6  * 7  * http://www.apache.org/licenses/LICENSE-2.0 8  * 9  * Unless required by applicable law or agreed to in writing, software distributed under the License 10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11  * or implied. See the License for the specific language governing permissions and limitations under 12  * the License. 13  */ 14  15 package com.google.common.collect; 16  17 import static com.google.common.base.Preconditions.checkNotNull; 18  19 import com.google.common.annotations.GwtCompatible; 20 import java.util.ArrayDeque; 21 import java.util.Collections; 22 import java.util.Queue; 23  24 /** 25  * An Iterator implementation which draws elements from a queue, removing them from the queue as it 26  * iterates. 27  */ 28 @GwtCompatible 29 class ConsumingQueueIterator<T> extends AbstractIterator<T> { 30  private final Queue<T> queue; 31  32  ConsumingQueueIterator(T... elements) { 33  this.queue = new ArrayDeque<T>(elements.length); 34  Collections.addAll(queue, elements); 35  } 36  37  ConsumingQueueIterator(Queue<T> queue) { 38  this.queue = checkNotNull(queue); 39  } 40  41  @Override 42  public T computeNext() { 43  return queue.isEmpty() ? endOfData() : queue.remove(); 44  } 45 }