本文整理匯總了Java中java.util.LinkedList.poll方法的典型用法代碼示例。如果您正苦於以下問題:Java LinkedList.poll方法的具體用法?Java LinkedList.poll怎麽用?Java LinkedList.poll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.LinkedList
的用法示例。
在下文中一共展示了LinkedList.poll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: levelIterator
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* 二叉樹的層序遍曆 借助於隊列來實現 借助隊列的先進先出的特性
*
* 首先將根節點入隊列 然後遍曆隊列。
* 首先將根節點打印出來,接著判斷左節點是否為空 不為空則加入隊列
* @param node
*/
public void levelIterator(BinaryNode node){
LinkedList<BinaryNode> queue = new LinkedList<>() ;
//先將根節點入隊
queue.offer(node) ;
BinaryNode current ;
while (!queue.isEmpty()){
current = queue.poll();
System.out.print(current.data+"--->");
if (current.getLeft() != null){
queue.offer(current.getLeft()) ;
}
if (current.getRight() != null){
queue.offer(current.getRight()) ;
}
}
}
示例2: computePowerSet
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* Implements a simple power set computer
* (the sets are made of objects)
*/
public static LinkedList<LinkedList<Object>> computePowerSet(LinkedList<Object> v) {
/**
* Computes the power set of a set (represented as a list of objects)
*/
LinkedList<LinkedList<Object>> res = new LinkedList<LinkedList<Object>>();
if (v.isEmpty()) {
res.add(new LinkedList<Object>());
}
else {
Object x = v.poll();
LinkedList<LinkedList<Object>> y = computePowerSet(v);
Iterator<LinkedList<Object>> i = y.iterator();
while (i.hasNext()) {
LinkedList<Object> lo = i.next();
// to be checked: copy constructor:
LinkedList<Object> lo2= new LinkedList<Object>(lo);
lo2.add(x);
res.add(lo);
res.add(lo2);
}
}
return res;
}
示例3: executeOldCommands
import java.util.LinkedList; //導入方法依賴的package包/類
/**
*Updates the local user model and ES based on a queue stored in local data
*/
static public int executeOldCommands(LinkedList<HabitEventCommand> oldQueue,Context ctx){
UserAccount currentUser = HabitUpApplication.getCurrentUser();
HabitEventCommand hec = oldQueue.poll();
while (hec!=null) {
Habit habit = currentUser.getHabitList().getHabit(hec.getHabitName());
if (hec.getType().equals("add")) {
addHabitEvent(hec.getEvent(), habit, ctx);
}
else if (hec.getType().equals("delete")) {
deleteHabitEvent(hec.getEvent(), habit.getHabitName(), ctx);
}
hec = oldQueue.poll();
}
executeCommands(ctx);
return 0;
}
示例4: descendantsOrSelves
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* Returns a list containing the given nodes and all its descendants
*
* @param nodes Nodes
* @return List of node's descendants and themselves, according to the document order
*/
public static LinkedList<Node> descendantsOrSelves(List<Node> nodes) {
LinkedList<Node> queue = new LinkedList<>();
LinkedList<Node> ns = new LinkedList<>();
ns.addAll(nodes);
queue.addAll(nodes);
while (!queue.isEmpty()) {
Node c = queue.poll();
LinkedList<Node> children = XPathEvaluator.children(c);
ns.addAll(children);
queue.addAll(children);
}
return ns;
}
示例5: leftShift
import java.util.LinkedList; //導入方法依賴的package包/類
private Object leftShift(int index, boolean removeTop) {
if (index < 0 || index >= stacks.size()) throw new RuntimeException("Index out of boundary!");
LinkedList stack = stacks.get(index);
Object removed_item;
if (removeTop) removed_item = stack.pop();
else removed_item = stack.poll();
if (stack.isEmpty()) {
stacks.remove(index);
} else if (index + 1 < stack.size()) {
leftShift(index + 1, false);
}
return removed_item;
}
示例6: sendPendingMessages
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* Tries to resend all pending messages
*/
public synchronized static void sendPendingMessages() {
//TODO: mooolt important!! el bluetooth torna a demanar la vinculació dels dispositius quan surten de l'abast del bluetooth!!!
System.out.println("Sending pending messages");
System.out.println(sendingQueue.size());
PendingMessage pendingMessage;
LinkedList<PendingMessage> pendingMessages = new LinkedList<>(sendingQueue);
//TODO: important, no resending messages of unload bomb when phone is locked, since then it bomb could be
//TODO: send by the phone when resending messages (this case is protected by the fact that messages are only
//TODO: resend when user presses send button
while(!pendingMessages.isEmpty()) {
sendingQueue.poll();
pendingMessage = pendingMessages.poll();
//Have to be careful, if message is a pending unloadBomb it must still have the bomb
if(!pendingMessage.getMessageToSend().getType().equals(Message.MessageType.unloadBomb)
|| MessageProcessor.getBomb().hasBomb() ) {
System.out.println("Pending message");
System.out.println(pendingMessage.getPlayerToSend());
System.out.println(pendingMessage.getMessageToSend());
sendMessage(pendingMessage.getPlayerToSend(), pendingMessage.getMessageToSend());
}
}
}
示例7: setJumpOrderIterative
import java.util.LinkedList; //導入方法依賴的package包/類
public static void setJumpOrderIterative(PostingListNode<Integer> node) {
LinkedList<PostingListNode<Integer>> queue = new LinkedList<>();
PostingListNode<Integer> current = node;
int order = 0;
while (current != null || !queue.isEmpty()) {
if (current == null || current.data != -1) {
current = queue.poll();
}
if (current.data == -1)
current.data = order++;
if (current.next != null && current.next.data == -1)
queue.addLast(current.next);
current = current.jump;
}
}
開發者ID:gardncl,項目名稱:elements-of-programming-interviews-solutions,代碼行數:16,代碼來源:SearchPostingsList.java
示例8: listAllFiles
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* @param root
* @return returns a list of all files (including those in sub-directories)
*/
public static List<File> listAllFiles(File root) {
LinkedList<File> files = new LinkedList<>();
if(root.isDirectory()) {
LinkedList<File> toList = new LinkedList<>(Arrays.asList(root.listFiles()));
while(!toList.isEmpty()) {
File f = toList.poll();
if(f.isDirectory()) {
toList.addAll(Arrays.asList(f.listFiles()));
} else {
files.add(f);
}
}
} else {
files.add(root);
}
return files;
}
示例9: validate
import java.util.LinkedList; //導入方法依賴的package包/類
private boolean validate(Path path) {
LinkedList<DeviceId> waypoints = new LinkedList<>(this.waypoints);
DeviceId current = waypoints.poll();
// This is safe because Path class ensures the number of links are more than 0
Link firstLink = path.links().get(0);
if (firstLink.src().elementId().equals(current)) {
current = waypoints.poll();
}
for (Link link : path.links()) {
if (link.dst().elementId().equals(current)) {
current = waypoints.poll();
// Empty waypoints means passing through all waypoints in the specified order
if (current == null) {
return true;
}
}
}
return false;
}
示例10: transferThroughList
import java.util.LinkedList; //導入方法依賴的package包/類
private String transferThroughList(String in, int index) {
LinkedList<String> list = new LinkedList<String>();
list.add(System.getenv("")); // taints the list
list.clear(); // makes the list safe again
list.add(1, "xx");
list.addFirst(in); // can taint the list
list.addLast("yy");
list.push(in);
return list.element() + list.get(index) + list.getFirst() + list.getLast()
+ list.peek() + list.peekFirst() + list.peekLast() + list.poll()
+ list.pollFirst() + list.pollLast() + list.pop() + list.remove()
+ list.remove(index) + list.removeFirst() + list.removeLast()
+ list.set(index, "safe") + list.toString();
}
示例11: getStats
import java.util.LinkedList; //導入方法依賴的package包/類
public String getStats() {
StringBuilder sb = new StringBuilder();
int pNodes = 0;
int cNodes = 0;
int mNodes = 0;
LinkedList<Node> worklist = new LinkedList<Node>();
worklist.add(this);
Node curNode;
while (!worklist.isEmpty()) {
curNode = worklist.poll();
worklist.addAll(curNode.childs);
for (Node n: curNode.childs) {
if (n instanceof PackageNode)
pNodes++;
else if (n instanceof ClassNode)
cNodes++;
else if (n instanceof MethodNode)
mNodes++;
}
}
sb.append("Node stats:\n");
sb.append(Utils.INDENT + "- contains " + mNodes + " method hashes.\n");
sb.append(Utils.INDENT + "- contains " + cNodes + " clazz hashes.\n");
sb.append(Utils.INDENT + "- contains " + pNodes + " package hashes.");
return sb.toString();
}
示例12: assignLeftovers
import java.util.LinkedList; //導入方法依賴的package包/類
/**
*
* @param unassignedWorkList the work units to assign
* @param endpointIterators the endpointIterators to assign to
* @param assignMinimum wheterh to assign the minimum amount
*/
private void assignLeftovers(LinkedList<WorkEndpointListPair<T>> unassignedWorkList, Map<DrillbitEndpoint,FragIteratorWrapper> endpointIterators, boolean assignMinimum) {
outer: for (FragIteratorWrapper iteratorWrapper : endpointIterators.values()) {
while (iteratorWrapper.count < (assignMinimum ? iteratorWrapper.minCount : iteratorWrapper.maxCount)) {
WorkEndpointListPair<T> workPair = unassignedWorkList.poll();
if (workPair == null) {
break outer;
}
Integer assignment = iteratorWrapper.iter.next();
iteratorWrapper.count++;
mappings.put(assignment, workPair.work);
}
}
}
示例13: absorb
import java.util.LinkedList; //導入方法依賴的package包/類
private boolean absorb(World world, int x, int y, int z) {
LinkedList<Tuple> linkedlist = Lists.newLinkedList();
ArrayList<WorldCoord> arraylist = Lists.newArrayList();
linkedlist.add(new Tuple(new WorldCoord(x, y, z), 0));
int i = 0;
WorldCoord blockpos1;
while (!linkedlist.isEmpty()) {
Tuple tuple = linkedlist.poll();
blockpos1 = (WorldCoord) tuple.getFirst();
int j = (Integer) tuple.getSecond();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
WorldCoord blockpos2 = blockpos1.add(dir);
if (world.getBlock(blockpos2.x, blockpos2.y, blockpos2.z).getMaterial() == Material.water) {
world.setBlockToAir(blockpos2.x, blockpos2.y, blockpos2.z);
arraylist.add(blockpos2);
i++;
if (j < 6)
linkedlist.add(new Tuple(blockpos2, j + 1));
}
}
if (i > 64)
break;
}
Iterator<WorldCoord> iterator = arraylist.iterator();
while (iterator.hasNext()) {
blockpos1 = iterator.next();
world.notifyBlockOfNeighborChange(blockpos1.x, blockpos1.y, blockpos1.z, Blocks.air);
}
return i > 0;
}
示例14: ApplyPatchFile
import java.util.LinkedList; //導入方法依賴的package包/類
public ApplyPatchFile(LinkedList<Long> patches, long target) {
if(patches.isEmpty()) {
throw new IllegalArgumentException("patch list must not be empty");
}
this.patchId = patches.poll();
this.target = target;
this.next = patches;
}
示例15: testContains
import java.util.LinkedList; //導入方法依賴的package包/類
/**
* contains(x) reports true when elements added but not yet removed
*/
public void testContains() {
LinkedList q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.contains(new Integer(i)));
q.poll();
assertFalse(q.contains(new Integer(i)));
}
}