當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。