当前位置: 首页>>代码示例>>Java>>正文


Java ArrayDeque.poll方法代码示例

本文整理汇总了Java中java.util.ArrayDeque.poll方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayDeque.poll方法的具体用法?Java ArrayDeque.poll怎么用?Java ArrayDeque.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.ArrayDeque的用法示例。


在下文中一共展示了ArrayDeque.poll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: levelOrder1

import java.util.ArrayDeque; //导入方法依赖的package包/类
void levelOrder1(BinaryTreeNode btn) {
	BinaryTreeNode root = btn;
	ArrayDeque<BinaryTreeNode> queue = new ArrayDeque<BinaryTreeNode>();
	if (root == null)
		return;
	//使用offer和poll优于add和remove之处在于它们返回值可以判断成功与否,而不抛出异常
	queue.offer(root);
	while (queue.isEmpty() != true) {
		root = queue.poll();
		printNode(root);
		if (root.leftNode != null)
			queue.offer(root.leftNode);
		if (root.rightNode != null)
			queue.offer(root.rightNode);
	}
}
 
开发者ID:selfconzrr,项目名称:Tree_learning,代码行数:17,代码来源:binaryTree.java

示例2: main

import java.util.ArrayDeque; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    final String stringPath = "files/Files-and-Streams" ;
    File file = new File(stringPath);
    PrintWriter writer = new PrintWriter("files/output08.txt");

    ArrayDeque<File> queue = new ArrayDeque<>();

    queue.offer(file);
    int counter = 1;
    while (!queue.isEmpty()){
        File currentDir = queue.poll();

        File[] nestedFiles = currentDir.listFiles();
        for (File nestedFile : nestedFiles) {
            if(nestedFile.isDirectory()){
                queue.offer(nestedFile);
                counter++;
            }
        }
        System.out.println(currentDir.getName());
        writer.println(currentDir.getName());
    }
    System.out.println(counter + " folders");
    writer.println(counter + " folders");
    writer.close();
}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:27,代码来源:p08_NestedFolders.java

示例3: swapAndSerializeQueuedWrites

import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
 * Swap the two queues of DeferredSerializations and serialize everything in the queue
 * and return the resulting ByteBuffers as an array.
 * @return
 * @throws IOException
 */
