Java Code Examples for com.google.common.collect.Multimap#remove()
The following examples show how to use
com.google.common.collect.Multimap#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DecomposedSessionTest.java From emissary with Apache License 2.0 | 6 votes |
@Test public void testMetadataProcessing() { DecomposedSession d = new DecomposedSession(); d.addMetaData("foo", null); assertFalse("Null valued metadata must not be added", d.hasMetaData()); d.addMetaData(null, "bar"); assertFalse("Null keyed metadata must not be added", d.hasMetaData()); Map<String, List<Object>> m = new HashMap<String, List<Object>>(); m.put("foo", Arrays.asList(new Object[] {"bar1", "bar2"})); d.addMetaData(m); assertTrue("Mapped metadata must be present", d.hasMetaData()); assertEquals("Mapped metadata values must be present", 2, d.getMetaDataItem("foo").size()); Multimap<String, Object> mm = d.getMultimap(); mm.remove("foo", "bar2"); assertEquals("Returned multimap must be live object", 1, d.getMetaDataItem("foo").size()); }
Example 2
Source File: SaltApiRunPostResponse.java From cloudbreak with Apache License 2.0 | 6 votes |
protected Object grainRemove(String body) throws IOException { Matcher targetMatcher = Pattern.compile(".*(tgt=([^&]+)).*").matcher(body); Matcher argMatcher = Pattern.compile(".*(arg=([^&]+)).*(arg=([^&]+)).*").matcher(body); Map<String, JsonNode> hostMap = new HashMap<>(); if (targetMatcher.matches() && argMatcher.matches()) { String[] targets = targetMatcher.group(2).split("%2C"); String key = argMatcher.group(2); String value = argMatcher.group(4); for (String target : targets) { if (grains.containsKey(target)) { Multimap<String, String> grainsForTarget = grains.get(target); grainsForTarget.remove(key, value); } hostMap.put(target, objectMapper.valueToTree(grains.get(target).entries())); } } return createGrainsModificationResponse(hostMap); }
Example 3
Source File: AwsMetadataCollector.java From cloudbreak with Apache License 2.0 | 6 votes |
private void addFromUnknownMap(CloudInstance cloudInstance, Multimap<String, Instance> unknownMap, List<CloudVmMetaDataStatus> collectedCloudVmMetaDataStatuses) { LOGGER.debug("Collect from unknown map, cloudInstance: {}, unknownMap: {}", cloudInstance.getInstanceId(), unknownMap.keySet()); String groupName = cloudInstance.getTemplate().getGroupName(); Collection<Instance> unknownInstancesForGroup = unknownMap.get(groupName); if (!unknownInstancesForGroup.isEmpty()) { Optional<Instance> found = unknownInstancesForGroup.stream().findFirst(); Instance foundInstance = found.get(); CloudInstance newCloudInstance = new CloudInstance(foundInstance.getInstanceId(), cloudInstance.getTemplate(), cloudInstance.getAuthentication(), cloudInstance.getParameters()); CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData( foundInstance.getPrivateIpAddress(), foundInstance.getPublicIpAddress(), awsLifeCycleMapper.getLifeCycle(foundInstance)); CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(newCloudInstance, InstanceStatus.CREATED); CloudVmMetaDataStatus newMetadataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData); collectedCloudVmMetaDataStatuses.add(newMetadataStatus); unknownMap.remove(groupName, found.get()); } }
Example 4
Source File: AbstractSchemaRepository.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811") private synchronized <T extends SchemaSourceRepresentation> void removeSource(final PotentialSchemaSource<?> source, final SchemaSourceRegistration<?> reg) { final Multimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> m = sources.get(source.getSourceIdentifier()); if (m != null) { m.remove(source.getRepresentation(), reg); for (SchemaListenerRegistration l : listeners) { l.getInstance().schemaSourceUnregistered(source); } if (m.isEmpty()) { sources.remove(source.getSourceIdentifier()); } } }
Example 5
Source File: AbstractResourceRepository.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
private void removeItem(@NonNull ResourceItem removedItem) { synchronized (ITEM_MAP_LOCK) { Multimap<String, ResourceItem> map = getMap(removedItem.getType(), false); if (map != null) { map.remove(removedItem.getName(), removedItem); } } }
Example 6
Source File: MemoryPerUserWaveViewHandlerImpl.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
@Override public ListenableFuture<Void> onParticipantRemoved(WaveletName waveletName, ParticipantId user) { Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user); if (perUserView != null) { if (perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) { perUserView.remove(waveletName.waveId, waveletName.waveletId); LOG.fine("Removed wavelet: " + waveletName + " from the view of user: " + user.getAddress()); } } SettableFuture<Void> task = SettableFuture.create(); task.set(null); return task; }
Example 7
Source File: MemoryPerUserWaveViewHandlerImpl.java From swellrt with Apache License 2.0 | 5 votes |
@Override public ListenableFuture<Void> onParticipantRemoved(WaveletName waveletName, ParticipantId user) { Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user); if (perUserView != null) { if (perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) { perUserView.remove(waveletName.waveId, waveletName.waveletId); LOG.fine("Removed wavelet: " + waveletName + " from the view of user: " + user.getAddress()); } } SettableFuture<Void> task = SettableFuture.create(); task.set(null); return task; }
Example 8
Source File: Sep10Challenge.java From java-stellar-sdk with Apache License 2.0 | 5 votes |
private static Set<String> verifyTransactionSignatures(Transaction transaction, Set<String> signers) throws InvalidSep10ChallengeException { if (transaction.getSignatures().isEmpty()) { throw new InvalidSep10ChallengeException("Transaction has no signatures."); } byte[] txHash = transaction.hash(); // find and verify signatures Set<String> signersFound = new HashSet<String>(); Multimap<SignatureHint, Signature> signatures = HashMultimap.create(); for (DecoratedSignature decoratedSignature : transaction.getSignatures()) { signatures.put(decoratedSignature.getHint(), decoratedSignature.getSignature()); } for (String signer : signers) { KeyPair keyPair = KeyPair.fromAccountId(signer); SignatureHint hint = keyPair.getSignatureHint(); for (Signature signature : signatures.get(hint)) { if (keyPair.verify(txHash, signature.getSignature())) { signersFound.add(signer); // explicitly ensure that a transaction signature cannot be // mapped to more than one signer signatures.remove(hint, signature); break; } } } return signersFound; }
Example 9
Source File: Guava.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@NoWarning("GC") public static void testMultimapOK2(Multimap<String, Pair<Integer,Long>> mm) { Pair<Integer, Long> p = new Pair<Integer, Long>(1, 1L); mm.containsEntry("x", p); mm.containsKey("x"); mm.containsValue(p); mm.remove("x", p); mm.removeAll("x"); }
Example 10
Source File: Guava.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@NoWarning("GC") public static void testMultimapOK(Multimap<String, Integer> mm) { mm.containsEntry("x", 1); mm.containsKey("x"); mm.containsValue(1); mm.remove("x", 1); mm.removeAll("x"); }
Example 11
Source File: Guava.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@ExpectWarning(value="GC", num=7) public static void testMultimap(Multimap<String, Integer> mm) { mm.containsEntry("x", "y"); mm.containsEntry(1, 5); mm.containsKey(1); mm.containsValue("x"); mm.remove("x", "x"); mm.remove(1, 2); mm.removeAll(1); }
Example 12
Source File: EventBus.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
/** * Unregisters all subscribed methods from provided subscriber object. * * @param object object to unsubscribe from */ public synchronized void unregister(@Nonnull final Object object) { if (subscribers == null) { return; } final Multimap<Class, Subscriber> map = HashMultimap.create(); map.putAll(subscribers); for (Class<?> clazz = object.getClass(); clazz != null; clazz = clazz.getSuperclass()) { for (final Method method : clazz.getDeclaredMethods()) { final Subscribe sub = method.getAnnotation(Subscribe.class); if (sub == null) { continue; } final Class<?> parameterClazz = method.getParameterTypes()[0]; map.remove(parameterClazz, new Subscriber(object, method, sub.priority(), null)); } } subscribers = ImmutableMultimap.copyOf(map); }
Example 13
Source File: AbstractReferenceUpdater.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void createReferenceUpdatesForCluster(ElementRenameArguments elementRenameArguments, Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet, IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 100); List<URI> unloadableResources = loadReferringResources(resourceSet, resource2references.keySet(), status, progress.newChild(10)); if (progress.isCanceled()) { throw new OperationCanceledException(); } for (URI unloadableResouce : unloadableResources) resource2references.removeAll(unloadableResouce); List<IReferenceDescription> unresolvableReferences = resolveReferenceProxies(resourceSet, resource2references.values(), status, progress.newChild(70)); if (progress.isCanceled()) { throw new OperationCanceledException(); } for (IReferenceDescription unresolvableReference : unresolvableReferences) { URI unresolvableReferringResource = unresolvableReference.getSourceEObjectUri().trimFragment(); resource2references.remove(unresolvableReferringResource, unresolvableReference); } elementRenameArguments.getRenameStrategy().applyDeclarationChange(elementRenameArguments.getNewName(), resourceSet); if (progress.isCanceled()) { throw new OperationCanceledException(); } createReferenceUpdates(elementRenameArguments, resource2references, resourceSet, updateAcceptor, progress.newChild(20)); if (progress.isCanceled()) { throw new OperationCanceledException(); } elementRenameArguments.getRenameStrategy().revertDeclarationChange(resourceSet); }
Example 14
Source File: AbstractResourceRepository.java From javaide with GNU General Public License v3.0 | 5 votes |
private void removeItem(@NonNull ResourceItem removedItem) { synchronized (ITEM_MAP_LOCK) { Multimap<String, ResourceItem> map = getMap(removedItem.getType(), false); if (map != null) { map.remove(removedItem.getName(), removedItem); } } }
Example 15
Source File: TurbineElements.java From turbine with Apache License 2.0 | 4 votes |
private boolean shouldAdd( ClassSymbol s, PackageSymbol from, Multimap<String, TurbineExecutableElement> methods, TurbineExecutableElement m) { if (m.sym().owner().equals(s)) { // always include methods (and constructors) declared in the given type return true; } if (m.getKind() == ElementKind.CONSTRUCTOR) { // skip constructors from super-types, because the spec says so return false; } if (!isVisible(from, packageSymbol(m.sym()), TurbineVisibility.fromAccess(m.info().access()))) { // skip invisible methods in supers return false; } // otherwise check if we've seen methods that override, or are overridden by, the // current method Set<TurbineExecutableElement> overrides = new HashSet<>(); Set<TurbineExecutableElement> overridden = new HashSet<>(); String name = m.info().name(); for (TurbineExecutableElement other : methods.get(name)) { if (overrides(m, other, (TypeElement) m.getEnclosingElement())) { overrides.add(other); continue; } if (overrides(other, m, (TypeElement) other.getEnclosingElement())) { overridden.add(other); continue; } } if (!overridden.isEmpty()) { // We've already processed method(s) that override this one; nothing to do here. // If that's true, and we've *also* processed a methods that this one overrides, // something has gone terribly wrong: since overriding is transitive the results // contain a pair of methods that override each other. checkState(overrides.isEmpty()); return false; } // Add this method, and remove any methods we've already processed that it overrides. for (TurbineExecutableElement override : overrides) { methods.remove(name, override); } return true; }
Example 16
Source File: GroupingDocumentTransformer.java From datawave with Apache License 2.0 | 4 votes |
private void getListKeyCounts(EventBase e, Multiset<Collection<FieldBase<?>>> multiset) { Set<String> expandedGroupFieldsList = new LinkedHashSet<>(); List<FieldBase<?>> fields = e.getFields(); Multimap<String,String> fieldToFieldWithContextMap = this.getFieldToFieldWithGroupingContextMap(fields, expandedGroupFieldsList); if (log.isTraceEnabled()) log.trace("got a new fieldToFieldWithContextMap:" + fieldToFieldWithContextMap); int longest = this.longestValueList(fieldToFieldWithContextMap); for (int i = 0; i < longest; i++) { Collection<FieldBase<?>> fieldCollection = Sets.newHashSet(); for (String fieldListItem : expandedGroupFieldsList) { if (log.isTraceEnabled()) log.trace("fieldListItem:" + fieldListItem); Collection<String> gtNames = fieldToFieldWithContextMap.get(fieldListItem); if (gtNames == null || gtNames.isEmpty()) { if (log.isTraceEnabled()) { log.trace("gtNames:" + gtNames); log.trace("fieldToFieldWithContextMap:" + fieldToFieldWithContextMap + " did not contain " + fieldListItem); } continue; } else { String gtName = gtNames.iterator().next(); if (fieldListItem.equals(gtName) == false) { fieldToFieldWithContextMap.remove(fieldListItem, gtName); } if (log.isTraceEnabled()) { log.trace("fieldToFieldWithContextMap now:" + fieldToFieldWithContextMap); log.trace("gtName:" + gtName); } fieldCollection.add(this.fieldMap.get(gtName)); } } if (fieldCollection.size() == expandedGroupFieldsList.size()) { multiset.add(fieldCollection); if (log.isTraceEnabled()) log.trace("added fieldList to the map:" + fieldCollection); } else { if (log.isTraceEnabled()) { log.trace("fieldList.size() != this.expandedGroupFieldsList.size()"); log.trace("fieldList:" + fieldCollection); log.trace("expandedGroupFieldsList:" + expandedGroupFieldsList); } } } if (log.isTraceEnabled()) log.trace("map:" + multiset); }
Example 17
Source File: APKModuleGraph.java From buck with Apache License 2.0 | 4 votes |
/** * For each seed target, find its reachable targets and mark them in a multimap as being reachable * by that module for later sorting into exclusive and shared targets * * @return the Multimap containing targets and the seed modules that contain them */ private Multimap<BuildTarget, String> mapTargetsToContainingModules() { Multimap<BuildTarget, String> targetToContainingApkModuleNameMap = MultimapBuilder.treeKeys().treeSetValues().build(); for (Map.Entry<String, ImmutableList<BuildTarget>> seedConfig : getSeedConfigMap().get().entrySet()) { String seedModuleName = seedConfig.getKey(); for (BuildTarget seedTarget : seedConfig.getValue()) { targetToContainingApkModuleNameMap.put(seedTarget, seedModuleName); new AbstractBreadthFirstTraversal<TargetNode<?>>(targetGraph.get(seedTarget)) { @Override public ImmutableSet<TargetNode<?>> visit(TargetNode<?> node) { ImmutableSet.Builder<TargetNode<?>> depsBuilder = ImmutableSet.builder(); for (BuildTarget depTarget : node.getBuildDeps()) { if (!isInRootModule(depTarget) && !isSeedTarget(depTarget)) { depsBuilder.add(targetGraph.get(depTarget)); targetToContainingApkModuleNameMap.put(depTarget, seedModuleName); } } return depsBuilder.build(); } }.start(); } } // Now to generate the minimal covers of APKModules for each set of APKModules that contain // a buildTarget DirectedAcyclicGraph<String> declaredDependencies = getDeclaredDependencyGraph(); Multimap<BuildTarget, String> targetModuleEntriesToRemove = MultimapBuilder.treeKeys().treeSetValues().build(); for (BuildTarget key : targetToContainingApkModuleNameMap.keySet()) { Collection<String> modulesForTarget = targetToContainingApkModuleNameMap.get(key); new AbstractBreadthFirstTraversal<String>(modulesForTarget) { @Override public Iterable<String> visit(String moduleName) throws RuntimeException { Collection<String> dependentModules = declaredDependencies.getIncomingNodesFor(moduleName); for (String dependent : dependentModules) { if (modulesForTarget.contains(dependent)) { targetModuleEntriesToRemove.put(key, dependent); } } return dependentModules; } }.start(); } for (Map.Entry<BuildTarget, String> entryToRemove : targetModuleEntriesToRemove.entries()) { targetToContainingApkModuleNameMap.remove(entryToRemove.getKey(), entryToRemove.getValue()); } return targetToContainingApkModuleNameMap; }