本文整理了Java中java.util.stream.Collectors.toConcurrentMap()
方法的一些代码示例,展示了Collectors.toConcurrentMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collectors.toConcurrentMap()
方法的具体详情如下:
包路径:java.util.stream.Collectors
类名称:Collectors
方法名:toConcurrentMap
暂无
代码示例来源:origin: speedment/speedment
/**
* Accumulates all key-value pairs of this {@code MapStream} into a
* {@code ConcurrentMap}.
* <p>
* If the mapped keys contains duplicates (according to
* {@link Object#equals(Object)}), an {@code IllegalStateException} is
* thrown when the collection operation is performed. If the mapped keys
* may have duplicates, use {@link #toConcurrentMap(BinaryOperator)} instead.
*
* <p>
* It is common for either the key or the value to be the input elements.
* In this case, the utility method
* {@link java.util.function.Function#identity()} may be helpful.
* <p>
* This is a {@link Collector.Characteristics#CONCURRENT concurrent} and
* {@link Collector.Characteristics#UNORDERED unordered} Collector.
*
* @return a {@code ConcurrentMap} whose keys are taken from this stream
*
* @see #toMap()
* @see #toConcurrentMap(BinaryOperator)
*/
public Map<K, V> toConcurrentMap() {
return inner.collect(Collectors.toConcurrentMap(
Map.Entry::getKey,
Map.Entry::getValue
));
}
代码示例来源:origin: speedment/speedment
/**
* Accumulates all key-value pairs of this {@code MapStream} into a
* {@code ConcurrentMap}.
* <p>
* If the mapped keys contains duplicates (according to
* {@link Object#equals(Object)}), the value mapping function is applied to
* each equal element, and the results are merged using the provided merging
* function.
*
* <p>
* There are multiple ways to deal with collisions between multiple elements
* mapping to the same key. The other forms of {@code toConcurrentMap} simply use
* a merge function that throws unconditionally, but you can easily write
* more flexible merge policies.
*
* @param mergeFunction a merge function, used to resolve collisions between
* values associated with the same key, as supplied
* to {@link Map#merge(Object, Object, BiFunction)}
* @return a {@code ConcurrentMap} whose keys are taken from this stream
*
* @see #toConcurrentMap()
* @see #toMap(BinaryOperator)
*/
public Map<K, V> toConcurrentMap(BinaryOperator<V> mergeFunction) {
return inner.collect(Collectors.toConcurrentMap(
Map.Entry::getKey,
Map.Entry::getValue,
mergeFunction
));
}
代码示例来源:origin: speedment/speedment
return inner.collect(Collectors.toConcurrentMap(
Map.Entry::getKey,
Map.Entry::getValue,
代码示例来源:origin: spring-projects/spring-security
/**
* Creates a new instance
* @param users the {@link UserDetails} to use
*/
public MapReactiveUserDetailsService(Collection<UserDetails> users) {
Assert.notEmpty(users, "users cannot be null or empty");
this.users = users.stream().collect(Collectors.toConcurrentMap( u -> getKey(u.getUsername()), Function.identity()));
}
代码示例来源:origin: speedment/speedment
return inner.collect(Collectors.toConcurrentMap(
Map.Entry::getKey,
Map.Entry::getValue,
代码示例来源:origin: org.springframework.security/spring-security-core
/**
* Creates a new instance
* @param users the {@link UserDetails} to use
*/
public MapReactiveUserDetailsService(Collection<UserDetails> users) {
Assert.notEmpty(users, "users cannot be null or empty");
this.users = users.stream().collect(Collectors.toConcurrentMap( u -> getKey(u.getUsername()), Function.identity()));
}
代码示例来源:origin: speedment/speedment
/**
* Accumulates all key-value pairs of this {@code MapStream} into a
* {@code ConcurrentNavigableMap}, sorting the entries by applying the
* specified comparator to the keys of the stream.
* <p>
* If the mapped keys contains duplicates (according to
* {@link Object#equals(Object)}), an {@code IllegalStateException} is
* thrown when the collection operation is performed. If the mapped keys
* may have duplicates, use {@link #toConcurrentNavigableMap(Comparator, BinaryOperator)}
* instead.
*
* @param keyComparator the comparator to use when sorting the keys
* @return a {@code ConcurrentNavigableMap} whose keys and
* values are identical to the entries of this stream
*
* @see #toMap(BinaryOperator)
* @see #toConcurrentMap()
* @see #toSortedMap()
*/
public ConcurrentNavigableMap<K, V> toConcurrentNavigableMapByKey(Comparator<K> keyComparator) {
return inner.collect(Collectors.toConcurrentMap(
Map.Entry::getKey,
Map.Entry::getValue,
throwingMerger(),
() -> new ConcurrentSkipListMap<>(keyComparator)
));
}
代码示例来源:origin: speedment/speedment
/**
* Accumulates all key-value pairs of this {@code MapStream} into a
* {@code ConcurrentNavigableMap}.
* <p>
* If the mapped keys contains duplicates (according to
* {@link Object#equals(Object)}), an {@code IllegalStateException} is
* thrown when the collection operation is performed. If the mapped keys
* may have duplicates, use {@link #toConcurrentNavigableMap(BinaryOperator)}
* instead.
* <p>
* If the keys are not {@link Comparable}, a
* {@code java.lang.ClassCastException} may be thrown when the terminal
* operation is executed. It is therefore better to use
* {@link #toConcurrentNavigableMapByKey(Comparator)} since it allows you to specify
* a comparator to use when comparing the keys.
*
* @return a {@code ConcurrentNavigableMap} whose keys and values are
* identical to the entries of this stream
*
* @see #toMap(BinaryOperator)
* @see #toConcurrentMap()
*/
public ConcurrentNavigableMap<K, V> toConcurrentNavigableMap() {
return inner.collect(Collectors.toConcurrentMap(
Map.Entry::getKey,
Map.Entry::getValue,
throwingMerger(),
ConcurrentSkipListMap::new
));
}
代码示例来源:origin: pmd/pmd
/**
* Builds a new code area with the given enum type as layer id provider.
* Constants of the enum will identify layers of the code area.
*
* @param idEnum Enum type
*/
// the annotation lets the value be passed from FXML
public HighlightLayerCodeArea(@NamedArg("idEnum") Class<K> idEnum) {
super();
this.layersById = EnumSet.allOf(idEnum)
.stream()
.collect(Collectors.toConcurrentMap(id -> id, id -> new StyleLayer()));
}
代码示例来源:origin: blynkkk/blynk-server
.collect(Collectors.toConcurrentMap(UserKey::new, identity()));
} catch (Exception e) {
log.error("Error reading user profiles from disk. {}", e.getMessage());
代码示例来源:origin: HubSpot/Singularity
public void cacheRacks(List<SingularityRack> racks) {
this.racks = racks.stream().collect(Collectors.toConcurrentMap(SingularityRack::getId, Function.identity()));
}
public void stop() {
代码示例来源:origin: HubSpot/Singularity
public void cacheSlaves(List<SingularitySlave> slaves) {
this.slaves = slaves.stream().collect(Collectors.toConcurrentMap(SingularitySlave::getId, Function.identity()));
}
代码示例来源:origin: stackoverflow.com
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ParallelWordCount
{
public static void main(String[] args)
{
List<String> list = Arrays.asList(
"hello", "bye", "ciao", "bye", "ciao");
Map<String, Integer> counts = list.parallelStream().
collect(Collectors.toConcurrentMap(
w -> w, w -> 1, Integer::sum));
System.out.println(counts);
}
}
代码示例来源:origin: stackoverflow.com
Collectors.toConcurrentMap(
w -> w, w -> 1, Integer::sum));
bh.consume(counts);
代码示例来源:origin: owlcs/owlapi
/**
* @param s stream to turn to map. The stream is consumed by this operation.
* @param key function to create the key
* @param val function to create the value
* @param <K> type of key
* @param <V> type of value
* @param <Q> type of input
* @return map including all elements in the stream, keyed by key and valued by val
*/
public static <K, V, Q> Map<K, V> asMap(Stream<Q> s, Function<Q, K> key, Function<Q, V> val) {
return s.collect(Collectors.toConcurrentMap(key::apply, val::apply));
}
代码示例来源:origin: net.sourceforge.owlapi/owlapi-distribution
/**
* @param s stream to turn to map. The stream is consumed by this operation.
* @param key function to create the key
* @param val function to create the value
* @param <K> type of key
* @param <V> type of value
* @param <Q> type of input
* @return map including all elements in the stream, keyed by key and valued by val
*/
public static <K, V, Q> Map<K, V> asMap(Stream<Q> s, Function<Q, K> key, Function<Q, V> val) {
return s.collect(Collectors.toConcurrentMap(key::apply, val::apply));
}
代码示例来源:origin: net.sourceforge.owlapi/owlapi-osgidistribution
/**
* @param s stream to turn to map. The stream is consumed by this operation.
* @param key function to create the key
* @param val function to create the value
* @param <K> type of key
* @param <V> type of value
* @param <Q> type of input
* @return map including all elements in the stream, keyed by key and valued by val
*/
public static <K, V, Q> Map<K, V> asMap(Stream<Q> s, Function<Q, K> key, Function<Q, V> val) {
return s.collect(Collectors.toConcurrentMap(key::apply, val::apply));
}
代码示例来源:origin: PhoenicisOrg/phoenicis
@Override
public RepositoryDTO fetchInstallableApplications() {
LOGGER.info(String.format("Fetching applications for: %s", this.toString()));
/*
* This step is needed because we need a mapping between the CategoryDTO
* list and its application source, to preserve the order in the
* reduction step
*/
final Map<Repository, RepositoryDTO> repositoriesMap = this.repositories.stream().parallel()
.collect(Collectors.toConcurrentMap(source -> source, Repository::fetchInstallableApplications));
return mergeRepositories(repositoriesMap, repositories);
}
代码示例来源:origin: io.zeebe/zeebe-broker-core
@SuppressWarnings("unchecked")
private Map<String, byte[]> loadResources() {
return Arrays.stream(RESOURCE_NAMES)
.map(resourceName -> new Tuple<>(resourceName, loadResource(resourceName)))
.collect(Collectors.toConcurrentMap(Tuple::getLeft, Tuple::getRight));
}
代码示例来源:origin: zeebe-io/zeebe
@SuppressWarnings("unchecked")
private Map<String, byte[]> loadResources() {
return Arrays.stream(RESOURCE_NAMES)
.map(resourceName -> new Tuple<>(resourceName, loadResource(resourceName)))
.collect(Collectors.toConcurrentMap(Tuple::getLeft, Tuple::getRight));
}
内容来源于网络,如有侵权,请联系作者删除!