final BBContainer[] swapAndSerializeQueuedWrites(final DBBPool pool) throws IOException {
    ArrayDeque<DeferredSerialization> oldlist;
    synchronized (this) {
        if (m_queuedWrites.isEmpty()) {
            return null;
        } else {
            if (m_queuedWrites == m_queuedWrites1) {
                oldlist = m_queuedWrites1;
                m_queuedWrites = m_queuedWrites2;
            }
            else {
                oldlist = m_queuedWrites2;
                m_queuedWrites = m_queuedWrites1;
            }
        }
    }
    final BBContainer results[] = new BBContainer[oldlist.size()];
    int ii = 0;
    DeferredSerialization ds = null;
    int bytesQueued = 0;
    while ((ds = oldlist.poll()) != null) {
        results[ii] = ds.serialize(pool);
        bytesQueued += results[ii].b.remaining();
        assert(results[ii] != null);
        assert(results[ii].b != null);
        ii++;
    }
    updateQueued(bytesQueued, true);
    return results;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:37,代码来源:NIOWriteStream.java

示例4: onNext

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public final void onNext(T item) {
    ArrayDeque<T> q = this.queue;
    if (q.size() == n) {
        q.poll();
    }
    q.offer(item);
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:9,代码来源:FolyamTakeLast.java

示例5: randomTick

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public int randomTick(World world, Area area, final int blockX, final int blockY, final int blockZ, int meta) {
  if (meta == 1) {
    HashSet<BlockReference> checked = new HashSet<BlockReference>();
    ArrayDeque<BlockReference> todo = new ArrayDeque<BlockReference>();
    BlockReference start = new BlockReference().setFromBlockCoordinates(blockX, blockY, blockZ);
    todo.add(start.copy().offset(-1, 0, 0));
    todo.add(start.copy().offset(1, 0, 0));
    todo.add(start.copy().offset(0, -1, 0));
    todo.add(start.copy().offset(0, 1, 0));
    todo.add(start.copy().offset(0, 0, -1));
    todo.add(start.copy().offset(0, 0, 1));
    while (!todo.isEmpty()) {
      BlockReference poll = todo.poll();
      int x = poll.blockX, y = poll.blockY, z = poll.blockZ;
      Area a = area;
      if (x < 0 || x >= Area.SIZE_BLOCKS || z < 0 || z >= Area.SIZE_BLOCKS) {
        a = area.neighbourBlockCoordinates(x + area.minBlockX, z + area.minBlockZ);
        if (a == null) return meta; //otherwise leaves may decay if area containing log is not loaded
        x = x + area.minBlockX - a.minBlockX;
        z = z + area.minBlockZ - a.minBlockZ;
      }
      if (y < 0 || y > a.maxY) continue;
      Block b = a.getBlock(x, y, z);
      if (b == Blocks.leaves) {
        add(checked, todo, start, poll, -1, 0, 0);
        add(checked, todo, start, poll, 1, 0, 0);
        add(checked, todo, start, poll, 0, -1, 0);
        add(checked, todo, start, poll, 0, 1, 0);
        add(checked, todo, start, poll, 0, 0, -1);
        add(checked, todo, start, poll, 0, 0, 1);
      } else if (b == Blocks.log) {
        return meta;
      }
    }
    area.setBlock(null, blockX, blockY, blockZ, 0);
    dropItems(Cubes.getServer().world, blockX + area.minBlockX, blockY, blockZ + area.minBlockZ, meta);
  }
  return meta;
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:41,代码来源:BlockLeaves.java

示例6: allocateFloatingNode

import java.util.ArrayDeque; //导入方法依赖的package包/类
private Node allocateFloatingNode(NodeClass<?> nodeClass) {
    ArrayDeque<? extends Node> cachedNodes = reusableFloatingNodes.get(nodeClass);
    if (cachedNodes != null) {
        Node node = cachedNodes.poll();
        if (node != null) {
            return node;
        }
    }
    return nodeClass.allocateInstance();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:GraphDecoder.java

示例7: randomTick

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public int randomTick(World world, Area area, final int blockX, final int blockY, final int blockZ, int meta) {
	if (meta == 1) {
		HashSet<BlockReference> checked = new HashSet<BlockReference>();
		ArrayDeque<BlockReference> todo = new ArrayDeque<BlockReference>();
		BlockReference start = new BlockReference().setFromBlockCoordinates(blockX, blockY, blockZ);
		todo.add(start.copy().offset(-1, 0, 0));
		todo.add(start.copy().offset(1, 0, 0));
		todo.add(start.copy().offset(0, -1, 0));
		todo.add(start.copy().offset(0, 1, 0));
		todo.add(start.copy().offset(0, 0, -1));
		todo.add(start.copy().offset(0, 0, 1));
		while (!todo.isEmpty()) {
			BlockReference poll = todo.poll();
			int x = poll.blockX;
			int y = poll.blockY;
			int z = poll.blockZ;
			Area a = area;

			randomTickMeta(x, z, a, area, meta);

			if (y < 0 || y > a.maxY) {
				continue;
			}
			Block b = a.getBlock(x, y, z);
			if (b == Blocks.leaves) {
				add(checked, todo, start, poll, -1, 0, 0);
				add(checked, todo, start, poll, 1, 0, 0);
				add(checked, todo, start, poll, 0, -1, 0);
				add(checked, todo, start, poll, 0, 1, 0);
				add(checked, todo, start, poll, 0, 0, -1);
				add(checked, todo, start, poll, 0, 0, 1);
			} else if (b == Blocks.log) {
				return meta;
			}
		}
		area.setBlock(null, blockX, blockY, blockZ, 0);
		dropItems(Cubes.getServer().world, blockX + area.minBlockX, blockY, blockZ + area.minBlockZ, meta);
	}
	return meta;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:42,代码来源:BlockLeaves.java


注:本文中的java.util.ArrayDeque.poll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。