List of usage examples for com.google.common.collect Multimap remove
boolean remove(@Nullable Object key, @Nullable Object value);
From source file:org.sonar.java.se.JavaCheckVerifier.java
private void validateIssue(Multimap<Integer, Expectations.Issue> expected, List<Integer> unexpectedLines, AnalyzerMessage issue) {// w w w .j a va 2 s .c o m int line = issue.getLine(); if (expected.containsKey(line)) { Expectations.Issue attrs = Iterables.getLast(expected.get(line)); assertAttributeMatch(issue, attrs, MESSAGE); validateAnalyzerMessageAttributes(attrs, issue); expected.remove(line, attrs); } else { unexpectedLines.add(line); } }
From source file:org.sonar.core.issue.tracking.AbstractTracker.java
protected void match(Tracking<RAW, BASE> tracking, Function<Trackable, SearchKey> searchKeyFactory) { if (tracking.isComplete()) { return;/*from w w w. j a va2 s . co m*/ } Multimap<SearchKey, BASE> baseSearch = ArrayListMultimap.create(); for (BASE base : tracking.getUnmatchedBases()) { baseSearch.put(searchKeyFactory.apply(base), base); } for (RAW raw : tracking.getUnmatchedRaws()) { SearchKey rawKey = searchKeyFactory.apply(raw); Collection<BASE> bases = baseSearch.get(rawKey); bases.stream().sorted( comparing(this::statusRank).reversed().thenComparing(comparing(Trackable::getCreationDate))) .findFirst().ifPresent(match -> { tracking.match(raw, match); baseSearch.remove(rawKey, match); }); } }
From source file:com.google.javascript.jscomp.newtypes.JSType.java
private static void updateTypemap(Multimap<String, JSType> typeMultimap, String typeParam, JSType type) { Preconditions.checkNotNull(type);//from ww w . jav a 2 s .co m Set<JSType> typesToRemove = new LinkedHashSet<>(); for (JSType other : typeMultimap.get(typeParam)) { JSType unified = unifyUnknowns(type, other); if (unified != null) { // Can't remove elms while iterating over the collection, so do it later typesToRemove.add(other); type = unified; } } for (JSType typeToRemove : typesToRemove) { typeMultimap.remove(typeParam, typeToRemove); } typeMultimap.put(typeParam, type); }
From source file:org.sonar.plugins.core.timemachine.ViolationPersisterDecorator.java
private void compareWithPastViolations(DecoratorContext context, List<RuleFailureModel> pastViolations) { Multimap<Rule, RuleFailureModel> pastViolationsByRule = LinkedHashMultimap.create(); for (RuleFailureModel pastViolation : pastViolations) { Rule rule = ruleFinder.findById(pastViolation.getRuleId()); pastViolationsByRule.put(rule, pastViolation); }/*from www . j a v a 2 s . c om*/ // for each violation, search equivalent past violation for (Violation violation : context.getViolations()) { RuleFailureModel pastViolation = selectPastViolation(violation, pastViolationsByRule); if (pastViolation != null) { // remove violation from past, since would be updated and shouldn't affect other violations anymore pastViolationsByRule.remove(violation.getRule(), pastViolation); } String checksum = getChecksumForLine(checksums, violation.getLineId()); violationPersister.saveOrUpdateViolation(context.getProject(), violation, pastViolation, checksum); } }
From source file:com.palantir.atlasdb.cleaner.Scrubber.java
private void scrubCells(TransactionManager txManager, Multimap<String, Cell> tableNameToCells, long scrubTimestamp, Transaction.TransactionType transactionType) { for (Entry<String, Collection<Cell>> entry : tableNameToCells.asMap().entrySet()) { String tableName = entry.getKey(); if (log.isInfoEnabled()) { log.info("Attempting to immediately scrub " + entry.getValue().size() + " cells from table " + tableName);//from ww w. j a v a 2s . com } for (List<Cell> cells : Iterables.partition(entry.getValue(), batchSizeSupplier.get())) { Multimap<Cell, Long> timestampsToDelete = HashMultimap.create( keyValueService.getAllTimestamps(tableName, ImmutableSet.copyOf(cells), scrubTimestamp)); for (Cell cell : ImmutableList.copyOf(timestampsToDelete.keySet())) { // Don't scrub garbage collection sentinels timestampsToDelete.remove(cell, Value.INVALID_VALUE_TIMESTAMP); } // If transactionType == TransactionType.AGGRESSIVE_HARD_DELETE this might // force other transactions to abort or retry deleteCellsAtTimestamps(txManager, tableName, timestampsToDelete, transactionType); } if (log.isInfoEnabled()) { log.info("Immediately scrubbed " + entry.getValue().size() + " cells from table " + tableName); } } }
From source file:org.sonar.plugins.core.timemachine.ViolationTrackingDecorator.java
private void mapViolation(Violation newViolation, RuleFailureModel pastViolation, Multimap<Integer, RuleFailureModel> lastViolationsByRule, Map<Violation, RuleFailureModel> violationMap) { if (pastViolation != null) { newViolation.setCreatedAt(pastViolation.getCreatedAt()); newViolation.setPermanentId(pastViolation.getPermanentId()); newViolation.setSwitchedOff(pastViolation.isSwitchedOff()); newViolation.setPersonId(pastViolation.getPersonId()); newViolation.setNew(false);//from w w w . j a v a 2s.c om lastViolationsByRule.remove(newViolation.getRule().getId(), pastViolation); violationMap.put(newViolation, pastViolation); unmappedLastViolations.remove(pastViolation); } else { newViolation.setNew(true); newViolation.setCreatedAt(project.getAnalysisDate()); } }
From source file:org.sonar.core.issue.tracking.Tracker.java
private void match(Tracking<RAW, BASE> tracking, SearchKeyFactory factory) { if (tracking.isComplete()) { return;/*from ww w .j av a 2 s . co m*/ } Multimap<SearchKey, BASE> baseSearch = ArrayListMultimap.create(); for (BASE base : tracking.getUnmatchedBases()) { baseSearch.put(factory.create(base), base); } for (RAW raw : tracking.getUnmatchedRaws()) { SearchKey rawKey = factory.create(raw); Collection<BASE> bases = baseSearch.get(rawKey); if (!bases.isEmpty()) { // TODO taking the first one. Could be improved if there are more than 2 issues on the same line. // Message could be checked to take the best one. BASE match = bases.iterator().next(); tracking.match(raw, match); baseSearch.remove(rawKey, match); } } }
From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingServiceTypeCalendar.java
private void parseCalendarDatesFile(final Reader calendarDatesReader, final Multimap<LocalDate, String> serviceTypesMap) throws FileNotFoundException, IOException { final CSVParser calendarDatesParser = new CSVParser(calendarDatesReader, CSVFormat.DEFAULT.withHeader()); final List<CSVRecord> calendarDatesRecords = calendarDatesParser.getRecords(); for (final CSVRecord record : calendarDatesRecords) { final String serviceType = record.get("service_id"); final LocalDate date = LocalDate.parse(record.get("date"), DateTimeFormatter.BASIC_ISO_DATE); final String exceptionType = record.get("exception_type"); switch (exceptionType) { case "1": serviceTypesMap.put(date, serviceType); break; case "2": serviceTypesMap.remove(date, serviceType); break; default:/* ww w. j a v a 2s . co m*/ throw new ScoreGeneratorFatalException(String.format("Invalid exception type %s", exceptionType)); } } }
From source file:com.enonic.cms.core.security.userstore.connector.synchronize.SynchronizeUserStoreJobImpl.java
private List<UserKey> resolveUsersToDelete(final Multimap<String, UserEntity> usersMapByName, final Collection<RemoteUser> remoteUsers) { // Remove all remote users from usersMapByName , so that we are only left with users not existing remote. final List<UserEntity> usersToRemoveFromMap = new ArrayList<UserEntity>(); for (final RemoteUser remoteUser : remoteUsers) { final Collection<UserEntity> candidates = usersMapByName.get(remoteUser.getId()); for (final UserEntity candidate : candidates) { if (candidate != null && remoteUser.getSync().equals(candidate.getSync())) { usersToRemoveFromMap.add(candidate); }/*from www . j ava 2 s. c o m*/ } } for (final UserEntity userToRemoveFromMap : usersToRemoveFromMap) { usersMapByName.remove(userToRemoveFromMap.getName(), userToRemoveFromMap); } final List<UserKey> usersToDelete = new ArrayList<UserKey>(); for (final UserEntity userToDelete : usersMapByName.values()) { usersToDelete.add(userToDelete.getKey()); } return usersToDelete; }
From source file:com.b2international.snowowl.snomed.datastore.request.SnomedAssociationTargetUpdateRequest.java
private void updateAssociationTargets(final TransactionContext context, final Inactivatable component) { final List<SnomedAssociationRefSetMember> existingMembers = Lists .newArrayList(component.getAssociationRefSetMembers()); final Multimap<AssociationType, String> newAssociationTargetsToCreate = HashMultimap .create(newAssociationTargets); final Iterator<SnomedAssociationRefSetMember> memberIterator = existingMembers.iterator(); while (memberIterator.hasNext()) { final SnomedAssociationRefSetMember existingMember = memberIterator.next(); final AssociationType associationType = AssociationType .getByConceptId(existingMember.getRefSetIdentifierId()); if (null == associationType) { continue; }// w w w .j a va 2 s.c o m final String existingTargetId = existingMember.getTargetComponentId(); if (newAssociationTargetsToCreate.remove(associationType, existingTargetId)) { // Exact match, just make sure that the member is active and remove it from the working list if (ensureMemberActive(context, existingMember)) { updateEffectiveTime(context, getLatestReleaseBranch(context), existingMember); } memberIterator.remove(); } } for (final SnomedAssociationRefSetMember existingMember : existingMembers) { final AssociationType associationType = AssociationType .getByConceptId(existingMember.getRefSetIdentifierId()); if (null == associationType) { continue; } if (newAssociationTargetsToCreate.containsKey(associationType)) { // We can re-use the member by changing the target component identifier, and checking that it is active final Iterator<String> targetIterator = newAssociationTargetsToCreate.get(associationType) .iterator(); final String newTargetId = targetIterator.next(); targetIterator.remove(); if (LOG.isDebugEnabled()) { LOG.debug( "Changing association member {} with type {} and target component identifier from {} to {}.", existingMember.getUuid(), associationType, existingMember.getTargetComponentId(), newTargetId); } ensureMemberActive(context, existingMember); existingMember.setTargetComponentId(newTargetId); updateEffectiveTime(context, getLatestReleaseBranch(context), existingMember); // Always check; we know that targetComponentId has changed } else { // We have no use for this member -- remove or inactivate if already released removeOrDeactivate(context, existingMember); } } // With all existing members processed, any remaining entries in the multimap will need to be added as members for (final Entry<AssociationType, String> newAssociationEntry : newAssociationTargetsToCreate.entries()) { final SnomedAssociationRefSetMember member = SnomedComponents.newAssociationMember() .withRefSet(newAssociationEntry.getKey().getConceptId()) .withTargetComponentId(newAssociationEntry.getValue()) .withReferencedComponent(((Component) component).getId()) .withModule(((Component) component).getModule().getId()).addTo(context); component.getAssociationRefSetMembers().add(member); } }