本文整理了Java中com.google.common.collect.Maps.immutableEntry()
方法的一些代码示例,展示了Maps.immutableEntry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.immutableEntry()
方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:immutableEntry
[英]Returns an immutable map entry with the specified key and value. The Entry#setValue operation throws an UnsupportedOperationException.
The returned entry is serializable.
[中]返回具有指定键和值的不可变映射项。条目#setValue操作抛出一个不支持的操作Exception。
返回的条目是可序列化的。
代码示例来源:origin: google/guava
@Override
public boolean apply(Entry<V, K> input) {
return forwardPredicate.apply(Maps.immutableEntry(input.getValue(), input.getKey()));
}
};
代码示例来源:origin: google/guava
@Override
public Entry<K, V> next() {
if (!valueItr.hasNext()) {
Entry<K, ? extends ImmutableCollection<V>> entry = asMapItr.next();
currentKey = entry.getKey();
valueItr = entry.getValue().iterator();
}
return Maps.immutableEntry(currentKey, valueItr.next());
}
};
代码示例来源:origin: google/j2objc
private static <K, V> Predicate<Entry<V, K>> inversePredicate(
final Predicate<? super Entry<K, V>> forwardPredicate) {
return new Predicate<Entry<V, K>>() {
@Override
public boolean apply(Entry<V, K> input) {
return forwardPredicate.apply(Maps.immutableEntry(input.getValue(), input.getKey()));
}
};
}
代码示例来源:origin: prestodb/presto
public Assignments rewrite(Function<Expression, Expression> rewrite)
{
return assignments.entrySet().stream()
.map(entry -> Maps.immutableEntry(entry.getKey(), rewrite.apply(entry.getValue())))
.collect(toAssignments());
}
代码示例来源:origin: google/guava
boolean removeEntriesIf(Predicate<? super Entry<K, Collection<V>>> predicate) {
Iterator<Entry<K, Collection<V>>> entryIterator = unfiltered.asMap().entrySet().iterator();
boolean changed = false;
while (entryIterator.hasNext()) {
Entry<K, Collection<V>> entry = entryIterator.next();
K key = entry.getKey();
Collection<V> collection = filterCollection(entry.getValue(), new ValuePredicate(key));
if (!collection.isEmpty() && predicate.apply(Maps.immutableEntry(key, collection))) {
if (collection.size() == entry.getValue().size()) {
entryIterator.remove();
} else {
collection.clear();
}
changed = true;
}
}
return changed;
}
代码示例来源:origin: wildfly/wildfly
@Override
public boolean apply(Entry<V, K> input) {
return forwardPredicate.apply(Maps.immutableEntry(input.getValue(), input.getKey()));
}
};
代码示例来源:origin: google/j2objc
@Override
public Entry<K, V> next() {
if (!valueItr.hasNext()) {
Entry<K, ? extends ImmutableCollection<V>> entry = asMapItr.next();
currentKey = entry.getKey();
valueItr = entry.getValue().iterator();
}
return Maps.immutableEntry(currentKey, valueItr.next());
}
};
代码示例来源:origin: wildfly/wildfly
@Override
public Entry<K, V> next() {
if (!valueItr.hasNext()) {
Entry<K, ? extends ImmutableCollection<V>> entry = asMapItr.next();
currentKey = entry.getKey();
valueItr = entry.getValue().iterator();
}
return Maps.immutableEntry(currentKey, valueItr.next());
}
};
代码示例来源:origin: atomix/atomix
public TranscodingAsyncDistributedMap(
AsyncDistributedMap<K2, V2> backingMap,
Function<K1, K2> keyEncoder,
Function<K2, K1> keyDecoder,
Function<V1, V2> valueEncoder,
Function<V2, V1> valueDecoder) {
super(backingMap);
this.backingMap = backingMap;
this.keyEncoder = k -> k == null ? null : keyEncoder.apply(k);
this.keyDecoder = k -> k == null ? null : keyDecoder.apply(k);
this.valueEncoder = v -> v == null ? null : valueEncoder.apply(v);
this.valueDecoder = v -> v == null ? null : valueDecoder.apply(v);
this.entryDecoder = e -> e == null ? null : Maps.immutableEntry(keyDecoder.apply(e.getKey()), valueDecoder.apply(e.getValue()));
this.entryEncoder = e -> e == null ? null : Maps.immutableEntry(keyEncoder.apply(e.getKey()), valueEncoder.apply(e.getValue()));
}
代码示例来源:origin: google/guava
ImmutableMap<Service, Long> startupTimes() {
List<Entry<Service, Long>> loadTimes;
monitor.enter();
try {
loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
// N.B. There will only be an entry in the map if the service has started
for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
Service service = entry.getKey();
Stopwatch stopWatch = entry.getValue();
if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
}
}
} finally {
monitor.leave();
}
Collections.sort(
loadTimes,
Ordering.natural()
.onResultOf(
new Function<Entry<Service, Long>, Long>() {
@Override
public Long apply(Entry<Service, Long> input) {
return input.getValue();
}
}));
return ImmutableMap.copyOf(loadTimes);
}
代码示例来源:origin: google/j2objc
boolean removeEntriesIf(Predicate<? super Entry<K, Collection<V>>> predicate) {
Iterator<Entry<K, Collection<V>>> entryIterator = unfiltered.asMap().entrySet().iterator();
boolean changed = false;
while (entryIterator.hasNext()) {
Entry<K, Collection<V>> entry = entryIterator.next();
K key = entry.getKey();
Collection<V> collection = filterCollection(entry.getValue(), new ValuePredicate(key));
if (!collection.isEmpty() && predicate.apply(Maps.immutableEntry(key, collection))) {
if (collection.size() == entry.getValue().size()) {
entryIterator.remove();
} else {
collection.clear();
}
changed = true;
}
}
return changed;
}
代码示例来源:origin: immutables/immutables
FromSupertype(String type, Iterable<ValueAttribute> attribute) {
this.type = type;
this.hasGenerics = type.indexOf('<') > 0;
Entry<String, List<String>> withArgs = SourceTypes.extract(type);
this.raw = withArgs.getKey();
this.wildcard = hasGenerics
? SourceTypes.stringify(Maps.immutableEntry(withArgs.getKey(),
Collections.nCopies(withArgs.getValue().size(), "?")))
: type;
this.attributes = ImmutableList.copyOf(attribute);
}
代码示例来源:origin: google/guava
@Override
Spliterator<Entry<K, V>> entrySpliterator() {
return CollectSpliterators.flatMap(
map.entrySet().spliterator(),
keyToValueCollectionEntry -> {
K key = keyToValueCollectionEntry.getKey();
Collection<V> valueCollection = keyToValueCollectionEntry.getValue();
return CollectSpliterators.map(
valueCollection.spliterator(), (V value) -> Maps.immutableEntry(key, value));
},
Spliterator.SIZED,
size());
}
代码示例来源:origin: SonarSource/sonarqube
private static Map<String, WsProjectResponse.FileDataByPath> buildFileDataByModuleAndPath(MultiModuleProjectRepository data) {
return data.repositoriesByModule().entrySet()
.stream()
.map(entry -> Maps.immutableEntry(entry.getKey(), buildFileDataByPath(entry.getValue().fileData())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
代码示例来源:origin: atomix/atomix
private Map.Entry<K, V> convertEntry(Map.Entry<K, Versioned<V>> entry) {
return entry == null ? null : Maps.immutableEntry(entry.getKey(), Versioned.valueOrNull(entry.getValue()));
}
代码示例来源:origin: prestodb/presto
.map(entry -> Maps.immutableEntry(entry.getKey(), new HashMap<>(entry.getValue())))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
for (Entry<String, Map<String, String>> catalogProperties : this.unprocessedCatalogProperties.entrySet()) {
String catalog = catalogProperties.getKey();
for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) {
connectorProperties.computeIfAbsent(catalog, id -> new HashMap<>())
.put(entry.getKey(), entry.getValue());
代码示例来源:origin: atomix/atomix
public TranscodingAsyncAtomicMap(
AsyncAtomicMap<K2, V2> backingMap,
Function<K1, K2> keyEncoder,
Function<K2, K1> keyDecoder,
Function<V1, V2> valueEncoder,
Function<V2, V1> valueDecoder) {
super(backingMap);
this.backingMap = backingMap;
this.keyEncoder = k -> k == null ? null : keyEncoder.apply(k);
this.keyDecoder = k -> k == null ? null : keyDecoder.apply(k);
this.valueEncoder = v -> v == null ? null : valueEncoder.apply(v);
this.valueDecoder = v -> v == null ? null : valueDecoder.apply(v);
this.versionedValueDecoder = v -> v == null ? null : v.map(valueDecoder);
this.versionedValueEncoder = v -> v == null ? null : v.map(valueEncoder);
this.entryDecoder = e -> e == null ? null : Maps.immutableEntry(keyDecoder.apply(e.getKey()), versionedValueDecoder.apply(e.getValue()));
this.entryEncoder = e -> e == null ? null : Maps.immutableEntry(keyEncoder.apply(e.getKey()), versionedValueEncoder.apply(e.getValue()));
}
代码示例来源:origin: atomix/atomix
@Override
public Set<Map.Entry<K, Versioned<byte[]>>> entrySet() {
return entries().entrySet().stream()
.filter(entry -> entry.getValue().type() != MapEntryValue.Type.TOMBSTONE)
.map(e -> Maps.immutableEntry(e.getKey(), toVersioned(e.getValue())))
.collect(Collectors.toSet());
}
代码示例来源:origin: google/guava
@Override
Spliterator<Entry<K, V>> entrySpliterator() {
return CollectSpliterators.flatMap(
asMap().entrySet().spliterator(),
keyToValueCollectionEntry -> {
K key = keyToValueCollectionEntry.getKey();
Collection<V> valueCollection = keyToValueCollectionEntry.getValue();
return CollectSpliterators.map(
valueCollection.spliterator(), (V value) -> Maps.immutableEntry(key, value));
},
Spliterator.SIZED | (this instanceof SetMultimap ? Spliterator.DISTINCT : 0),
size());
}
代码示例来源:origin: atomix/atomix
private Map.Entry<K, Versioned<byte[]>> toVersionedEntry(
Map.Entry<K, MapEntryValue> entry) {
return entry == null || valueIsNull(entry.getValue())
? null : Maps.immutableEntry(entry.getKey(), toVersioned(entry.getValue()));
}
内容来源于网络,如有侵权,请联系作者删除!