List of usage examples for java.util List set
E set(int index, E element);
From source file:beast.evolution.tree.RandomTree.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private void swap(final List list, final int i, final int j) { final Object tmp = list.get(i); list.set(i, list.get(j)); list.set(j, tmp);// w w w . j a va 2s . c o m }
From source file:de.pixida.logtest.logreaders.GenericLogReader.java
private String joinLinesToPayload(final List<String> payloadLines) { String payload;/*from ww w . ja va 2s . co m*/ LOG.trace("Joining multiline entries (including headline): {}", payloadLines); if (this.trimPayload) { LOG.trace("Trimming payload lines"); for (int j = 0; j < payloadLines.size(); j++) { payloadLines.set(j, payloadLines.get(j).trim()); } } else { LOG.trace("Not trimming payload lines"); } if (this.removeEmptyPayloadLinesFromMultilineEntry) { LOG.trace("Skipping empty payload lines"); for (final Iterator<String> it = payloadLines.iterator(); it.hasNext();) { if (it.next().length() == 0) { it.remove(); } } } else { LOG.trace("Not removing empty payload lines"); } payload = payloadLines.stream().collect(Collectors.joining("\n")); LOG.trace("Payload lines assembled to payload: {}", payloadLines, payload); return payload; }
From source file:io.github.davejoyce.dao.composite.social.connect.jpa.JpaConnectionRepository.java
/** * {@inheritDoc}// www . ja va 2 s . c o m */ public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); } StringBuilder providerUsersCriteriaJpaQl = new StringBuilder(QUERY_SELECT_FROM) .append("WHERE ausc.key.appUser.userId = :userId").append(" AND "); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); providerUsersCriteriaJpaQl.append("ausc.key.providerId = :providerId_").append(providerId) .append("AND ausc.key.providerUserId IN (:providerUserIds_").append(providerId).append(")"); if (it.hasNext()) { providerUsersCriteriaJpaQl.append(" OR "); } } providerUsersCriteriaJpaQl.append(" ORDER BY ausc.key.providerId, ausc.rank"); TypedQuery<AppUserSocialConnection> query = entityManager .createQuery(providerUsersCriteriaJpaQl.toString(), AppUserSocialConnection.class) .setParameter("userId", userId); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); query.setParameter(("providerId_" + providerId), providerId) .setParameter(("providerUserIds_" + providerId), entry.getValue()); } List<Connection<?>> resultList = appUserSocialConnectionsToConnections(query.getResultList()); MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Connection<?> connection : resultList) { String providerId = connection.getKey().getProviderId(); List<String> userIds = providerUsers.get(providerId); List<Connection<?>> connections = connectionsForUsers.get(providerId); if (connections == null) { connections = new ArrayList<Connection<?>>(userIds.size()); for (int i = 0; i < userIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); } String providerUserId = connection.getKey().getProviderUserId(); int connectionIndex = userIds.indexOf(providerUserId); connections.set(connectionIndex, connection); } return connectionsForUsers; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo.java
public void subInLiterals(Map<String, Literal> varsToVals, List<String> n3targets) { if (varsToVals == null || varsToVals.isEmpty() || n3targets == null) return;/*from w w w .jav a 2 s . c o m*/ for (int i = 0; i < n3targets.size(); i++) { String orginalN3 = n3targets.get(i); if (orginalN3 == null) continue; String newN3 = orginalN3; for (String key : varsToVals.keySet()) { newN3 = subInLiterals(key, varsToVals.get(key), newN3); } n3targets.set(i, newN3); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo.java
/** * This is the method to use to substitute in Literals into variables of target N3 strings. * This takes into account multiple values that would be returned from a select list. * subInUris should no longer be used./*from w w w .j a va2s.co m*/ * * It will modify the list n3targets. */ public void subInMultiLiterals(Map<String, List<Literal>> varsToVals, List<String> n3targets) { if (varsToVals == null || varsToVals.isEmpty() || n3targets == null) return; for (int i = 0; i < n3targets.size(); i++) { String orginalN3 = n3targets.get(i); if (orginalN3 == null) continue; String newN3 = orginalN3; for (String key : varsToVals.keySet()) { newN3 = subInMultiLiterals(key, varsToVals.get(key), newN3); } n3targets.set(i, newN3); } }
From source file:org.psikeds.common.interceptor.RequestIdGenerationInterceptor.java
private void setRequestIdAsHTTPHeader(final T message, final String reqid) { if (!StringUtils.isEmpty(this.nameOfRequestIdHttpHeader) && !StringUtils.isEmpty(reqid)) { Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS)); if (headers == null) { headers = new HashMap<String, List<String>>(); }// w w w . j av a 2s . c om List<String> rih = headers.get(this.nameOfRequestIdHttpHeader); if (rih == null) { rih = new ArrayList<String>(); } if (rih.isEmpty()) { LOGGER.debug("Adding new HTTP-Header: {} = {}", this.nameOfRequestIdHttpHeader, reqid); rih.add(reqid); } else { LOGGER.debug("Replacing existing HTTP-Header: {} = {}", this.nameOfRequestIdHttpHeader, reqid); // same http header could exist several times // we simply replace the first one in that case rih.set(0, reqid); } headers.put(this.nameOfRequestIdHttpHeader, rih); message.put(Message.PROTOCOL_HEADERS, headers); } }
From source file:com.draagon.meta.manager.xml.ObjectManagerXML.java
/** * Update the specified object in the datastore *//* w w w .j av a 2s.c o m*/ public void updateObject(ObjectConnection c, Object obj) throws MetaException { MetaObject mc = MetaDataLoader.findMetaObject(obj); List<Object> list = getObjectsFromTable(c, mc); int i = list.indexOf(obj); if (i < 0) throw new MetaException("Object [" + obj + "] did not exist in table for class [" + mc + "]"); if (!isUpdateableClass(mc)) throw new MetaException("Object of class [" + mc + "] is not persistable"); prePersistence(c, mc, obj, UPDATE); list.set(i, obj); postPersistence(c, mc, obj, UPDATE); }
From source file:com.liusoft.dlog4j.velocity.DLOG_Photo_VelocityTool.java
/** * ?//from www . ja v a 2 s . c o m * @param site * @return */ public List format_photo_months(List months) { if (months == null) return null; List new_months = new ArrayList(); if (months.size() > 0) { new_months.addAll(months); final SimpleDateFormat month_fm = new SimpleDateFormat("MMM yyyy", request.getLocale()); Calendar time = Calendar.getInstance(); for (int i = 0; i < new_months.size(); i++) { int value = ((Integer) new_months.get(i)).intValue(); time.set(Calendar.YEAR, value / 100); time.set(Calendar.MONTH, ((value % 100) - 1)); new_months.set(i, month_fm.format(time.getTime())); } } return new_months; }
From source file:name.persistent.behaviours.RemoteDomainSupport.java
private InetSocketAddress pickService(List<Service> services) { int total = 0; List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>(); for (int i = 0, n = services.size(); i < n; i++) { addresses.add(null);//from w ww . j a v a2 s. com Service srv = services.get(i); Object url = srv.getPurlServer(); if (url == null) continue; ParsedURI parsed = new ParsedURI(((RDFObject) url).getResource().stringValue()); int port = "https".equalsIgnoreCase(parsed.getScheme()) ? 443 : 80; InetSocketAddress server = resolve(parsed.getAuthority(), port); if (isBlackListed(server) || server.isUnresolved()) continue; addresses.set(i, server); Number weight = srv.getPurlWeight(); total += weight == null ? 1 : weight.intValue(); } total = random(total); for (int i = 0, n = services.size(); i < n; i++) { Service srv = services.get(i); if (addresses.get(i) == null) continue; Number weight = srv.getPurlWeight(); total -= weight == null ? 1 : weight.intValue(); if (total < 0) { return addresses.get(i); } } return null; }
From source file:com.opoopress.maven.plugins.plugin.ThemeMojo.java
private void updateSiteConfigurationFile(ConfigImpl config, String currentThemeName, String newThemeName) throws MojoFailureException { if (currentThemeName != null) { File file = new File(config.getBasedir(), "config.yml"); if (file.exists()) { try { List<String> lines = FileUtils.readLines(file, "UTF-8"); int lineNumber = -1; for (int i = 0; i < lines.size(); i++) { if (lines.get(i).startsWith("theme: ")) { lineNumber = i;/*from www . j av a 2 s. c o m*/ break; } } if (lineNumber != -1) { getLog().debug("Change theme to '" + newThemeName + "' in file:" + file); lines.set(lineNumber, "theme: '" + newThemeName + "'"); FileUtils.writeLines(file, "UTF-8", lines); return; } } catch (IOException e) { throw new MojoFailureException("Update configuration file failed: " + e.getMessage(), e); } } } getLog().debug("Changing config file 'config-theme.yml'."); File themeConfigFile = new File(config.getBasedir(), "config-theme.yml"); try { FileUtils.writeStringToFile(themeConfigFile, "theme: '" + name + "'"); } catch (IOException e) { throw new MojoFailureException("Change theme config file failed.", e); } }