本文整理了Java中com.google.common.collect.Multimap.entries()
方法的一些代码示例,展示了Multimap.entries()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multimap.entries()
方法的具体详情如下:
包路径:com.google.common.collect.Multimap
类名称:Multimap
方法名:entries
[英]Returns a view collection of all key-value pairs contained in this multimap, as Entryinstances.
Changes to the returned collection or the entries it contains will update the underlying multimap, and vice versa. However, adding to the returned collection is not possible.
[中]以Entryinstances的形式返回此多重映射中包含的所有键值对的视图集合。
对返回的集合或其包含的条目所做的更改将更新基础多重映射,反之亦然。但是,无法添加到返回的集合中。
代码示例来源:origin: google/guava
@Override
public void forEach(Consumer<? super K> consumer) {
checkNotNull(consumer);
multimap.entries().forEach(entry -> consumer.accept(entry.getKey()));
}
代码示例来源:origin: google/guava
/**
* Performs the given action for all key-value pairs contained in this multimap. If an ordering is
* specified by the {@code Multimap} implementation, actions will be performed in the order of
* iteration of {@link #entries()}. Exceptions thrown by the action are relayed to the caller.
*
* <p>To loop over all keys and their associated value collections, write {@code
* Multimaps.asMap(multimap).forEach((key, valueCollection) -> action())}.
*
* @since 21.0
*/
default void forEach(BiConsumer<? super K, ? super V> action) {
checkNotNull(action);
entries().forEach(entry -> action.accept(entry.getKey(), entry.getValue()));
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public String getColumnLabel(final int columnIndex) throws SQLException {
for (Entry<String, Integer> entry : columnLabelAndIndexMap.entries()) {
if (columnIndex == entry.getValue()) {
return entry.getKey();
}
}
throw new SQLException("Column index out of range", "9999");
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public String getColumnLabel(final int columnIndex) throws SQLException {
for (Entry<String, Integer> entry : columnLabelAndIndexMap.entries()) {
if (columnIndex == entry.getValue()) {
return entry.getKey();
}
}
throw new SQLException("Column index out of range", "9999");
}
代码示例来源:origin: google/guava
@CanIgnoreReturnValue
@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
boolean changed = false;
for (Entry<? extends K, ? extends V> entry : multimap.entries()) {
changed |= put(entry.getKey(), entry.getValue());
}
return changed;
}
代码示例来源:origin: google/guava
/**
* Copies each key-value mapping in {@code source} into {@code dest}, with its key and value
* reversed.
*
* <p>If {@code source} is an {@link ImmutableMultimap}, consider using {@link
* ImmutableMultimap#inverse} instead.
*
* @param source any multimap
* @param dest the multimap to copy into; usually empty
* @return {@code dest}
*/
@CanIgnoreReturnValue
public static <K, V, M extends Multimap<K, V>> M invertFrom(
Multimap<? extends V, ? extends K> source, M dest) {
checkNotNull(dest);
for (Map.Entry<? extends V, ? extends K> entry : source.entries()) {
dest.put(entry.getValue(), entry.getKey());
}
return dest;
}
代码示例来源:origin: google/guava
@Override
public boolean remove(@Nullable Object o) {
Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
unfilteredItr.hasNext(); ) {
Entry<K, V> entry = unfilteredItr.next();
if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
unfilteredItr.remove();
return true;
}
}
return false;
}
代码示例来源:origin: wildfly/wildfly
@Override
public void forEach(Consumer<? super K> consumer) {
checkNotNull(consumer);
multimap.entries().forEach(entry -> consumer.accept(entry.getKey()));
}
代码示例来源:origin: ctripcorp/apollo
private void scanAndClean() {
Iterator<Multimap<String, SpringValue>> iterator = registry.values().iterator();
while (!Thread.currentThread().isInterrupted() && iterator.hasNext()) {
Multimap<String, SpringValue> springValues = iterator.next();
Iterator<Entry<String, SpringValue>> springValueIterator = springValues.entries().iterator();
while (springValueIterator.hasNext()) {
Entry<String, SpringValue> springValue = springValueIterator.next();
if (!springValue.getValue().isTargetBeanValid()) {
// clear unused spring values
springValueIterator.remove();
}
}
}
}
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testEntriesRemainValidAfterRemove() {
Iterator<Entry<K, V>> iterator = multimap().entries().iterator();
Entry<K, V> entry = iterator.next();
K key = entry.getKey();
V value = entry.getValue();
multimap().removeAll(key);
assertEquals(key, entry.getKey());
assertEquals(value, entry.getValue());
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Performs the given action for all key-value pairs contained in this multimap. If an ordering is
* specified by the {@code Multimap} implementation, actions will be performed in the order of
* iteration of {@link #entries()}. Exceptions thrown by the action are relayed to the caller.
*
* <p>To loop over all keys and their associated value collections, write {@code
* Multimaps.asMap(multimap).forEach((key, valueCollection) -> action())}.
*
* @since 21.0
*/
default void forEach(BiConsumer<? super K, ? super V> action) {
checkNotNull(action);
entries().forEach(entry -> action.accept(entry.getKey(), entry.getValue()));
}
代码示例来源:origin: thinkaurelius/titan
private void remove(String store, String docid, Multimap<String, Object> doc, boolean deleteAll) {
for (Map.Entry<String, Object> kv : doc.entries()) {
if (index.supports(allKeys.get(kv.getKey()))) {
tx.delete(store, docid, kv.getKey(), kv.getValue(), deleteAll);
}
}
}
代码示例来源:origin: google/j2objc
/**
* Copies each key-value mapping in {@code source} into {@code dest}, with its key and value
* reversed.
*
* <p>If {@code source} is an {@link ImmutableMultimap}, consider using {@link
* ImmutableMultimap#inverse} instead.
*
* @param source any multimap
* @param dest the multimap to copy into; usually empty
* @return {@code dest}
*/
@CanIgnoreReturnValue
public static <K, V, M extends Multimap<K, V>> M invertFrom(
Multimap<? extends V, ? extends K> source, M dest) {
checkNotNull(dest);
for (Map.Entry<? extends V, ? extends K> entry : source.entries()) {
dest.put(entry.getValue(), entry.getKey());
}
return dest;
}
代码示例来源:origin: google/j2objc
@CanIgnoreReturnValue
@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
boolean changed = false;
for (Entry<? extends K, ? extends V> entry : multimap.entries()) {
changed |= put(entry.getKey(), entry.getValue());
}
return changed;
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public String getColumnLabel(final int columnIndex) throws SQLException {
if (metaData.getAggregationDistinctColumnIndexes().contains(columnIndex)) {
return metaData.getAggregationDistinctColumnLabel(columnIndex);
}
for (Entry<String, Integer> entry : getColumnLabelAndIndexMap().entries()) {
if (columnIndex == entry.getValue()) {
return entry.getKey();
}
}
throw new SQLException("Column index out of range", "9999");
}
代码示例来源:origin: immutables/immutables
void preBuild() {
for (String exception : exceptions) {
@Nullable String qualifiedName = nameToQualified.get(exception);
if (qualifiedName != null) {
String asInCurrentPackage = currentPackagePrefix.concat(exception);
if (!qualifiedName.equals(asInCurrentPackage)) {
importCandidates.removeAll(qualifiedName);
}
}
}
for (Map.Entry<String, ImportCandidate> candidateEntry : importCandidates.entries()) {
ImportCandidate candidate = candidateEntry.getValue();
String originalFullyName = originalImports.get(candidate.simpleName);
if (originalFullyName != null && !originalFullyName.equals(candidate.preparedImport)) {
importCandidates.remove(candidateEntry.getKey(), candidateEntry.getValue());
}
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
/**
* Writes annotations as LI html elements
*/
private void writeAnnotations() {
String annotationFMT = "<li>%s</li>";
for (Map.Entry<String, String> annotation: writerAnnotations.entries()) {
print(String.format(annotationFMT, annotation.getValue()));
}
}
代码示例来源:origin: google/j2objc
@Override
public boolean remove(@NullableDecl Object o) {
Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
unfilteredItr.hasNext(); ) {
Entry<K, V> entry = unfilteredItr.next();
if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
unfilteredItr.remove();
return true;
}
}
return false;
}
代码示例来源:origin: JanusGraph/janusgraph
private void remove(String store, String documentId, Multimap<String, Object> doc, boolean deleteAll) {
for (final Map.Entry<String, Object> kv : doc.entries()) {
if (index.supports(allKeys.get(kv.getKey()))) {
tx.delete(store, documentId, kv.getKey(), kv.getValue(), deleteAll);
}
}
}
代码示例来源:origin: google/guava
public void testSize() {
int expectedSize = getNumElements();
Multimap<K, V> multimap = multimap();
assertEquals(expectedSize, multimap.size());
int size = 0;
for (Entry<K, V> entry : multimap.entries()) {
assertTrue(multimap.containsEntry(entry.getKey(), entry.getValue()));
size++;
}
assertEquals(expectedSize, size);
int size2 = 0;
for (Entry<K, Collection<V>> entry2 : multimap.asMap().entrySet()) {
size2 += entry2.getValue().size();
}
assertEquals(expectedSize, size2);
}
内容来源于网络,如有侵权,请联系作者删除!