本文整理汇总了Java中java.util.Queue.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java Queue.iterator方法的具体用法?Java Queue.iterator怎么用?Java Queue.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Queue
的用法示例。
在下文中一共展示了Queue.iterator方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tickParticleList
import java.util.Queue; //导入方法依赖的package包/类
private void tickParticleList(Queue<Particle> p_187240_1_)
{
if (!p_187240_1_.isEmpty())
{
Iterator<Particle> iterator = p_187240_1_.iterator();
while (iterator.hasNext())
{
Particle particle = (Particle)iterator.next();
this.tickParticle(particle);
if (!particle.isAlive())
{
iterator.remove();
}
}
}
}
示例2: printTree
import java.util.Queue; //导入方法依赖的package包/类
public void printTree() {
Queue<Expression> currentLevel = new LinkedList<Expression>();
Queue<Expression> nextLevel = new LinkedList<Expression>();
currentLevel.add(root);
while (!currentLevel.isEmpty()) {
Iterator<Expression> iter = currentLevel.iterator();
while (iter.hasNext()) {
Expression currentNode = iter.next();
if (currentNode.getLeftChild() != null) {
nextLevel.add(currentNode.getLeftChild());
}
if (currentNode.getRightChild() != null) {
nextLevel.add(currentNode.getRightChild());
}
System.out.print(currentNode.getType() + " ");
}
System.out.println();
currentLevel = nextLevel;
nextLevel = new LinkedList<Expression>();
}
System.out.println("==================");
}
示例3: getLastElement
import java.util.Queue; //导入方法依赖的package包/类
/**
* Returns the last element in a {@link Queue}.
*
* @param queue a {@link Queue}
* @param <T> the type of the elements in the {@link Queue}
* @return the last element in a {@link Queue}
*/
private <T> @Nullable T getLastElement(final Queue<T> queue) {
final Iterator<T> iterator = queue.iterator();
T last = null;
while (iterator.hasNext()) {
last = iterator.next();
}
return last;
}
示例4: checkIterator
import java.util.Queue; //导入方法依赖的package包/类
private void checkIterator(Queue<Integer> set, Queue<Integer> setCopy) {
for (Iterator<Integer> iterator = set.iterator(); iterator.hasNext();) {
Integer value = iterator.next();
if (!setCopy.remove(value)) {
Assert.fail();
}
}
Assert.assertEquals(0, setCopy.size());
}
示例5: plotEvents
import java.util.Queue; //导入方法依赖的package包/类
/** Plot a list of events read from a file */
public static void plotEvents(Queue<Spike> evts)
{
Iterator<Spike> itr=evts.iterator();
XYSeries data=new XYSeries("Size");
for (int i=0; i<evts.size(); i++)
{ Spike ev=itr.next();
data.add((float)ev.time,ev.addr);
}
XYDataset raster = new XYSeriesCollection(data);
XYDotRenderer renderer = new XYDotRenderer();
renderer.setDotWidth(2);
renderer.setDotHeight(2);
XYPlot subplot1 = new XYPlot(raster, null, new NumberAxis("address"), renderer);
XYPlot subplot2 = new XYPlot(raster, null, new NumberAxis("address"), renderer);
CombinedXYPlot plot = new CombinedXYPlot(new NumberAxis("Time"),new NumberAxis("Address"));
plot.add(subplot1, 1);
plot.add(subplot2, 1);
JFreeChart chart= new JFreeChart("Raster",JFreeChart.DEFAULT_TITLE_FONT, plot,true);
JFrame fr=new JFrame();
fr.getContentPane().add(new ChartPanel(chart));
fr.setSize(1200,1000);
fr.setVisible(true);
}
示例6: checkIterationSanity
import java.util.Queue; //导入方法依赖的package包/类
void checkIterationSanity(Queue q) {
if (rnd.nextBoolean())
return;
int size = q.size();
Object[] a = q.toArray();
Object[] b = new Object[size+2];
Arrays.fill(b, Boolean.TRUE);
Object[] c = q.toArray(b);
assertEquals(a.length, size);
assertSame(b, c);
assertNull(b[size]);
assertSame(b[size+1], Boolean.TRUE);
assertEquals(q.toString(), Arrays.toString(a));
Integer[] xx = null, yy = null;
if (size > 0) {
xx = new Integer[size - 1];
Arrays.fill(xx, 42);
yy = ((Queue<Integer>)q).toArray(xx);
for (Integer zz : xx)
assertEquals(42, (int) zz);
}
Iterator it = q.iterator();
for (int i = 0; i < size; i++) {
if (rnd.nextBoolean()) assertTrue(it.hasNext());
Object x = it.next();
assertSame(x, a[i]);
assertSame(x, b[i]);
if (xx != null) assertSame(x, yy[i]);
}
if (rnd.nextBoolean()) assertTrue(!it.hasNext());
}
示例7: main
import java.util.Queue; //导入方法依赖的package包/类
public static void main(String[] args) {
int n = 10000;
if (args.length > 0)
n = Integer.parseInt(args[0]);
List<Integer> sorted = new ArrayList<>(n);
for (int i = 0; i < n; i++)
sorted.add(new Integer(i));
List<Integer> shuffled = new ArrayList<>(sorted);
Collections.shuffle(shuffled);
Queue<Integer> pq = new PriorityQueue<>(n, new MyComparator());
for (Iterator<Integer> i = shuffled.iterator(); i.hasNext(); )
pq.add(i.next());
List<Integer> recons = new ArrayList<>();
while (!pq.isEmpty())
recons.add(pq.remove());
if (!recons.equals(sorted))
throw new RuntimeException("Sort test failed");
recons.clear();
pq = new PriorityQueue<>(shuffled);
while (!pq.isEmpty())
recons.add(pq.remove());
if (!recons.equals(sorted))
throw new RuntimeException("Sort test failed");
// Remove all odd elements from queue
pq = new PriorityQueue<>(shuffled);
for (Iterator<Integer> i = pq.iterator(); i.hasNext(); )
if ((i.next().intValue() & 1) == 1)
i.remove();
recons.clear();
while (!pq.isEmpty())
recons.add(pq.remove());
for (Iterator<Integer> i = sorted.iterator(); i.hasNext(); )
if ((i.next().intValue() & 1) == 1)
i.remove();
if (!recons.equals(sorted))
throw new RuntimeException("Iterator remove test failed.");
}
示例8: findMatchingEntry
import java.util.Queue; //导入方法依赖的package包/类
@SuppressFBWarnings(value = "NP_OPTIONAL_RETURN_NULL",
justification = "Returning null Optional is documented in the API contract.")
private static Optional<TransmittedConnectionEntry> findMatchingEntry(final Queue<? extends ConnectionEntry> queue,
final ResponseEnvelope<?> envelope) {
// Try to find the request in a queue. Responses may legally come back in a different order, hence we need
// to use an iterator
final Iterator<? extends ConnectionEntry> it = queue.iterator();
while (it.hasNext()) {
final ConnectionEntry e = it.next();
final Request<?, ?> request = e.getRequest();
final Response<?, ?> response = envelope.getMessage();
// First check for matching target, or move to next entry
if (!request.getTarget().equals(response.getTarget())) {
continue;
}
// Sanity-check logical sequence, ignore any out-of-order messages
if (request.getSequence() != response.getSequence()) {
LOG.debug("Expecting sequence {}, ignoring response {}", request.getSequence(), envelope);
return Optional.empty();
}
// Check if the entry has (ever) been transmitted
if (!(e instanceof TransmittedConnectionEntry)) {
return Optional.empty();
}
final TransmittedConnectionEntry te = (TransmittedConnectionEntry) e;
// Now check session match
if (envelope.getSessionId() != te.getSessionId()) {
LOG.debug("Expecting session {}, ignoring response {}", te.getSessionId(), envelope);
return Optional.empty();
}
if (envelope.getTxSequence() != te.getTxSequence()) {
LOG.warn("Expecting txSequence {}, ignoring response {}", te.getTxSequence(), envelope);
return Optional.empty();
}
LOG.debug("Completing request {} with {}", request, envelope);
it.remove();
return Optional.of(te);
}
return null;
}