List of usage examples for java.util List remove
E remove(int index);
From source file:com.espertech.esper.view.ViewServiceHelper.java
/** * Match the views under the stream to the list of view specications passed in. * The method changes the view specifications list passed in and removes those * specifications for which matcing views have been found. * If none of the views under the stream matches the first view specification passed in, * the method returns the stream itself and leaves the view specification list unchanged. * If one view under the stream matches, the view's specification is removed from the list. * The method will then attempt to determine if any child views of that view also match * specifications./*from ww w.j av a 2s .c om*/ * @param rootViewable is the top rootViewable event stream to which all views are attached as child views * This parameter is changed by this method, ie. specifications are removed if they match existing views. * @param viewFactories is the view specifications for making views * @return a pair of (A) the stream if no views matched, or the last child view that matched (B) the full list * of parent views */ protected static Pair<Viewable, List<View>> matchExistingViews(Viewable rootViewable, List<ViewFactory> viewFactories) { Viewable currentParent = rootViewable; List<View> matchedViewList = new LinkedList<View>(); boolean foundMatch; if (viewFactories.isEmpty()) { return new Pair<Viewable, List<View>>(rootViewable, Collections.<View>emptyList()); } do // while ((foundMatch) && (specifications.size() > 0)); { foundMatch = false; for (View childView : currentParent.getViews()) { ViewFactory currentFactory = viewFactories.get(0); if (!(currentFactory.canReuse(childView))) { continue; } // The specifications match, check current data window size viewFactories.remove(0); currentParent = childView; foundMatch = true; matchedViewList.add(childView); break; } } while ((foundMatch) && (!viewFactories.isEmpty())); return new Pair<Viewable, List<View>>(currentParent, matchedViewList); }
From source file:com.astamuse.asta4d.render.RenderUtil.java
/** * Find out all the snippet in the passed Document and execute them. The Containing embed tag of the passed Document will be exactly * mixed in here too. <br>/*from w w w . j a v a 2s. c o m*/ * Recursively contained snippets will be executed from outside to inside, thus the inner snippets will not be executed until all of * their outer snippets are finished. Also, the dynamically created snippets and embed tags will comply with this rule too. * * @param doc * the Document to apply snippets * @throws SnippetNotResovlableException * @throws SnippetInvokeException * @throws TemplateException */ public final static void applySnippets(Document doc) throws SnippetNotResovlableException, SnippetInvokeException, TemplateException, TemplateNotFoundException { if (doc == null) { return; } applyClearAction(doc, false); // retrieve ready snippets String selector = SelectorUtil.attr(ExtNodeConstants.SNIPPET_NODE_TAG_SELECTOR, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_READY); List<Element> snippetList = new ArrayList<>(doc.select(selector)); int readySnippetCount = snippetList.size(); int blockedSnippetCount = 0; for (int i = readySnippetCount - 1; i >= 0; i--) { // if parent snippet has not been executed, the current snippet will // not be executed too. if (isBlockedByParentSnippet(doc, snippetList.get(i))) { snippetList.remove(i); blockedSnippetCount++; } } readySnippetCount = readySnippetCount - blockedSnippetCount; String renderDeclaration; Renderer renderer; Context context = Context.getCurrentThreadContext(); Configuration conf = Configuration.getConfiguration(); final SnippetInvoker invoker = conf.getSnippetInvoker(); String refId; String currentTemplatePath; Element renderTarget; for (Element element : snippetList) { if (!conf.isSkipSnippetExecution()) { // for a faked snippet node which is created by template // analyzing process, the render target element should be its // child. if (element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE) .equals(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE_FAKE)) { renderTarget = element.children().first(); // the hosting element of this faked snippet has been removed by outer a snippet if (renderTarget == null) { element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_FINISHED); continue; } } else { renderTarget = element; } // we have to reset the ref of current snippet at every time to make sure the ref is always unique(duplicated snippet ref // could be created by list rendering) TemplateUtil.resetSnippetRefs(element); context.setCurrentRenderingElement(renderTarget); renderDeclaration = element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_RENDER); refId = element.attr(ExtNodeConstants.ATTR_SNIPPET_REF); currentTemplatePath = element.attr(ExtNodeConstants.ATTR_TEMPLATE_PATH); context.setCurrentRenderingElement(renderTarget); context.setData(TRACE_VAR_TEMPLATE_PATH, currentTemplatePath); try { if (element.hasAttr(ExtNodeConstants.SNIPPET_NODE_ATTR_PARALLEL)) { ConcurrentRenderHelper crHelper = ConcurrentRenderHelper.getInstance(context, doc); final Context newContext = context.clone(); final String declaration = renderDeclaration; crHelper.submitWithContext(newContext, declaration, refId, new Callable<Renderer>() { @Override public Renderer call() throws Exception { return invoker.invoke(declaration); } }); element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_WAITING); } else { renderer = invoker.invoke(renderDeclaration); applySnippetResultToElement(doc, refId, element, renderTarget, renderer); } } catch (SnippetNotResovlableException | SnippetInvokeException e) { throw e; } catch (Exception e) { SnippetInvokeException se = new SnippetInvokeException( "Error occured when executing rendering on [" + renderDeclaration + "]:" + e.getMessage(), e); throw se; } context.setData(TRACE_VAR_TEMPLATE_PATH, null); context.setCurrentRenderingElement(null); } else {// if skip snippet element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_FINISHED); } } // load embed nodes which blocking parents has finished List<Element> embedNodeList = doc.select(ExtNodeConstants.EMBED_NODE_TAG_SELECTOR); int embedNodeListCount = embedNodeList.size(); Iterator<Element> embedNodeIterator = embedNodeList.iterator(); Element embed; Element embedContent; while (embedNodeIterator.hasNext()) { embed = embedNodeIterator.next(); if (isBlockedByParentSnippet(doc, embed)) { embedNodeListCount--; continue; } embedContent = TemplateUtil.getEmbedNodeContent(embed); TemplateUtil.mergeBlock(doc, embedContent); embed.before(embedContent); embed.remove(); } if ((readySnippetCount + embedNodeListCount) > 0) { TemplateUtil.regulateElement(null, doc); applySnippets(doc); } else { ConcurrentRenderHelper crHelper = ConcurrentRenderHelper.getInstance(context, doc); String delcaration = null; if (crHelper.hasUnCompletedTask()) { delcaration = null; try { FutureRendererHolder holder = crHelper.take(); delcaration = holder.getRenderDeclaration(); String ref = holder.getSnippetRefId(); String reSelector = SelectorUtil.attr(ExtNodeConstants.SNIPPET_NODE_TAG_SELECTOR, ExtNodeConstants.ATTR_SNIPPET_REF, ref); Element element = doc.select(reSelector).get(0);// must have Element target; if (element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE) .equals(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE_FAKE)) { target = element.children().first(); } else { target = element; } applySnippetResultToElement(doc, ref, element, target, holder.getRenderer()); applySnippets(doc); } catch (InterruptedException | ExecutionException e) { throw new SnippetInvokeException("Concurrent snippet invocation failed" + (delcaration == null ? "" : " on [" + delcaration + "]"), e); } } } }
From source file:org.elasticsearch.client.NodeSelectorTests.java
public void testNotMasterOnly() { Node masterOnly = dummyNode(true, false, false); Node all = dummyNode(true, true, true); Node masterAndData = dummyNode(true, true, false); Node masterAndIngest = dummyNode(true, false, true); Node coordinatingOnly = dummyNode(false, false, false); Node ingestOnly = dummyNode(false, false, true); Node data = dummyNode(false, true, randomBoolean()); List<Node> nodes = new ArrayList<>(); nodes.add(masterOnly);/*w w w . jav a 2 s . c om*/ nodes.add(all); nodes.add(masterAndData); nodes.add(masterAndIngest); nodes.add(coordinatingOnly); nodes.add(ingestOnly); nodes.add(data); Collections.shuffle(nodes, getRandom()); List<Node> expected = new ArrayList<>(nodes); expected.remove(masterOnly); NodeSelector.SKIP_DEDICATED_MASTERS.select(nodes); assertEquals(expected, nodes); }
From source file:net.dv8tion.jda.handle.GuildRoleDeleteHandler.java
@Override protected String handleInternally(JSONObject content) { if (GuildLock.get(api).isLocked(content.getString("guild_id"))) { return content.getString("guild_id"); }/*from w w w.ja v a 2s . co m*/ GuildImpl guild = (GuildImpl) api.getGuildMap().get(content.getString("guild_id")); Role removedRole = guild.getRolesMap().remove(content.getString("role_id")); if (removedRole == null) { EventCache.get(api).cache(EventCache.Type.ROLE, content.getString("role_id"), () -> { handle(allContent); }); EventCache.LOG .debug("GUILD_ROLE_DELETE attempted to delete a role that didn't exist! JSON: " + content); return null; } //Now that the role is removed from the Guild, remove it from all users. for (List<Role> userRoles : guild.getUserRoles().values()) { userRoles.remove(removedRole); } api.getEventManager().handle(new GuildRoleDeleteEvent(api, responseNumber, guild, removedRole)); return null; }
From source file:springobjectmapper.TableProperties.java
private List<Field> getUpdateFields() { List<Field> fields = getFields(typeClass); fields.remove(idField); return fields; }
From source file:edu.upenn.egricelab.AlignerBoost.FilterSAMAlignPE.java
private static int filterPEHits(List<SAMRecordPair> alnPEList, int minMapQ) { int n = alnPEList.size(); int removed = 0; for (int i = n - 1; i >= 0; i--) { // search backward for maximum performance if (alnPEList.get(i).getPEMapQ() < minMapQ) { alnPEList.remove(i); removed++;/*from www.j ava2 s. c o m*/ } } return removed; }
From source file:br.com.projetotcc.controller.DesenvolvedorController.java
@RequestMapping("/editardesenvolvedor") public ModelAndView editarDesenvolvedor(HttpServletRequest request) { int id = Integer.parseInt(request.getParameter("id")); Desenvolvedor d = desenvolvedorDao.getDesenvolvedor(id); ModelAndView model = new ModelAndView("editardesenvolvedor"); model.addObject("desenvolvedor", d); List<Area> areas = areaDao.list(); areas.remove(d.getArea()); areas.add(0, d.getArea());// w w w. jav a2 s. co m model.addObject("areas", areas); return model; }
From source file:org.businessmanager.web.controller.page.admin.AssignGroupsController.java
private void removeUserFromGroup(Group group) { List<User> members = group.getMembers(); members.remove(model.getSelectedUser()); }
From source file:com.github.magicsky.sya.checkers.TestSourceReader.java
/** * Returns an array of StringBuilder objects for each comment section found preceding the named * test in the source code./*w w w. ja va 2s .c o m*/ * * @param srcRoot the directory inside the bundle containing the packages * @param clazz the name of the class containing the test * @param testName the name of the test * @param numSections the number of comment sections preceding the named test to return. * Pass zero to get all available sections. * @return an array of StringBuilder objects for each comment section found preceding the named * test in the source code. * @throws IOException */ public static StringBuilder[] getContentsForTest(String srcRoot, Class clazz, final String testName, int numSections) throws IOException { // Walk up the class inheritance chain until we find the test method. try { while (clazz.getMethod(testName).getDeclaringClass() != clazz) { clazz = clazz.getSuperclass(); } } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchMethodException e) { Assert.fail(e.getMessage()); } while (true) { // Find and open the .java file for the class clazz. String fqn = clazz.getName().replace('.', '/'); fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$")); String classFile = fqn + ".java"; InputStream in; Class superclass = clazz.getSuperclass(); try { in = FileUtils.openInputStream(new File(srcRoot + '/' + classFile)); } catch (IOException e) { if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { throw e; } clazz = superclass; continue; } BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { // Read the java file collecting comments until we encounter the test method. List<StringBuilder> contents = new ArrayList<StringBuilder>(); StringBuilder content = new StringBuilder(); for (String line = br.readLine(); line != null; line = br.readLine()) { line = line.replaceFirst("^\\s*", ""); // Replace leading whitespace, preserve trailing if (line.startsWith("//")) { content.append(line.substring(2) + "\n"); } else { if (!line.startsWith("@") && content.length() > 0) { contents.add(content); if (numSections > 0 && contents.size() == numSections + 1) contents.remove(0); content = new StringBuilder(); } if (line.length() > 0 && !contents.isEmpty()) { int idx = line.indexOf(testName); if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) { return contents.toArray(new StringBuilder[contents.size()]); } if (!line.startsWith("@")) { contents.clear(); } } } } } finally { br.close(); } if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { throw new IOException("Test data not found for " + clazz.getName() + "." + testName); } clazz = superclass; } }
From source file:net.adamcin.granite.client.packman.AbstractPackageManagerClient.java
private static DetailedResponse handleFailure(String line, List<String> failureBuilder, List<String> progressErrors) { if (line.startsWith("</pre>")) { String msg = failureBuilder != null && !failureBuilder.isEmpty() ? failureBuilder.remove(0) : ""; return new DetailedResponseImpl(false, msg, -1, progressErrors, failureBuilder); } else {/* ww w. j a v a2s . c o m*/ // assume line is part of stack trace failureBuilder.add(line.trim()); } return null; }