List of usage examples for java.util LinkedList removeLast
public E removeLast()
From source file:org.movsim.simulator.roadnetwork.RoadSegment.java
private static double travelTimeInRange(double begin, double end, double maxRoadSpeed, LinkedList<Vehicle> vehicles) { int count = 0; double sumSpeed = 0; while (!vehicles.isEmpty() && vehicles.getLast().getFrontPosition() < end) { Vehicle veh = vehicles.removeLast(); sumSpeed += Math.max(veh.getSpeed(), MIN_SPEED_TT); count++;// ww w.j av a2s. c o m } double avgSpeed = (count == 0) ? maxRoadSpeed : sumSpeed / count; return (end - begin) / avgSpeed; }
From source file:ome.security.basic.CurrentDetails.java
public int logout() { LinkedList<BasicEventContext> list = list(); BasicEventContext bec = list.removeLast(); bec.getStats().methodOut();/*from w ww. j a va 2 s . c om*/ if (log.isDebugEnabled()) { log.debug("Logged out: " + bec); } return list.size(); }
From source file:org.openmrs.module.kenyaemr.page.controller.MedicalChartViewPatientPageController.java
/** * Remember that this patient was just viewed *//*from w w w.j av a 2 s . com*/ private void recentlyViewed(Patient patient, Session session) { LinkedList<Integer> recent = session.getAttribute("kenyaemr.medicalChart.recentlyViewedPatients", LinkedList.class); if (recent == null) { recent = new LinkedList<Integer>(); session.setAttribute("kenyaemr.medicalChart.recentlyViewedPatients", recent); } recent.removeFirstOccurrence(patient.getPatientId()); recent.add(0, patient.getPatientId()); while (recent.size() > 10) recent.removeLast(); }
From source file:com.theaigames.game.warlight2.Warlight2.java
/** * Turns the game that is stored in the processor to a nice string for the visualization * @param winner : winner//from ww w . j av a 2 s. co m * @param gameView : type of view * @return : string that the visualizer can read */ private String getPlayedGame(Player winner, String gameView) { StringBuilder out = new StringBuilder(); LinkedList<MoveResult> playedGame; if (gameView.equals("player1")) playedGame = this.processor.getPlayer1PlayedGame(); else if (gameView.equals("player2")) playedGame = this.processor.getPlayer2PlayedGame(); else playedGame = this.processor.getFullPlayedGame(); playedGame.removeLast(); int roundNr = 0; for (MoveResult moveResult : playedGame) { if (moveResult != null) { if (moveResult.getMove() != null) { try { PlaceArmiesMove plm = (PlaceArmiesMove) moveResult.getMove(); out.append(plm.getString() + "\n"); } catch (Exception e) { AttackTransferMove atm = (AttackTransferMove) moveResult.getMove(); out.append(atm.getString() + "\n"); } } out.append("map " + moveResult.getMap().getMapString() + "\n"); } else { out.append("round " + roundNr + "\n"); roundNr++; } } if (winner != null) out.append(winner.getName() + " won\n"); else out.append("Nobody won\n"); return out.toString(); }
From source file:eu.uqasar.model.tree.TreeNode.java
@SuppressWarnings("unchecked") @Override//from w w w. j ava2 s .com public boolean changePositionWithNextSibling(boolean changeParents) { LinkedList<TreeNode> directSiblings = (LinkedList<TreeNode>) getMutableSiblings(); int currentIndex = directSiblings.indexOf(this); int newIndex = currentIndex + 1; if (newIndex < directSiblings.size()) { // switch currently selected node with the next one TreeNode movedNode = directSiblings.remove(currentIndex); directSiblings.add(newIndex, movedNode); getParent().setChildren(directSiblings); logger.info(String.format("Moving %s from index %s to %s", this, currentIndex, newIndex)); return true; } else if (newIndex >= directSiblings.size() && changeParents) { // add currently selected node as first entry to the next parent // sibling LinkedList<TreeNode> parentSiblings = (LinkedList<TreeNode>) this.getParent().getMutableSiblings(); int parentIndex = parentSiblings.indexOf(this.getParent()); int newParentIndex = parentIndex + 1; if (newParentIndex < parentSiblings.size()) { TreeNode oldParent = this.getParent(); LinkedList<TreeNode> oldParentChildren = oldParent.getChildren(); oldParentChildren.removeLast(); oldParent.setChildren(oldParentChildren); TreeNode newParent = parentSiblings.get(newParentIndex); logger.info(String.format("Moving %s from parent %s to %s", this, this.getParent(), newParent)); this.setParent(newParent); return true; } } return false; }
From source file:alma.acs.tmcdb.compare.TestHighLevelNodes.java
private String[] getSubNodes(DAL dal, String subnode) throws Exception { ArrayList<String> subnodes = new ArrayList<String>(); LinkedList<String> stack = new LinkedList<String>(); stack.addLast(subnode);//ww w . j a va 2s . c o m while (!stack.isEmpty()) { String parentNode = stack.removeLast().toString(); String nodes = dal.list_nodes(parentNode); if (nodes.length() > 0) { StringTokenizer tokenizer = new StringTokenizer(nodes); while (tokenizer.hasMoreTokens()) { String nodeName = tokenizer.nextToken(); if (nodeName.endsWith(".xml")) continue; String fullName = parentNode + "/" + nodeName; stack.addLast(fullName); // strip off relative path subnodes.add(fullName.substring(subnode.length() + 1)); } } } String[] retVal = new String[subnodes.size()]; subnodes.toArray(retVal); return retVal; }
From source file:org.eclipse.wb.internal.swing.model.layout.gbl.DimensionOperations.java
/** * Cuts dimensions to the size rendered by {@link GridBagLayout}.<br> * We don't analyze that there are empty columns/rows ourselves. Instead we just allow * {@link GridBagLayout} to this for us and obey it - remove {@link DimensionInfo}'s and cut * "weight" arrays./*from w ww .j a va 2s . com*/ * * @return <code>true</code> if any dimension was removed. */ boolean cutToGrid(int renderedSize) throws Exception { LinkedList<T> dimensions = getDimensions(); // cut dimensions boolean removedAnyDimension = false; while (dimensions.size() > renderedSize) { dimensions.removeLast(); removedAnyDimension = true; } // cut "weight" { ArrayInitializer initializer = getFieldArrayInitializer(m_weightField); if (initializer != null) { while (initializer.expressions().size() > renderedSize) { m_editor.removeArrayElement(initializer, initializer.expressions().size() - 1); } } } // return removedAnyDimension; }
From source file:org.mycard.net.network.Connection.java
/*** * After a send/receive failure, any pipelined requests must be * cleared back to the mRequest queue/*from w w w . j a va 2s.c o m*/ * @return true if mRequests is empty after pipe cleared */ private boolean clearPipe(LinkedList<Request> pipe) { boolean empty = true; synchronized (mRequestFeeder) { Request tReq; while (!pipe.isEmpty()) { tReq = (Request) pipe.removeLast(); mRequestFeeder.requeueRequest(tReq); empty = false; } if (empty) empty = !mRequestFeeder.haveRequest(mHost); } return empty; }
From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolatorSimple.java
@Override public float getExtrapolatedValue(double x, double y) { //duplicate points for thread safety final LinkedList<Point3d> points = new LinkedList<Point3d>(points_); //find 3 closest points and calculate value //find closest convex hull vertex final LinkedList<Integer> closestIndices = new LinkedList<Integer>(); final LinkedList<Double> closestDistances = new LinkedList<Double>(); for (int i = 0; i < points.size(); i++) { //get current distance Vector2D vertex = new Vector2D(points.get(i).x, points.get(i).y); double distance = vertex.distance(new Vector2D(x, y)); if (closestDistances.size() < 3) { closestIndices.add(i);/* ww w. j av a 2s.co m*/ closestDistances.add(distance); } else if (distance < closestDistances.get(2)) { closestIndices.removeLast(); closestDistances.removeLast(); closestIndices.add(i); closestDistances.add(distance); } //sort Collections.sort(closestIndices, new Comparator<Integer>() { public int compare(Integer left, Integer right) { return (new Double(closestDistances.get(closestIndices.indexOf(left)))) .compareTo(closestDistances.get(closestIndices.indexOf(right))); } }); Collections.sort(closestDistances); } Point3d point1 = points.get(closestIndices.get(0)); Point3d point2 = points.get(closestIndices.get(1)); Point3d point3 = points.get(closestIndices.get(2)); Vector3D v1 = new Vector3D(point1.x, point1.y, point1.z); Vector3D v2 = new Vector3D(point2.x, point2.y, point2.z); Vector3D v3 = new Vector3D(point3.x, point3.y, point3.z); Plane plane = new Plane(v1, v2, v3, TOLERANCE); //intersetion of vertical line at these x+y values with plane gives point in plane Vector3D pointInPlane = plane .intersection(new Line(new Vector3D(x, y, 0), new Vector3D(x, y, 1), TOLERANCE)); float zVal = (float) pointInPlane.getZ(); return zVal; }
From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java
private void updateChildren(Node node, JsonNode jsonNode, VersionableChanges changes) throws RepositoryException { Session session = node.getSession(); // Get the existing children ... Map<String, Node> existingChildNames = new LinkedHashMap<>(); List<String> existingChildrenToUpdate = new ArrayList<>(); NodeIterator childIter = node.getNodes(); while (childIter.hasNext()) { Node child = childIter.nextNode(); String childName = nameOf(child); existingChildNames.put(childName, child); existingChildrenToUpdate.add(childName); }/*w w w . j av a2s . c o m*/ //keep track of the old/new order of children to be able to perform reorderings List<String> newChildrenToUpdate = new ArrayList<>(); List<JSONChild> children = getChildren(jsonNode); for (JSONChild jsonChild : children) { String childName = jsonChild.getNameWithSNS(); JsonNode child = jsonChild.getBody(); // Find the existing node ... if (node.hasNode(childName)) { // The node exists, so get it and update it ... Node childNode = node.getNode(childName); String childNodeName = nameOf(childNode); newChildrenToUpdate.add(childNodeName); updateNode(childNode, child, changes); existingChildNames.remove(childNodeName); } else { //try to see if the child name is actually an identifier try { Node childNode = session.getNodeByIdentifier(childName); String childNodeName = nameOf(childNode); if (childNode.getParent().getIdentifier().equals(node.getIdentifier())) { //this is an existing child of the current node, referenced via an identifier newChildrenToUpdate.add(childNodeName); updateNode(childNode, child, changes); existingChildNames.remove(childNodeName); } else { //this is a child belonging to another node if (childNode.isNodeType("mix:shareable")) { //if it's a shared node, we can't clone it because clone is not a session-scoped operation logger.warn( "The node {0} with the id {1} is a shared node belonging to another parent. It cannot be changed via the update operation", childNode.getPath(), childNode.getIdentifier()); } else { //move the node into this parent session.move(childNode.getPath(), node.getPath() + "/" + childNodeName); } } } catch (ItemNotFoundException e) { //the child name is not a valid identifier, so treat it as a new child addNode(node, childName, child); } } } // Remove the children in reverse order (starting with the last child to be removed) ... LinkedList<Node> childNodes = new LinkedList<Node>(existingChildNames.values()); while (!childNodes.isEmpty()) { Node child = childNodes.removeLast(); existingChildrenToUpdate.remove(child.getIdentifier()); child.remove(); } // Do any necessary reorderings if (newChildrenToUpdate.equals(existingChildrenToUpdate)) { //no order changes exist return; } for (int i = 0; i < newChildrenToUpdate.size() - 1; i++) { String startNodeName = newChildrenToUpdate.get(i); int startNodeOriginalPosition = existingChildrenToUpdate.indexOf(startNodeName); assert startNodeOriginalPosition != -1; for (int j = i + 1; j < newChildrenToUpdate.size(); j++) { String nodeName = newChildrenToUpdate.get(j); int nodeOriginalPosition = existingChildrenToUpdate.indexOf(nodeName); assert nodeOriginalPosition != -1; if (startNodeOriginalPosition > nodeOriginalPosition) { //the start node should be moved *before* this node node.orderBefore(startNodeName, nodeName); } } } }