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:ome.services.blitz.repo.path.FilePathRestrictions.java
/** * Minimally adjust a set of rules to include transformations away from Unicode control characters. * @param rules a set of rules//from w ww . ja v a2 s . com * @return the given rules with full coverage for preventing control characters */ private static FilePathRestrictions includeControlTransformations(FilePathRestrictions rules) { final Set<Character> safeCharacters = new HashSet<Character>(rules.safeCharacters.size()); final Set<Integer> safeCodePoints = new HashSet<Integer>(rules.safeCharacters.size()); for (final Character safeCharacter : rules.safeCharacters) { final int safeCodePoint = FilePathRestrictionInstance.getCodePoint(safeCharacter); if (!controlCodePoints.contains(safeCodePoint)) { safeCharacters.add(safeCharacter); safeCodePoints.add(safeCodePoint); } } final SetMultimap<Integer, Integer> newTransformationMatrix = HashMultimap .create(Multimaps.filterValues(rules.transformationMatrix, isNotControlCodePoint)); for (final int controlCodePoint : controlCodePoints) { if (!newTransformationMatrix.containsKey(controlCodePoint)) { if (rules.transformationMatrix.containsKey(controlCodePoint)) { throw new IllegalArgumentException( "only control character mappings available for Unicode code point " + controlCodePoint); } newTransformationMatrix.putAll(controlCodePoint, safeCodePoints); } } return combineRules(rules, new FilePathRestrictions(newTransformationMatrix, null, null, null, safeCharacters)); }
From source file:org.basepom.mojo.duplicatefinder.ResultCollector.java
public Map<String, Collection<ConflictResult>> getResults(final ConflictType type, final ConflictState state) { Multimap<String, ConflictResult> result = Multimaps.filterValues(results, new Predicate<ConflictResult>() { @Override//from ww w .ja v a 2 s . c om public boolean apply(@Nonnull ConflictResult conflictResult) { checkNotNull(conflictResult, "conflictResult is null"); return conflictResult.getConflictState() == state && conflictResult.getType() == type && !conflictResult.isExcepted(); } }); return ImmutableMap.copyOf(result.asMap()); }
From source file:net.minecraftforge.fml.common.discovery.ASMDataTable.java
public SetMultimap<String, ASMData> getAnnotationsFor(ModContainer container) { if (containerAnnotationData == null) { ImmutableMap.Builder<ModContainer, SetMultimap<String, ASMData>> mapBuilder = ImmutableMap .<ModContainer, SetMultimap<String, ASMData>>builder(); for (ModContainer cont : containers) { Multimap<String, ASMData> values = Multimaps.filterValues(globalAnnotationData, new ModContainerPredicate(cont)); mapBuilder.put(cont, ImmutableSetMultimap.copyOf(values)); }//from www. ja v a 2 s .com containerAnnotationData = mapBuilder.build(); } return containerAnnotationData.get(container); }
From source file:org.mitreid.multiparty.service.InMemoryResourceService.java
@Override public Resource getById(final String rsId) { Multimap<String, Resource> filtered = Multimaps.filterValues(resources, new Predicate<Resource>() { @Override// w ww .ja va 2 s. c om public boolean apply(Resource input) { if (input.getId().equals(rsId)) { return true; } else { return false; } } }); if (filtered.size() == 1) { return Iterators.getOnlyElement(filtered.values().iterator()); } else { return null; } }
From source file:com.android.tools.idea.sdk.SdkPackages.java
void setRemotePkgInfos(Multimap<PkgType, RemotePkgInfo> packages) { myRemotePkgInfos = Multimaps.filterValues(packages, new Predicate<RemotePkgInfo>() { @Override//w w w .j a v a2 s . c o m public boolean apply(RemotePkgInfo input) { return input.hasCompatibleArchive(); } }); computeUpdates(); }
From source file:dagger.internal.codegen.ComponentHierarchyValidator.java
/** * Checks that components do not have any scopes that are also applied on any of their ancestors. *///from ww w.ja va2s . c o m private void validateScopeHierarchy(ValidationReport.Builder<TypeElement> report, ComponentDescriptor subject, SetMultimap<ComponentDescriptor, Scope> scopesByComponent) { scopesByComponent.putAll(subject, subject.scopes()); for (ComponentDescriptor child : subject.subcomponents()) { validateScopeHierarchy(report, child, scopesByComponent); } scopesByComponent.removeAll(subject); Predicate<Scope> subjectScopes = subject.kind().isProducer() // TODO(beder): validate that @ProductionScope is only applied on production components ? and(in(subject.scopes()), not(equalTo(Scope.productionScope(elements)))) : in(subject.scopes()); SetMultimap<ComponentDescriptor, Scope> overlappingScopes = Multimaps.filterValues(scopesByComponent, subjectScopes); if (!overlappingScopes.isEmpty()) { StringBuilder error = new StringBuilder().append(subject.componentDefinitionType().getQualifiedName()) .append(" has conflicting scopes:"); for (Map.Entry<ComponentDescriptor, Scope> entry : overlappingScopes.entries()) { Scope scope = entry.getValue(); error.append("\n ").append(entry.getKey().componentDefinitionType().getQualifiedName()) .append(" also has ").append(scope.getReadableSource()); } report.addItem(error.toString(), compilerOptions.scopeCycleValidationType().diagnosticKind().get(), subject.componentDefinitionType()); } }
From source file:org.apache.brooklyn.core.location.dynamic.clocker.StubInfrastructureLocation.java
@Override public void release(MachineLocation machine) { Set<StubHostLocation> set = Multimaps.filterValues(containers, Predicates.equalTo(machine.getId())) .keySet();/*from w w w . j a va 2s . c o m*/ StubHostLocation hostLocation = Iterables.getOnlyElement(set); hostLocation.release((StubContainerLocation) machine); containers.remove(hostLocation, machine); }
From source file:org.spongepowered.api.util.command.args.ChildCommandElementExecutor.java
private Set<String> filterCommands(final CommandSource src) { return Multimaps.filterValues(this.dispatcher.getAll(), input -> input != null && input.getCallable().testPermission(src)).keys().elementSet(); }
From source file:org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.java
@Override public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener( final T listener, final Collection<SchemaPath> types) { final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) { @Override/*from ww w . jav a2 s. c om*/ 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; } }))); } } }; if (!types.isEmpty()) { final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap .builder(); b.putAll(listeners); for (final SchemaPath t : types) { b.put(t, reg); } replaceListeners(b.build()); } return reg; }
From source file:clocker.mesos.location.MesosLocation.java
@Override public void release(MachineLocation task) { String id = task.getId();// w ww . j a va 2 s. c om 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); }