List of usage examples for org.springframework.util MultiValueMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.craftercms.commons.rest.RestClientUtils.java
/** * Converts a map of params to a query string. * * @param params the params to convert to a query string * @param encode if the param values should be encoded * @return the params as a query string//from www. j ava 2 s .c o m */ public static String createQueryStringFromParams(MultiValueMap<String, String> params, boolean encode) { StringBuilder queryString = new StringBuilder(); if (MapUtils.isNotEmpty(params)) { for (Map.Entry<String, List<String>> entry : params.entrySet()) { String paramName; try { paramName = URLEncoder.encode(entry.getKey(), "UTF-8"); } catch (UnsupportedEncodingException e) { // Should NEVER happen throw new RuntimeException(e); } for (String paramValue : entry.getValue()) { if (queryString.length() > 0) { queryString.append('&'); } if (encode) { try { paramValue = URLEncoder.encode(paramValue, "UTF-8"); } catch (UnsupportedEncodingException e) { // Should NEVER happen throw new RuntimeException(e); } } queryString.append(paramName).append('=').append(paramValue); } } queryString.insert(0, '?'); } return queryString.toString(); }
From source file:org.crazydog.util.spring.CollectionUtils.java
/** * Return an unmodifiable view of the specified multi-value map. * * @param map the map for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified multi-value map. * @since 3.1/* w w w . java 2s . co m*/ */ @SuppressWarnings("unchecked") public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap( MultiValueMap<? extends K, ? extends V> map) { org.springframework.util.Assert.notNull(map, "'map' must not be null"); Map<K, List<V>> result = new LinkedHashMap<K, List<V>>(map.size()); for (Map.Entry<? extends K, ? extends List<? extends V>> entry : map.entrySet()) { List<? extends V> values = Collections.unmodifiableList(entry.getValue()); result.put(entry.getKey(), (List<V>) values); } Map<K, List<V>> unmodifiableMap = Collections.unmodifiableMap(result); return toMultiValueMap(unmodifiableMap); }
From source file:org.n52.io.request.IoParameters.java
protected static MultiValueMap<String, JsonNode> convertValuesToJsonNodes( MultiValueMap<String, String> queryParameters) { MultiValueMap<String, JsonNode> parameters = new LinkedMultiValueMap<>(); final Set<Entry<String, List<String>>> entrySet = queryParameters.entrySet(); for (Entry<String, List<String>> entry : entrySet) { for (String value : entry.getValue()) { final String key = entry.getKey().toLowerCase(); parameters.add(key, getJsonNodeFrom(value)); }/* w w w . j a v a 2s.c o m*/ } return parameters; }
From source file:com.miserablemind.api.consumer.tradeking.api.impl.StreamingTemplate.java
private String createFormUrlEncodedBodyString(MultiValueMap<String, String> body) { StringBuilder bodyBuffer = new StringBuilder(); for (Iterator<Map.Entry<String, List<String>>> bodyIt = body.entrySet().iterator(); bodyIt.hasNext();) { Map.Entry<String, List<String>> entry = bodyIt.next(); String key = entry.getKey(); List<String> values = entry.getValue(); for (Iterator<String> valuesIt = values.iterator(); valuesIt.hasNext();) { bodyBuffer.append(key).append("=").append(formEncode(valuesIt.next())); if (valuesIt.hasNext()) { bodyBuffer.append("&"); }//w w w .j a v a 2s.com } if (bodyIt.hasNext()) { bodyBuffer.append("&"); } } return bodyBuffer.toString(); }
From source file:com.onedrive.api.internal.MultipartRelatedHttpMessageConverter.java
private void writeParts(OutputStream os, MultiValueMap<String, Object> parts, byte[] boundary) throws IOException { for (Map.Entry<String, List<Object>> entry : parts.entrySet()) { String name = entry.getKey(); for (Object part : entry.getValue()) { if (part != null) { writeBoundary(os, boundary); writePart(name, getHttpEntity(part), os); writeNewLine(os);//from ww w . j a v a 2 s. c o m } } } }
From source file:org.devefx.httpmapper.binding.MapperMethod.java
private URI appendUrlParams(URI uri, MultiValueMap<String, Object> body) throws URISyntaxException { UriComponentsBuilder builder = UriComponentsBuilder.fromUri(uri); for (Map.Entry<String, List<Object>> entry : body.entrySet()) { String key = entry.getKey(); for (Object value : entry.getValue()) { if (value instanceof String) { builder.queryParam(key, (String) value); }/*from w w w .j av a 2s.co m*/ } } UriComponents uriComponents = builder.build(); return uriComponents.toUri(); }
From source file:jails.http.converter.FormHttpMessageConverter.java
private void writeParts(OutputStream os, MultiValueMap<String, Object> parts, byte[] boundary) throws IOException { for (Map.Entry<String, List<Object>> entry : parts.entrySet()) { String name = entry.getKey(); for (Object part : entry.getValue()) { writeBoundary(boundary, os); HttpEntity entity = getEntity(part); writePart(name, entity, os); writeNewLine(os);//w w w. ja v a 2 s .com } } }
From source file:com.httpMessageConvert.FormHttpMessageConverter.java
private void writeParts(OutputStream os, MultiValueMap<String, Object> parts, byte[] boundary) throws IOException { for (Map.Entry<String, List<Object>> entry : parts.entrySet()) { String name = entry.getKey(); for (Object part : entry.getValue()) { if (part != null) { writeBoundary(boundary, os); HttpEntity entity = getEntity(part); writePart(name, entity, os); writeNewLine(os);//from ww w . j ava 2s.co m } } } }
From source file:com.seajas.search.codex.social.connection.InMemoryConnectionRepository.java
@Override public MultiValueMap<String, Connection<?>> findConnectionsToUsers( final MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }/* w ww . j a va 2s . c o m*/ Map<String, List<String>> providerUserIdsByProviderId = new HashMap<String, List<String>>(); for (Entry<String, List<String>> entry : providerUsers.entrySet()) { String providerId = entry.getKey(); providerUserIdsByProviderId.put(providerId, entry.getValue()); } List<ConnectionData> connectionDatas = new ArrayList<ConnectionData>(); for (Map.Entry<String, List<String>> entry : providerUserIdsByProviderId.entrySet()) { connectionDatas.addAll(getInMemoryProviderConnectionRepository(entry.getKey()) .findByProviderUserIdsOrderByProviderIdAndRank(entry.getValue())); } List<Connection<?>> resultList = createConnections(connectionDatas); 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:com.jiwhiz.domain.account.impl.ConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }//from w w w .ja va 2 s. co m MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); List<String> providerUserIds = entry.getValue(); List<UserSocialConnection> userSocialConnections = userSocialConnectionRepository .findByProviderIdAndProviderUserIdIn(providerId, providerUserIds); List<Connection<?>> connections = new ArrayList<Connection<?>>(providerUserIds.size()); for (int i = 0; i < providerUserIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); for (UserSocialConnection userSocialConnection : userSocialConnections) { String providerUserId = userSocialConnection.getProviderUserId(); int connectionIndex = providerUserIds.indexOf(providerUserId); connections.set(connectionIndex, buildConnection(userSocialConnection)); } } return connectionsForUsers; }