List of usage examples for java.util List remove
E remove(int index);
From source file:EntityToD2RHelpers.java
public EntityToD2RHelpers(String uri, String config_file, List<String> people, List<String> places, PrintWriter out) throws Exception { // In this example, I am assuming that the D2R server is running on localhost:2020 //out.println("PREFIX vocab: <http://localhost:2020/vocab/resource/>"); List<String> lines = (List<String>) FileUtils.readLines(new File(config_file)); String d2r_host_and_port = lines.remove(0); String[] info = d2r_host_and_port.split(" "); System.out.println("D2R host = |" + info[0] + "| and port = |" + info[1] + "|"); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); String d2r_type = scanner.next(); System.out.println("* d2r_type = " + d2r_type); while (scanner.hasNext()) { String term = scanner.next(); String[] property_and_entity_type = term.split("/"); System.out.println(" property: " + property_and_entity_type[0] + " entity type: " + property_and_entity_type[1]); if (property_and_entity_type[1].equals("person")) { for (String person : people) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + person + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("person"); out.println(blank_node + " <http://knowledgebooks.com/rdf/personName> \"" + person.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPerson> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); }//from www .j ava 2 s . com } } } else if (property_and_entity_type[1].equals("place")) { for (String place : places) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + place + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("place"); out.println(blank_node + " <http://knowledgebooks.com/rdf/placeName> \"" + place.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPlace> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); } } } } } } out.close(); }
From source file:alpha.portal.webapp.filter.LocaleRequestWrapper.java
/** * {@inheritDoc}//from ww w . java 2 s . co m */ @Override @SuppressWarnings("unchecked") public Enumeration<Locale> getLocales() { if (null != this.preferredLocale) { final List<Locale> l = Collections.list(super.getLocales()); if (l.contains(this.preferredLocale)) { l.remove(this.preferredLocale); } l.add(0, this.preferredLocale); return Collections.enumeration(l); } else return super.getLocales(); }
From source file:com.ibm.jaggr.core.impl.deps.DepUtils.java
/** * Removes URIs containing duplicate and non-orthogonal paths so that the * collection contains only unique and non-overlapping paths. * * @param uris collection of URIs// ww w.j a v a 2 s . c o m * * @return a new collection with redundant paths removed */ static public Collection<URI> removeRedundantPaths(Collection<URI> uris) { List<URI> result = new ArrayList<URI>(); for (URI uri : uris) { String path = uri.getPath(); if (!path.endsWith("/")) { //$NON-NLS-1$ path += "/"; //$NON-NLS-1$ } boolean addIt = true; for (int i = 0; i < result.size(); i++) { URI testUri = result.get(i); if (!StringUtils.equals(testUri.getScheme(), uri.getScheme()) || !StringUtils.equals(testUri.getHost(), uri.getHost()) || testUri.getPort() != uri.getPort()) { continue; } String test = testUri.getPath(); if (!test.endsWith("/")) { //$NON-NLS-1$ test += "/"; //$NON-NLS-1$ } if (path.equals(test) || path.startsWith(test)) { addIt = false; break; } else if (test.startsWith(path)) { result.remove(i); } } if (addIt) result.add(uri); } // Now copy the trimmed list back to the original return result; }
From source file:cc.kave.commons.pointsto.evaluation.UsagePruning.java
/** * @return The number of pruned usages/*www . j a v a2 s.com*/ */ public int prune(final int maxUsages, Map<ProjectIdentifier, List<Usage>> usages) { final int initialNumUsages = usages.values().stream().mapToInt(Collection::size).sum(); int numUsages = initialNumUsages; if (numUsages > maxUsages) { Random rnd = new Random(rndGenerator.nextLong()); List<Pair<ProjectIdentifier, Double>> projectUsageCounts = new ArrayList<>(usages.size()); for (Map.Entry<ProjectIdentifier, List<Usage>> entry : usages.entrySet()) { projectUsageCounts.add(Pair.create(entry.getKey(), (double) entry.getValue().size())); Collections.shuffle(entry.getValue(), rnd); } EnumeratedDistribution<ProjectIdentifier> distribution = new EnumeratedDistribution<>(rndGenerator, projectUsageCounts); while (numUsages > maxUsages) { ProjectIdentifier project = distribution.sample(); List<Usage> projectUsages = usages.get(project); if (!projectUsages.isEmpty()) { projectUsages.remove(projectUsages.size() - 1); --numUsages; } } } return initialNumUsages - numUsages; }
From source file:com.cronutils.parser.CronParser.java
/** * Build possible cron expressions from definitions. One is built for sure. A second one may be build if last field is optional. * // ww w . j a v a2s . com * @param cronDefinition * - cron definition instance */ private void buildPossibleExpressions(CronDefinition cronDefinition) { List<CronParserField> expression = new ArrayList<>(); for (FieldDefinition fieldDefinition : cronDefinition.getFieldDefinitions()) { expression.add(new CronParserField(fieldDefinition.getFieldName(), fieldDefinition.getConstraints())); } Collections.sort(expression, CronParserField.createFieldTypeComparator()); expressions.put(expression.size(), expression); if (cronDefinition.isLastFieldOptional()) { List<CronParserField> shortExpression = new ArrayList<>(); shortExpression.addAll(expression); shortExpression.remove(shortExpression.size() - 1); expressions.put(shortExpression.size(), shortExpression); } }
From source file:com.manydesigns.portofino.buttons.ButtonsLogic.java
public static List<ButtonInfo> computeButtonsForClass(Class<?> someClass, String list) { List<ButtonInfo> buttons = new ArrayList<ButtonInfo>(); for (Method method : someClass.getMethods()) { if (method.isBridge() || method.isSynthetic()) { continue; }// w ww. j ava 2 s . co m Button button = getButtonForMethod(method, list); if (button != null) { ButtonInfo buttonInfo = new ButtonInfo(button, method, someClass); buttons.add(buttonInfo); } } Collections.sort(buttons, new ButtonComparatorByOrder()); //Group together buttons of the same group for (int i = 0; i < buttons.size() - 1; i++) { ButtonInfo info = buttons.get(i); String group = info.getButton().group(); if (!StringUtils.isBlank(group)) { int count = 1; for (int j = i + 1; j < buttons.size(); j++) { ButtonInfo info2 = buttons.get(j); if (info2.getButton().group().equals(group)) { buttons.remove(j); buttons.add(i + count, info2); count++; } } } } return buttons; }
From source file:edu.kit.dama.transfer.client.util.CleanupManager.java
/** * Add a file from cleanup/* w w w . jav a2 s. c om*/ * * @param pId The ID for the transfer * @param pFile The file not to cleanup */ public final void removeFile(String pId, File pFile) { if (pId == null || pFile == null) { return; } List<File> files = filesToCleanup.get(pId); if (files != null) { files.remove(pFile); } }
From source file:net.formicary.remoterun.examples.Server.java
private void closeInput(String line) { StrTokenizer tokenizer = new StrTokenizer(line, ' ', '"'); @SuppressWarnings("unchecked") List<String> tokens = tokenizer.getTokenList(); tokens.remove(0); // first token is the run command long id = Long.parseLong(tokens.remove(0)); Collection<IAgentConnection> connectedClients = remoteRunMaster.getConnectedClients(); if (connectedClients.isEmpty()) { log.error("Unable to send command: no agent connections"); } else {/*from w ww . j ava 2 s.c o m*/ IAgentConnection connection = connectedClients.iterator().next(); RemoteRun.MasterToAgent.Builder builder = RemoteRun.MasterToAgent.newBuilder() .setMessageType(RemoteRun.MasterToAgent.MessageType.CLOSE_STDIN).setRequestId(id); connection.write(builder.build()); } }
From source file:com.huateng.startup.init.MenuInfoUtil.java
private static void valueIdRole(List<Object[]> funcMapList) { List<Object[]> list = new ArrayList<Object[]>(); for (int i = 0; i < funcMapList.size(); i++) { Object[] obj = funcMapList.get(i); BigDecimal valueId = (BigDecimal) obj[1]; String roleFlag = (String) obj[5]; for (int j = i + 1; j < funcMapList.size(); j++) { Object[] obj2 = funcMapList.get(j); BigDecimal valueId2 = (BigDecimal) obj2[1]; String roleFlag2 = (String) obj2[5]; if (valueId.equals(valueId2)) { roleFlag = roleFlag + roleFlag2; list.add(obj2);/* ww w.j ava2 s. c o m*/ } } obj[5] = roleFlag; } for (Object[] ov : list) { funcMapList.remove(ov); } }
From source file:edu.yale.cs.hadoopdb.connector.DBChunk.java
/** * Randomly chooses a host from the set of hosts avoiding if possible the * given host//ww w. jav a 2 s . c o m */ public DBChunkHost getAnyHost(DBChunkHost avoid_host) { if (avoid_host == null) { return getAnyHost(); } List<DBChunkHost> nds = new ArrayList<DBChunkHost>(); nds.addAll(this.locations.values()); nds.remove(avoid_host); if (nds.size() == 0) { LOG.warn("Request to avoid host " + avoid_host + " unsatisfiable -" + "- only one host for chunk " + this.getId()); return getAnyHost(); } return nds.get(R.nextInt(nds.size())); }