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


Java LinkedList.poll方法代码示例

本文整理汇总了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()) ;
        }
    }
}
 
开发者ID:crossoverJie,项目名称:Java-Interview,代码行数:27,代码来源:BinaryNode.java

示例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;
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:30,代码来源:PowerSet.java

示例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;
}
 
开发者ID:CMPUT301F17T29,项目名称:HabitUp,代码行数:25,代码来源:HabitUpController.java

示例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;
}
 
开发者ID:jsidrach,项目名称:xquery-engine,代码行数:20,代码来源:XPathEvaluator.java

示例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;
}
 
开发者ID:xy1m,项目名称:PlayGround,代码行数:17,代码来源:Q3_03_SetOfStacks.java

示例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());
        }
    }
}
 
开发者ID:mcr222,项目名称:pass_the_bomb,代码行数:26,代码来源:BluetoothServices.java

示例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;
  }
 
开发者ID:olehmberg,项目名称:winter,代码行数:26,代码来源:FileUtils.java

示例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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:WaypointConstraint.java

示例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();
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:15,代码来源:CommandInjection.java

示例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();
  }
 
开发者ID:reddr,项目名称:LibScout,代码行数:32,代码来源:HashTree.java

示例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);
    }
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:AssignmentCreator.java

示例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;
}
 
开发者ID:jm-organization,项目名称:connor41-etfuturum2,代码行数:38,代码来源:Sponge.java

示例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;
}
 
开发者ID:Idrinths-Stellaris-Mods,项目名称:Mod-Tools,代码行数:9,代码来源:ApplyPatchFile.java

示例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)));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:LinkedListTest.java


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