Refine search
/** * 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())); }
/** * 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; }
@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; }
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(); } } } } }
@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()); } }
/** * 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())); }
/** * 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; }
@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"); }
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()); } } }
@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; }
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); }