/** * Create a deep copy of this Map. * @return a copy of this Map, including a copy of each value-holding List entry * (consistently using an independent modifiable {@link LinkedList} for each entry) * along the lines of {@code MultiValueMap.addAll} semantics * @since 4.2 * @see #addAll(MultiValueMap) * @see #clone() */ public LinkedMultiValueMap<K, V> deepCopy() { LinkedMultiValueMap<K, V> copy = new LinkedMultiValueMap<>(this.targetMap.size()); this.targetMap.forEach((key, value) -> copy.put(key, new LinkedList<>(value))); return copy; }
/** * Create a deep copy of this Map. * @return a copy of this Map, including a copy of each value-holding List entry * (consistently using an independent modifiable {@link LinkedList} for each entry) * along the lines of {@code MultiValueMap.addAll} semantics * @since 4.2 * @see #addAll(MultiValueMap) * @see #clone() */ public LinkedMultiValueMap<K, V> deepCopy() { LinkedMultiValueMap<K, V> copy = new LinkedMultiValueMap<>(this.targetMap.size()); this.targetMap.forEach((key, value) -> copy.put(key, new LinkedList<>(value))); return copy; }
@Test public void getFirst() { List<String> values = new ArrayList<>(2); values.add("value1"); values.add("value2"); map.put("key", values); assertEquals("value1", map.getFirst("key")); assertNull(map.getFirst("other")); }
public UaaAuthentication getUaaAuthentication(List<? extends GrantedAuthority> uaaAuthorityList, Set<String> externalGroups, MultiValueMap<String, String> userAttributes) { LinkedMultiValueMap<String, String> customAttributes = new LinkedMultiValueMap<>(); for (Map.Entry<String, List<String>> entry : userAttributes.entrySet()) { if (entry.getKey().startsWith(USER_ATTRIBUTE_PREFIX)) { customAttributes.put(entry.getKey().substring(USER_ATTRIBUTE_PREFIX.length()), entry.getValue()); } } UaaAuthentication authentication = new UaaAuthentication(getUaaPrincipal(), getCredentials(), uaaAuthorityList, externalGroups, customAttributes, null, isAuthenticated(), System.currentTimeMillis(), getTokenExpiration()==null ? -1l : getTokenExpiration().getTime()); authentication.setAuthenticationMethods(Collections.singleton("ext")); List<String> acrValues = userAttributes.get(AUTHENTICATION_CONTEXT_CLASS_REFERENCE); if (acrValues !=null) { authentication.setAuthContextClassRef(new HashSet<>(acrValues)); } return authentication; } }
private MultiValueMap<Object, Object> convertToMultiValueMap(Map<?, ?> simpleMap) { LinkedMultiValueMap<Object, Object> multipartValueMap = new LinkedMultiValueMap<Object, Object>(); for (Entry<?, ?> entry : simpleMap.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Object[]) { value = Arrays.asList((Object[]) value); } if (value instanceof Collection) { multipartValueMap.put(key, new ArrayList<Object>((Collection<?>) value)); } else { multipartValueMap.add(key, value); } } return multipartValueMap; }
public DefaultBar(Map<String, String[]> parameters) { for (String key : parameters.keySet()) { super.put(key, Arrays.asList(parameters.get(key))); } }
/** * Create a deep copy of this Map. * @return a copy of this Map, including a copy of each value-holding List entry * (consistently using an independent modifiable {@link LinkedList} for each entry) * along the lines of {@code MultiValueMap.addAll} semantics * @since 4.2 * @see #addAll(MultiValueMap) * @see #clone() */ public LinkedMultiValueMap<K, V> deepCopy() { LinkedMultiValueMap<K, V> copy = new LinkedMultiValueMap<>(this.targetMap.size()); this.targetMap.forEach((key, value) -> copy.put(key, new LinkedList<>(value))); return copy; }
private MultiValueMap<Object, Object> convertToMultiValueMap(Map<?, ?> simpleMap) { LinkedMultiValueMap<Object, Object> multipartValueMap = new LinkedMultiValueMap<Object, Object>(); for (Entry<?, ?> entry : simpleMap.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Object[]) { value = Arrays.asList((Object[]) value); } if (value instanceof Collection) { multipartValueMap.put(key, new ArrayList<Object>((Collection<?>) value)); } else { multipartValueMap.add(key, value); } } return multipartValueMap; }