@Override SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) { multimap.put("one", 314); multimap.put("two", 159); multimap.put("one", 265); return Multimaps.filterValues( multimap, Predicates.not(Predicates.in(ImmutableSet.of(314, 159, 265)))); } })
public void testFilterFiltered() { Multimap<String, Integer> unfiltered = HashMultimap.create(); unfiltered.put("foo", 55556); unfiltered.put("badkey", 1); unfiltered.put("foo", 1); Multimap<String, Integer> keyFiltered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE); Multimap<String, Integer> filtered = Multimaps.filterValues(keyFiltered, VALUE_PREDICATE); assertEquals(1, filtered.size()); assertTrue(filtered.containsEntry("foo", 1)); assertTrue(filtered.keySet().retainAll(Arrays.asList("cat", "dog"))); assertEquals(0, filtered.size()); }
private Set<String> filterCommands(final CommandSource src, String start) { ListMultimap<String, CommandMapping> map = Multimaps.filterKeys(this.commands, input -> input != null && input.toLowerCase().startsWith(start.toLowerCase())); return Multimaps.filterValues(map, input -> input.getCallable().testPermission(src)).keys().elementSet(); }
public void testFilterValues() { Multimap<String, Integer> unfiltered = HashMultimap.create(); unfiltered.put("foo", 55556); unfiltered.put("badkey", 1); Multimap<String, Integer> filtered = Multimaps.filterValues(unfiltered, VALUE_PREDICATE); assertEquals(1, filtered.size()); assertFalse(filtered.containsEntry("foo", 55556)); assertTrue(filtered.containsEntry("badkey", 1)); }
private Set<String> filterCommands(final CommandSource src) { return Multimaps.filterValues(this.commands, input -> input.getCallable().testPermission(src)).keys().elementSet(); }
private Set<String> filterCommands(final CommandSource src) { return Multimaps.filterValues(this.dispatcher.getAll(), input -> input != null && input.getCallable().testPermission(src) ) .keys() .elementSet(); }
private void scrubCells(TransactionManager txManager, Multimap<TableReference, Cell> tableNameToCells, long scrubTimestamp, Transaction.TransactionType transactionType) { Map<TableReference, Multimap<Cell, Long>> allCellsToMarkScrubbed = Maps.newHashMapWithExpectedSize(tableNameToCells.keySet().size()); for (Entry<TableReference, Collection<Cell>> entry : tableNameToCells.asMap().entrySet()) { TableReference tableRef = entry.getKey(); log.debug("Attempting to immediately scrub {} cells from table {}", entry.getValue().size(), tableRef); for (List<Cell> cells : Iterables.partition(entry.getValue(), batchSizeSupplier.get())) { Multimap<Cell, Long> allTimestamps = keyValueService.getAllTimestamps( tableRef, ImmutableSet.copyOf(cells), scrubTimestamp); Multimap<Cell, Long> timestampsToDelete = Multimaps.filterValues( allTimestamps, v -> !v.equals(Value.INVALID_VALUE_TIMESTAMP)); // If transactionType == TransactionType.AGGRESSIVE_HARD_DELETE this might // force other transactions to abort or retry deleteCellsAtTimestamps(txManager, tableRef, timestampsToDelete, transactionType); Multimap<Cell, Long> cellsToMarkScrubbed = HashMultimap.create(allTimestamps); for (Cell cell : cells) { cellsToMarkScrubbed.put(cell, scrubTimestamp); } allCellsToMarkScrubbed.put(tableRef, cellsToMarkScrubbed); } log.debug("Immediately scrubbed {} cells from table {}", entry.getValue().size(), tableRef); } scrubberStore.markCellsAsScrubbed(allCellsToMarkScrubbed, batchSizeSupplier.get()); }
private Link(Builder builder) { uriReference = Objects.requireNonNull(builder.uriReference); linkParams = ImmutableListMultimap.copyOf(Multimaps.filterValues(builder.linkParams, Objects::nonNull)); }
public Multimap<Table, LoadConstraint> getLoadConstraints(final MetaDataType... objectTypes) { return filterValues(getLoadConstraints(), new Predicate<LoadConstraint>() { @Override public boolean apply(LoadConstraint loadConstraint) { return contains(objectTypes, loadConstraint.getConstraint().getObjectType()); } }); } }
@Override protected void removeRegistration() { final ListenerRegistration<T> me = this; synchronized (DOMNotificationRouter.this) { replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, new Predicate<ListenerRegistration<? extends DOMNotificationListener>>() { @Override public boolean apply(final ListenerRegistration<? extends DOMNotificationListener> input) { return input != me; } }))); } } };
@Override public void release(MachineLocation task) { String id = task.getId(); Set<MachineProvisioningLocation> set = Multimaps.filterValues(tasks, Predicates.equalTo(id)).keySet(); if (set.isEmpty()) { throw new IllegalArgumentException("Request to release "+task+", but not currently allocated"); } MachineProvisioningLocation framework = Iterables.getOnlyElement(set); LOG.debug("Request to remove task mapping {} to {}", framework, id); framework.release(task); tasks.remove(framework, id); }
private void scrubCells(TransactionManager txManager, Multimap<TableReference, Cell> tableNameToCells, long scrubTimestamp, Transaction.TransactionType transactionType) { Map<TableReference, Multimap<Cell, Long>> allCellsToMarkScrubbed = Maps.newHashMapWithExpectedSize(tableNameToCells.keySet().size()); for (Entry<TableReference, Collection<Cell>> entry : tableNameToCells.asMap().entrySet()) { TableReference tableRef = entry.getKey(); log.debug("Attempting to immediately scrub {} cells from table {}", entry.getValue().size(), tableRef); for (List<Cell> cells : Iterables.partition(entry.getValue(), batchSizeSupplier.get())) { Multimap<Cell, Long> allTimestamps = keyValueService.getAllTimestamps( tableRef, ImmutableSet.copyOf(cells), scrubTimestamp); Multimap<Cell, Long> timestampsToDelete = Multimaps.filterValues( allTimestamps, v -> !v.equals(Value.INVALID_VALUE_TIMESTAMP)); // If transactionType == TransactionType.AGGRESSIVE_HARD_DELETE this might // force other transactions to abort or retry deleteCellsAtTimestamps(txManager, tableRef, timestampsToDelete, transactionType); Multimap<Cell, Long> cellsToMarkScrubbed = HashMultimap.create(allTimestamps); for (Cell cell : cells) { cellsToMarkScrubbed.put(cell, scrubTimestamp); } allCellsToMarkScrubbed.put(tableRef, cellsToMarkScrubbed); } log.debug("Immediately scrubbed {} cells from table {}", entry.getValue().size(), tableRef); } scrubberStore.markCellsAsScrubbed(allCellsToMarkScrubbed, batchSizeSupplier.get()); }
@Override public void release(MachineLocation machine) { if (provisioner == null) { throw new IllegalStateException("No provisioner available to release "+machine); } String id = machine.getId(); Set<DockerHostLocation> set = Multimaps.filterValues(containers, Predicates.equalTo(id)).keySet(); if (set.isEmpty()) { throw new IllegalArgumentException("Request to release "+machine+", but this machine is not currently allocated"); } DockerHostLocation host = Iterables.getOnlyElement(set); LOG.debug("Request to remove container mapping {} to {}", host, id); host.release((DockerContainerLocation) machine); if (containers.remove(host, id)) { if (containers.get(host).isEmpty()) { LOG.debug("Empty Docker host: {}", host); // Remove hosts when it has no containers, except for the last one if (infrastructure.config().get(DockerInfrastructure.REMOVE_EMPTY_DOCKER_HOSTS) && set.size() > 1) { LOG.info("Removing empty Docker host: {}", host); remove(host); } } } else { throw new IllegalArgumentException("Request to release "+machine+", but container mapping not found"); } }
@Override public Multimap<Long, Interval> getIntervalsPerProductionLine(final TimeGapsContext context) { Multimap<Long, Interval> intervals = HashMultimap.create(); Set<Order> orders = buildOrders(orderIntervalsModelHelper.getOrdersProjection(context)); intervals.putAll(ordersToIntervals(orders)); Multimap<Long, Interval> changeoverIntervals = getChangeovers(getGaps(groupedByStartDate(orders))); intervals.putAll(changeoverIntervals); Multimap<Long, Interval> filteredIntervals = Multimaps.filterValues(intervals, new Predicate<Interval>() { @Override public boolean apply(final Interval interval) { return context.getInterval().overlaps(interval); } }); return Multimaps.unmodifiableMultimap(filteredIntervals); }
private Set<String> filterCommands(final CommandSource src) { return Multimaps.filterValues(this.commands, input -> input.getCallable().testPermission(src)).keys().elementSet(); }
public void testFilterFiltered() { Multimap<String, Integer> unfiltered = HashMultimap.create(); unfiltered.put("foo", 55556); unfiltered.put("badkey", 1); unfiltered.put("foo", 1); Multimap<String, Integer> keyFiltered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE); Multimap<String, Integer> filtered = Multimaps.filterValues(keyFiltered, VALUE_PREDICATE); assertEquals(1, filtered.size()); assertTrue(filtered.containsEntry("foo", 1)); assertTrue(filtered.keySet().retainAll(Arrays.asList("cat", "dog"))); assertEquals(0, filtered.size()); }
private Set<String> filterCommands(final CommandSource src) { return Multimaps.filterValues(this.dispatcher.getAll(), input -> input != null && input.getCallable().testPermission(src)).keys().elementSet(); }
public void testFilterValues() { Multimap<String, Integer> unfiltered = HashMultimap.create(); unfiltered.put("foo", 55556); unfiltered.put("badkey", 1); Multimap<String, Integer> filtered = Multimaps.filterValues(unfiltered, VALUE_PREDICATE); assertEquals(1, filtered.size()); assertFalse(filtered.containsEntry("foo", 55556)); assertTrue(filtered.containsEntry("badkey", 1)); }
@Override public void release(MachineLocation machine) { Set<StubHostLocation> set = Multimaps.filterValues(containers, Predicates.equalTo(machine.getId())).keySet(); StubHostLocation hostLocation = Iterables.getOnlyElement(set); hostLocation.release((StubContainerLocation)machine); containers.remove(hostLocation, machine); }
private void validateRepeatedScopedDeclarations( ValidationReport.Builder<TypeElement> report, ComponentDescriptor component, // TODO(ronshapiro): optimize ModuleDescriptor.hashCode()/equals. Otherwise this could be // quite costly SetMultimap<ComponentDescriptor, ModuleDescriptor> modulesWithScopes) { ImmutableSet<ModuleDescriptor> modules = component.modules().stream().filter(this::hasScopedDeclarations).collect(toImmutableSet()); modulesWithScopes.putAll(component, modules); for (ComponentDescriptor childComponent : component.childComponents()) { validateRepeatedScopedDeclarations(report, childComponent, modulesWithScopes); } modulesWithScopes.removeAll(component); SetMultimap<ComponentDescriptor, ModuleDescriptor> repeatedModules = Multimaps.filterValues(modulesWithScopes, modules::contains); if (repeatedModules.isEmpty()) { return; } report.addError( repeatedModulesWithScopeError(component, ImmutableSetMultimap.copyOf(repeatedModules))); }