List of usage examples for java.util LinkedList removeLast
public E removeLast()
From source file:org.alfresco.repo.admin.patch.impl.SharedFolderPatch.java
@Override protected String applyInternal() throws Exception { StoreRef storeRef = importerBootstrap.getStoreRef(); NodeRef rootNodeRef = nodeService.getRootNode(storeRef); if (getRenamePath() != null) { List<NodeRef> results = searchService.selectNodes(rootNodeRef, getRenamePath(), null, namespaceService, false);/* w ww.ja va 2 s . c o m*/ if (results.size() > 1) { throw new PatchException(ERR_MULTIPLE_FOUND, renamePath); } else if (results.size() == 1) { if (logger.isDebugEnabled()) { logger.debug("There is an existing node in the way path:" + getRenamePath()); } // A node already exists that we must rename. NodeRef existingNodeRef = results.get(0); // get the path of the parent node e.g. company_home LinkedList<String> folderElements = new LinkedList<String>( Arrays.asList(getRenamePath().split("/"))); folderElements.removeLast(); StringBuffer parentPath = new StringBuffer(); for (String folder : folderElements) { parentPath.append("/"); parentPath.append(folder); } List<NodeRef> parentResults = searchService.selectNodes(rootNodeRef, parentPath.toString(), null, namespaceService, false); if (parentResults.size() == 1) { NodeRef parentNodeRef = parentResults.get(0); if (logger.isDebugEnabled()) { logger.debug("Found the parent node - doing a move parentNodeRef:" + parentNodeRef); } // rename the existing node nodeService.moveNode(existingNodeRef, parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "shared")); return I18NUtil.getMessage(MSG_RENAMED, renamePath); } else { // Something has gone horribly wrong if we get here - we have multiple parents, or none despite finding the node earlier throw new PatchException(ERR_MULTIPLE_FOUND, parentPath.toString()); } } } // Else run the normal GenericBootstrapPatch implementation if (logger.isDebugEnabled()) { logger.debug("Node does not already exist, Running the Generic Bootstrap Patch"); } return super.applyInternal(); }
From source file:org.sonar.plugins.cxx.coverage.BullseyeParser.java
private void collectCoverage2(String refPath, SMInputCursor folder, final Map<String, CoverageMeasuresBuilder> coverageData) throws XMLStreamException { LinkedList<String> path = new LinkedList<String>(); while (folder.getNext() != null) { String folderName = folder.getAttrValue("name"); path.add(folderName);//from w w w .j a v a 2 s .c om recTreeWalk(refPath, folder, path, coverageData); path.removeLast(); } }
From source file:org.apache.ofbiz.solr.SolrProductSearch.java
/** * Return a map of the side deep categories. *///from w w w . ja va 2 s . c o m public static Map<String, Object> getSideDeepCategories(DispatchContext dctx, Map<String, Object> context) { Map<String, Object> result; String solrIndexName = (String) context.get("indexName"); try { String catalogId = null; if (UtilValidate.isNotEmpty(context.get("catalogId"))) catalogId = (String) context.get("catalogId"); String productCategoryId = (String) context.get("productCategoryId") != null ? CategoryUtil.getCategoryNameWithTrail((String) context.get("productCategoryId"), dctx) : null; result = ServiceUtil.returnSuccess(); Map<String, List<Map<String, Object>>> catLevel = new HashMap<String, List<Map<String, Object>>>(); Debug.logInfo("productCategoryId: " + productCategoryId, module); //Add toplevel categories String[] trailElements = productCategoryId.split("/"); //iterate over actual results for (String elements : trailElements) { //catIds must be greater than 3 chars if (elements.length() > 3) { Debug.logInfo("elements: " + elements, module); String categoryPath = CategoryUtil.getCategoryNameWithTrail(elements, dctx); String[] categoryPathArray = categoryPath.split("/"); int level = Integer.parseInt(categoryPathArray[0]); String facetQuery = CategoryUtil.getFacetFilterForCategory(categoryPath, dctx); //Debug.logInfo("categoryPath: "+categoryPath + " facetQuery: "+facetQuery,module); Map<String, Object> query = SolrUtil.categoriesAvailable(catalogId, categoryPath, null, facetQuery, false, 0, 0, solrIndexName); QueryResponse cat = (QueryResponse) query.get("rows"); List<Map<String, Object>> categories = new ArrayList<Map<String, Object>>(); List<FacetField> catList = (List<FacetField>) cat.getFacetFields(); for (Iterator<FacetField> catIterator = catList.iterator(); catIterator.hasNext();) { FacetField field = (FacetField) catIterator.next(); List<Count> catL = (List<Count>) field.getValues(); if (catL != null) { for (Iterator<Count> catIter = catL.iterator(); catIter.hasNext();) { FacetField.Count f = (FacetField.Count) catIter.next(); if (f.getCount() > 0) { Map<String, Object> catMap = new HashMap<String, Object>(); LinkedList<String> iName = new LinkedList<String>(); iName.addAll(Arrays.asList(f.getName().split("/"))); //Debug.logInfo("topLevel "+topLevel,""); // int l = Integer.parseInt((String) iName.getFirst()); catMap.put("catId", iName.getLast()); iName.removeFirst(); String path = f.getName(); catMap.put("path", path); if (level > 0) { iName.removeLast(); catMap.put("parentCategory", StringUtils.join(iName, "/")); } else { catMap.put("parentCategory", null); } catMap.put("count", Long.toString(f.getCount())); categories.add(catMap); } } } } catLevel.put("menu-" + level, categories); } } result.put("categories", catLevel); result.put("numFound", (long) 0); } catch (Exception e) { result = ServiceUtil.returnError(e.toString()); result.put("numFound", (long) 0); } return result; }
From source file:org.cocos2dx.lib.Cocos2dxBitmap.java
private static String[] splitString(String content, int maxHeight, int maxWidth, Paint paint) { String[] lines = content.split("\\n"); String[] ret = null;/*from www . j av a 2 s .com*/ FontMetricsInt fm = paint.getFontMetricsInt(); int heightPerLine = (int) Math.ceil(fm.bottom - fm.top); int maxLines = maxHeight / heightPerLine; if (maxWidth != 0) { LinkedList<String> strList = new LinkedList<String>(); for (String line : lines) { /* * The width of line is exceed maxWidth, should divide it into * two or more lines. */ int lineWidth = (int) Math.ceil(paint.measureText(line)); if (lineWidth > maxWidth) { strList.addAll(divideStringWithMaxWidth(paint, line, maxWidth)); } else { strList.add(line); } /* * Should not exceed the max height; */ if (maxLines > 0 && strList.size() >= maxLines) { break; } } /* * Remove exceeding lines */ if (maxLines > 0 && strList.size() > maxLines) { while (strList.size() > maxLines) { strList.removeLast(); } } ret = new String[strList.size()]; strList.toArray(ret); } else if (maxHeight != 0 && lines.length > maxLines) { /* * Remove exceeding lines */ LinkedList<String> strList = new LinkedList<String>(); for (int i = 0; i < maxLines; i++) { strList.add(lines[i]); } ret = new String[strList.size()]; strList.toArray(ret); } else { ret = lines; } return ret; }
From source file:name.martingeisse.api.tools.LocalizationFileAction.java
private void handleFolder(File folder, LinkedList<String> packageStack) { if (!folder.isDirectory()) { throw new IllegalArgumentException("not a folder: " + folder); }// ww w . j a v a 2 s . c o m for (File file : folder.listFiles()) { if (file.isDirectory()) { packageStack.addLast(file.getName()); handleFolder(file, packageStack); packageStack.removeLast(); } else if (file.isFile()) { String fileName = file.getName(); int underscoreIndex = fileName.indexOf('_'); if (underscoreIndex != -1 && fileName.endsWith(DOT_PROPERTIES)) { String baseName = fileName.substring(0, underscoreIndex); String localeName = fileName.substring(underscoreIndex + 1, fileName.length() - DOT_PROPERTIES.length()); if (acceptLocale(localeName)) { onLocalizationFile(packageStack, file, baseName, localeName); } } } } }
From source file:eu.uqasar.model.qmtree.QMTreeNode.java
@SuppressWarnings("unchecked") @Override/*from w ww.j av a 2s .co m*/ public boolean changePositionWithNextSibling(boolean changeParents) { LinkedList<QMTreeNode> directSiblings = (LinkedList<QMTreeNode>) getMutableSiblings(); int currentIndex = directSiblings.indexOf(this); int newIndex = currentIndex + 1; if (newIndex < directSiblings.size()) { // switch currently selected node with the next one QMTreeNode 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<QMTreeNode> parentSiblings = (LinkedList<QMTreeNode>) this.getParent().getMutableSiblings(); int parentIndex = parentSiblings.indexOf(this.getParent()); int newParentIndex = parentIndex + 1; if (newParentIndex < parentSiblings.size()) { QMTreeNode oldParent = this.getParent(); LinkedList<QMTreeNode> oldParentChildren = (LinkedList) oldParent.getChildren(); oldParentChildren.removeLast(); oldParent.setChildren(oldParentChildren); QMTreeNode 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:org.kuali.rice.kew.actionrequest.service.impl.NotificationSuppression.java
/** * add metadata (a NodeState) to the route node so that if this action request is regenerated * verbatim, the notification email will suppressed (since it is a duplicate!). * @param nodeInstance where additional NodeState will be added * @param actionRequestValue /*ww w .j a v a 2 s . c o m*/ */ public void addNotificationSuppression(RouteNodeInstance nodeInstance, ActionRequestValue actionRequestValue) { // iterative depth first traversal of the action request tree LinkedList<ActionRequestValue> stack = new LinkedList<ActionRequestValue>(); // push stack.add(actionRequestValue); while (stack.size() > 0) { // pop our next action request ActionRequestValue childActionRequest = stack.removeLast(); // process this action request only if it is a leaf if (childActionRequest.getChildrenRequests() == null || childActionRequest.getChildrenRequests().size() == 0) { List<String> requestKeys = getSuppressNotifyNodeStateKeys(childActionRequest); if (requestKeys != null) for (String requestKey : requestKeys) { if (nodeInstance.getNodeState(requestKey) == null) { // only add once NodeState ns = new NodeState(); ns.setKey(requestKey); ns.setValue("notification suppression"); nodeInstance.addNodeState(ns); } } } // put child action requests on the stack if (childActionRequest.getChildrenRequests() != null) { // equivalent to 'push' all stack.addAll(childActionRequest.getChildrenRequests()); } } }
From source file:org.openmrs.module.kenyaemr.page.controller.chart.ChartViewPatientPageController.java
/** * Adds this patient to the user's recently viewed list * @param patient the patient/* w ww .ja v a 2 s . co m*/ * @param session the session */ private void recentlyViewed(Patient patient, Session session) { String attrName = EmrConstants.APP_CHART + ".recentlyViewedPatients"; LinkedList<Integer> recent = session.getAttribute(attrName, LinkedList.class); if (recent == null) { recent = new LinkedList<Integer>(); session.setAttribute(attrName, recent); } recent.removeFirstOccurrence(patient.getPatientId()); recent.add(0, patient.getPatientId()); while (recent.size() > 10) recent.removeLast(); }
From source file:uniol.apt.analysis.cycles.lts.AllSmallCyclesHavePVOne.java
/** * Recursive implementation of the depth-first search that looks for cycles with a Parikh vector of at most all * ones.//w ww.j av a2s . co m * @param ts The transition system to examine * @param state The next state that should be followed. * @param firedEvents Set of events which were already fired on the path from the initial state. * @param arcsFollowed List of arcs that were followed from the initial state to this state. * @return A pair were the first element is true if a cycle with Parikh vector 1 was found and the second * element is either null or a cycle with a smaller Parikh vector. */ static private Pair<Boolean, List<Arc>> checkPhase1(TransitionSystem ts, State state, Set<String> firedEvents, LinkedList<Arc> arcsFollowed) { boolean success = false; for (Arc arc : state.getPostsetEdges()) { if (firedEvents.contains(arc.getLabel())) continue; firedEvents.add(arc.getLabel()); arcsFollowed.addLast(arc); State target = arc.getTarget(); if (target.equals(ts.getInitialState())) { if (firedEvents.containsAll(ts.getAlphabet())) { // Found a suitable cycle! success = true; } else { // Found a counter-example return new Pair<Boolean, List<Arc>>(false, arcsFollowed); } } else { // Recurse to this new state Pair<Boolean, List<Arc>> result = checkPhase1(ts, target, firedEvents, arcsFollowed); if (result.getSecond() != null) return result; success = success || result.getFirst(); } // Undo the modifications done above boolean r = firedEvents.remove(arc.getLabel()); assert r == true; Arc last = arcsFollowed.removeLast(); assert last == arc; } return new Pair<>(success, null); }
From source file:com.github.jknack.handlebars.internal.Partial.java
@Override public void merge(final Context context, final Writer writer) throws IOException { TemplateLoader loader = handlebars.getLoader(); try {/*w w w . j a v a 2 s . c o m*/ LinkedList<TemplateSource> invocationStack = context.data(Context.INVOCATION_STACK); TemplateSource source = loader.sourceAt(path); if (exists(invocationStack, source.filename())) { TemplateSource caller = invocationStack.removeLast(); Collections.reverse(invocationStack); final String message; final String reason; if (invocationStack.isEmpty()) { reason = String.format("infinite loop detected, partial '%s' is calling itself", source.filename()); message = String.format("%s:%s:%s: %s", caller.filename(), line, column, reason); } else { reason = String.format("infinite loop detected, partial '%s' was previously loaded", source.filename()); message = String.format("%s:%s:%s: %s\n%s", caller.filename(), line, column, reason, "at " + join(invocationStack, "\nat ")); } HandlebarsError error = new HandlebarsError(caller.filename(), line, column, reason, text(), message); throw new HandlebarsException(error); } if (indent != null) { source = partial(source, indent); } Template template = handlebars.compile(source); if (this.context == null || this.context.equals("this")) { template.apply(context, writer); } else { template.apply(Context.newContext(context, context.get(this.context)), writer); } } catch (IOException ex) { String reason = String.format("The partial '%s' could not be found", loader.resolve(path)); String message = String.format("%s:%s:%s: %s", filename, line, column, reason); HandlebarsError error = new HandlebarsError(filename, line, column, reason, text(), message); throw new HandlebarsException(error); } }