/** * Computes the size of the store files for a single region. */ long getSizeOfStoreFile(TableName tn, StoreFileReference storeFileName) { String regionName = storeFileName.getRegionName(); return storeFileName.getFamilyToFilesMapping() .entries().stream() .collect(Collectors.summingLong((e) -> getSizeOfStoreFile(tn, regionName, e.getKey(), e.getValue()))); }
void partitionTablesByQuotaTarget(Multimap<TableName,QuotaSettings> quotas, Set<TableName> tablesWithTableQuota, Set<TableName> tablesWithNamespaceQuota) { // Partition the tables with quotas by table and ns quota for (Entry<TableName, QuotaSettings> entry : quotas.entries()) { SpaceLimitSettings settings = (SpaceLimitSettings) entry.getValue(); TableName tn = entry.getKey(); if (settings.getTableName() != null) { tablesWithTableQuota.add(tn); } if (settings.getNamespace() != null) { tablesWithNamespaceQuota.add(tn); } if (settings.getTableName() == null && settings.getNamespace() == null) { fail("Unexpected table name with null tableName and namespace: " + tn); } } }
@Test public void testFetchSpaceQuota() throws Exception { Multimap<TableName,QuotaSettings> tables = helper.createTablesWithSpaceQuotas(); // Can pass in an empty map, we're not consulting it. chore.initializeSnapshotStores(Collections.emptyMap()); // All tables that were created should have a quota defined. for (Entry<TableName,QuotaSettings> entry : tables.entries()) { final TableName table = entry.getKey(); final QuotaSettings qs = entry.getValue(); assertTrue("QuotaSettings was an instance of " + qs.getClass(), qs instanceof SpaceLimitSettings); SpaceQuota spaceQuota = null; if (qs.getTableName() != null) { spaceQuota = chore.getTableSnapshotStore().getSpaceQuota(table); assertNotNull("Could not find table space quota for " + table, spaceQuota); } else if (qs.getNamespace() != null) { spaceQuota = chore.getNamespaceSnapshotStore().getSpaceQuota(table.getNamespaceAsString()); assertNotNull("Could not find namespace space quota for " + table.getNamespaceAsString(), spaceQuota); } else { fail("Expected table or namespace space quota"); } final SpaceLimitSettings sls = (SpaceLimitSettings) qs; assertEquals(sls.getProto().getQuota(), spaceQuota); } TableName tableWithoutQuota = helper.createTable(); assertNull(chore.getTableSnapshotStore().getSpaceQuota(tableWithoutQuota)); }
@Override public Collection<Entry<K, V>> entries() { Collection<Entry<K, V>> result = entries; if (result == null) { entries = result = unmodifiableEntries(delegate.entries()); } return result; }
@Override public void forEach(Consumer<? super K> consumer) { checkNotNull(consumer); multimap.entries().forEach(entry -> consumer.accept(entry.getKey())); }
@Override public Collection<Map.Entry<K, V>> entries() { synchronized (mutex) { if (entries == null) { entries = typePreservingCollection(delegate().entries(), mutex); } return entries; } }
@Override public Iterator<K> iterator() { return Maps.keyIterator(multimap.entries().iterator()); }
@Override public Collection<Entry<K, V>> entries() { return delegate().entries(); }
@Override Collection<Entry<K, V>> createEntries() { return filterCollection(unfiltered.entries(), predicate); }
/** * 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())); }
@CanIgnoreReturnValue @Override public boolean putAll(Multimap<? extends K, ? extends V> multimap) { boolean changed = false; for (Map.Entry<? extends K, ? extends V> entry : multimap.entries()) { changed |= put(entry.getKey(), entry.getValue()); } return changed; }
@Override Iterator<Entry<K, V2>> entryIterator() { return Iterators.transform( fromMultimap.entries().iterator(), Maps.<K, V1, V2>asEntryToEntryFunction(transformer)); }
@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(); ) { Map.Entry<K, V> entry = unfilteredItr.next(); if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) { unfilteredItr.remove(); return true; } } return false; }
private String computeToString() { StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype); if (!parameters.isEmpty()) { builder.append("; "); Multimap<String, String> quotedParameters = Multimaps.transformValues( parameters, new Function<String, String>() { @Override public String apply(String value) { return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value); } }); PARAMETER_JOINER.appendTo(builder, quotedParameters.entries()); } return builder.toString(); }
@Override Collection<V2> createValues() { return Collections2.transform( fromMultimap.entries(), Maps.<K, V1, V2>asEntryToValueFunction(transformer)); } }
@Override public Spliterator<K> spliterator() { return CollectSpliterators.map(multimap.entries().spliterator(), Map.Entry::getKey); }
private static MediaType create( String type, String subtype, Multimap<String, String> parameters) { checkNotNull(type); checkNotNull(subtype); checkNotNull(parameters); String normalizedType = normalizeToken(type); String normalizedSubtype = normalizeToken(subtype); checkArgument( !WILDCARD.equals(normalizedType) || WILDCARD.equals(normalizedSubtype), "A wildcard type cannot be used with a non-wildcard subtype"); ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); for (Entry<String, String> entry : parameters.entries()) { String attribute = normalizeToken(entry.getKey()); builder.put(attribute, normalizeParameterValue(attribute, entry.getValue())); } MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build()); // Return one of the constants if the media type is a known type. return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType); }
@Override public boolean removeAll(Collection<?> c) { return Iterables.removeIf( multimap.unfiltered().entries(), // explicit <Entry<K, V>> is required to build with JDK6 Predicates.<Entry<K, V>>and( multimap.entryPredicate(), Maps.<V>valuePredicateOnEntries(Predicates.in(c)))); }
void partitionTablesByQuotaTarget(Multimap<TableName,QuotaSettings> quotas, Set<TableName> tablesWithTableQuota, Set<TableName> tablesWithNamespaceQuota) { // Partition the tables with quotas by table and ns quota for (Entry<TableName, QuotaSettings> entry : quotas.entries()) { SpaceLimitSettings settings = (SpaceLimitSettings) entry.getValue(); TableName tn = entry.getKey(); if (settings.getTableName() != null) { tablesWithTableQuota.add(tn); } if (settings.getNamespace() != null) { tablesWithNamespaceQuota.add(tn); } if (settings.getTableName() == null && settings.getNamespace() == null) { fail("Unexpected table name with null tableName and namespace: " + tn); } } }
@Override public boolean retainAll(Collection<?> c) { return Iterables.removeIf( multimap.unfiltered().entries(), // explicit <Entry<K, V>> is required to build with JDK6 Predicates.<Entry<K, V>>and( multimap.entryPredicate(), Maps.<V>valuePredicateOnEntries(Predicates.not(Predicates.in(c))))); }