List of usage examples for com.google.common.collect Multimaps filterValues
@CheckReturnValue public static <K, V> SetMultimap<K, V> filterValues(SetMultimap<K, V> unfiltered, final Predicate<? super V> valuePredicate)
From source file:google.registry.rde.RdeStagingAction.java
@Override public void run() { ImmutableSetMultimap<String, PendingDeposit> pendings = ImmutableSetMultimap.copyOf( Multimaps.filterValues(pendingDepositChecker.getTldsAndWatermarksPendingDepositForRdeAndBrda(), new Predicate<PendingDeposit>() { @Override public boolean apply(PendingDeposit pending) { if (clock.nowUtc().isBefore(pending.watermark().plus(transactionCooldown))) { logger.infofmt("Ignoring within %s cooldown: %s", transactionCooldown, pending); return false; } else { return true; }/* w ww . j ava 2 s . co m*/ } })); if (pendings.isEmpty()) { String message = "Nothing needs to be deposited"; logger.info(message); response.setStatus(SC_NO_CONTENT); response.setPayload(message); return; } for (PendingDeposit pending : pendings.values()) { logger.infofmt("%s", pending); } response.sendJavaScriptRedirect(createJobPath(mrRunner.setJobName("Stage escrow deposits for all TLDs") .setModuleName("backend").setDefaultReduceShards(pendings.size()) .runMapreduce(new RdeStagingMapper(pendings), reducer, ImmutableList.of( // Add an extra shard that maps over a null resource. See the mapper code for why. new NullInput<EppResource>(), EppResourceInputs.createEntityInput(EppResource.class))))); }
From source file:brooklyn.location.docker.DockerLocation.java
@Override public void release(MachineLocation machine) { if (provisioner == null) { throw new IllegalStateException("No provisioner available to release " + machine); }/* w w w . j a v a 2 s.c o m*/ 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); if (LOG.isDebugEnabled()) { LOG.debug("Request to remove container mapping {} to {}", host, id); } host.release((DockerContainerLocation) machine); if (containers.remove(host, id)) { if (containers.get(host).isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Empty Docker host: {}", host); } // Remove hosts when it has no containers, except for the last one if (getOwner().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"); } }
From source file:net.foxdenstudio.sponge.foxcore.plugin.command.FCCommandDispatcher.java
private Set<CommandMapping> filterCommandMappings(final CommandSource src) { return new HashSet<>( Multimaps.filterValues(this.commands, input -> input.getCallable().testPermission(src)).values()); }
From source file:clocker.docker.location.DockerLocation.java
@Override public void release(MachineLocation machine) { if (provisioner == null) { throw new IllegalStateException("No provisioner available to release " + machine); }//from w w w . j ava 2 s.c o m 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"); } }
From source file:org.voltcore.agreement.AgreementSeeker.java
/** * Walk the alive graph to see if there is a connected path between origins, * and destinations// www . ja v a 2 s . c om * @param destinations set of sites that we are looking a path to * @param origins set of sites that we are looking a path from * @return true origins have path to destinations */ protected boolean seenByInterconnectedPeers(Set<Long> destinations, Set<Long> origins) { Set<Long> seers = Multimaps.filterValues(m_alive, in(origins)).keySet(); int before = origins.size(); origins.addAll(seers); if (origins.containsAll(destinations)) { return true; } else if (origins.size() == before) { return false; } return seenByInterconnectedPeers(destinations, origins); }
From source file:uk.jamierocks.zinc.ZincDispatcher.java
private Set<String> filterCommands(final CommandSource src) { return Multimaps.filterValues(this.commands, input -> input.getCallable().testPermission(src)).keys() .elementSet();/*from w ww .ja va 2s . co m*/ }
From source file:org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin.java
/** * Returns a new instance of EMF Compare adapter factory descriptor registry to which extension will be * registered. It filters available adapter factories using preferences. * /*from w ww. j av a 2 s .co m*/ * @return the the adapter factory descriptor registry to which extension will be registered * @since 2.3 */ public RankedAdapterFactoryDescriptor.Registry createFilteredAdapterFactoryRegistry() { final List<String> disabledAdapterFactories = EMFComparePreferences .getDisabledAdapterFacotryDescriptorIds(getEMFComparePreferences()); // Filters disabled adapter factories Multimap<Collection<?>, RankedAdapterFactoryDescriptor> filteredBackingMultimap = ImmutableMultimap .copyOf(Multimaps.filterValues(adapterFactoryRegistryBackingMultimap, new Predicate<RankedAdapterFactoryDescriptor>() { public boolean apply(RankedAdapterFactoryDescriptor input) { return !disabledAdapterFactories.contains(input.getId()); } })); return new RankedAdapterFactoryDescriptorRegistryImpl(ComposedAdapterFactory.Descriptor.Registry.INSTANCE, filteredBackingMultimap); }