Example usage for com.google.common.collect Multimap keySet

List of usage examples for com.google.common.collect Multimap keySet

Introduction

In this page you can find the example usage for com.google.common.collect Multimap keySet.

Prototype

Set<K> keySet();

Source Link

Document

Returns a view collection of all distinct keys contained in this multimap.

Usage

From source file:eu.lp0.cursus.xml.scores.results.ScoresXMLSeriesResults.java

public ScoresXMLSeriesResults(Scores scores) {
    super(scores);

    series = AbstractXMLEntity.generateId(scores.getSeries());

    discards = scores.getDiscardCount();

    Multimap<Event, Race> events_ = LinkedHashMultimap.create(scores.getRaces().size(),
            scores.getRaces().size());//from ww  w . ja v a2  s  . c o m
    for (Race race : scores.getRaces()) {
        events_.put(race.getEvent(), race);
    }

    eventResults = new ArrayList<ScoresXMLSeriesEventResults>(events_.keySet().size());
    for (Entry<Event, Collection<Race>> event : events_.asMap().entrySet()) {
        eventResults.add(new ScoresXMLSeriesEventResults(scores, event.getKey(), event.getValue()));
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.states.EventDocumentsService.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
private void createDocuments(final Entity event) {

    EventType eventType = EventType.of(event);

    List<Entity> machinePartsForEvent = event.getHasManyField(eventType.getMachinePartsName());
    if (machinePartsForEvent.isEmpty()) {
        return;/*from  w ww.j  a  v  a 2s .  c  om*/
    }

    DataDefinition warehouseDD = dataDefinitionService.get(MaterialFlowConstants.PLUGIN_IDENTIFIER,
            MaterialFlowConstants.MODEL_LOCATION);
    Multimap<Long, Entity> groupedMachinePartsForEvent = groupMachinePartsByLocation(machinePartsForEvent);

    boolean resourcesSufficient = true;
    for (Long warehouseId : groupedMachinePartsForEvent.keySet()) {
        Collection<Entity> machinePartsForLocation = groupedMachinePartsForEvent.get(warehouseId);
        List<Entity> machineParts = machinePartsForLocation.stream()
                .map(part -> part.getBelongsToField(MachinePartForEventFields.MACHINE_PART)).distinct()
                .collect(Collectors.toList());
        Entity warehouse = warehouseDD.get(warehouseId);
        Map<Long, BigDecimal> quantitiesInWarehouse = materialFlowResourcesService
                .getQuantitiesForProductsAndLocation(machineParts, warehouse);

        if (!checkIfResourcesAreSufficient(event, quantitiesInWarehouse, machinePartsForLocation, warehouse)) {
            resourcesSufficient = false;
        }
    }
    if (!resourcesSufficient) {
        return;
    }
    for (Long warehouseId : groupedMachinePartsForEvent.keySet()) {
        Collection<Entity> machinePartsForLocation = groupedMachinePartsForEvent.get(warehouseId);

        Entity warehouse = warehouseDD.get(warehouseId);

        Entity document = createDocumentForLocation(event, eventType, warehouse, machinePartsForLocation);
        if (!document.isValid()) {
            event.addGlobalError("cmmsMachineParts.maintenanceEvent.state.documentNotCreated");
            return;
        }
    }

}

From source file:com.google.jstestdriver.output.XmlPrinterImpl.java

public void writeXmlReportFiles() {
    Map<BrowserInfo, String> browserNames = createUniqueBrowserNames(resultHolder.getResults().keySet());
    for (BrowserInfo browser : resultHolder.getResults().keySet()) {
        Multimap<String, TestResult> testCaseRollup = newMultiMap();
        for (TestResult testResult : resultHolder.getResults().get(browser)) {
            testCaseRollup.put(testResult.getTestCaseName(), testResult);
        }// w  w w.  ja v  a2  s  .  c o  m
        for (String testCaseName : testCaseRollup.keySet()) {
            String suiteName = formatSuiteName(browserNames.get(browser), testCaseName);
            File xmlOutputFile = new File(xmlOutputDir, formatFileName(suiteName));
            try {
                xmlOutputFile.createNewFile();
                TestXmlSerializer serializer = new TestXmlSerializer(new FileWriter(xmlOutputFile));

                serializer.writeTestCase(suiteName, testCaseRollup.get(testCaseName));
            } catch (IOException e) {
                logger.error("Could not create file: {}", xmlOutputFile.getAbsolutePath(), e);
            }
        }
    }
}

From source file:org.summer.ss.core.dispatch.DispatchingSupport.java

protected void removeNonLocalMethods(final JvmGenericType type,
        Multimap<Pair<String, Integer>, JvmOperation> result) {
    List<Pair<String, Integer>> removeKeys = newArrayList();
    for (Pair<String, Integer> signatureTuple : result.keySet()) {
        Collection<JvmOperation> collection = result.get(signatureTuple);
        if (!any(collection, new Predicate<JvmOperation>() {
            public boolean apply(JvmOperation input) {
                return input.getDeclaringType() == type;
            }/*  w  ww  .jav  a2s  .c  om*/
        })) {
            removeKeys.add(signatureTuple);
        }
    }
    for (Pair<String, Integer> signatureTuple : removeKeys) {
        result.removeAll(signatureTuple);
    }
}

From source file:com.b2international.snowowl.snomed.datastore.converter.SnomedReferenceSetMemberConverter.java

private ImmutableListMultimap<ComponentCategory, String> collectReferencedComponentCategories(
        final Multimap<String, SnomedReferenceSetMember> refCompToMembers) {

    return FluentIterable.from(refCompToMembers.keySet()).index(new Function<String, ComponentCategory>() {
        @Override/*from  ww w.j a  v a  2 s  .co  m*/
        public ComponentCategory apply(String input) {
            return SnomedIdentifiers.getComponentCategory(input);
        }
    });
}

From source file:com.facebook.presto.execution.BenchmarkNodeScheduler.java

@Benchmark
@OperationsPerInvocation(SPLITS)//  w w w  . j  a  v a  2 s . com
public Object benchmark(BenchmarkData data) throws Throwable {
    List<RemoteTask> remoteTasks = ImmutableList.copyOf(data.getTaskMap().values());
    Iterator<MockRemoteTaskFactory.MockRemoteTask> finishingTask = Iterators.cycle(data.getTaskMap().values());
    Iterator<Split> splits = data.getSplits().iterator();
    Set<Split> batch = new HashSet<>();
    while (splits.hasNext() || !batch.isEmpty()) {
        Multimap<Node, Split> assignments = data.getNodeSelector().computeAssignments(batch, remoteTasks)
                .getAssignments();
        for (Node node : assignments.keySet()) {
            MockRemoteTaskFactory.MockRemoteTask remoteTask = data.getTaskMap().get(node);
            remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder()
                    .putAll(new PlanNodeId("sourceId"), assignments.get(node)).build());
            remoteTask.startSplits(MAX_SPLITS_PER_NODE);
        }
        if (assignments.size() == batch.size()) {
            batch.clear();
        } else {
            batch.removeAll(assignments.values());
        }
        while (batch.size() < SPLIT_BATCH_SIZE && splits.hasNext()) {
            batch.add(splits.next());
        }
        finishingTask.next().finishSplits((int) Math.ceil(MAX_SPLITS_PER_NODE / 50.0));
    }

    return remoteTasks;
}

From source file:it.sayservice.platform.smartplanner.otp.schedule.TransitTimes.java

public void buildStopIds() {
    BucketSet mergedBs = new BucketSet();
    Multimap<String, TripTimes> map = ArrayListMultimap.create();
    for (TripTimes tt : times) {
        map.put(tt.getRecurrence(), tt);
    }/*from w  ww  .j  a  v  a 2 s .com*/

    List<BucketSet> bss = new ArrayList<BucketSet>();
    BucketSet bs;
    for (String key : map.keySet()) {
        bs = new BucketSet();
        List<TripTimes> ttl = (List<TripTimes>) map.get(key);

        Collections.sort(ttl, new Comparator<TripTimes>() {
            @Override
            public int compare(TripTimes o1, TripTimes o2) {
                return o2.getTripTimes().size() - o1.getTripTimes().size();
            }
        });

        for (TripTimes tt : ttl) {
            List<Bucket> buckets = new ArrayList<Bucket>();
            for (TripTimeEntry sch : tt.getTripTimes()) {
                Bucket b = sch.toBucket();
                buckets.add(b);
            }
            bs.merge(buckets);
        }
        bss.add(bs);
    }

    for (BucketSet bs0 : bss) {
        mergedBs.merge(bs0.getBuckets());
    }

    stopIds = mergedBs.getIds();
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.ecore.EcoreServiceForTabReportingImpl.java

private TabReportingEcoreData createAdditionalEStructuralFeatures(EPackage modelPackage) {
    TabReportingEcoreData data = new TabReportingEcoreData(modelPackage);
    Multimap<Class<? extends AttributeType>, AttributeType> fetchAttributeTypes = fetchAttributeTypes();

    for (Class<? extends AttributeType> attributeTypeClass : fetchAttributeTypes.keySet()) {
        if (attributeTypeClass.equals(EnumAT.class)) {
            handleEnumATs(fetchAttributeTypes, data);
        } else {/*www . j a  v  a2  s .  c  o m*/
            handleSimpleATs(fetchAttributeTypes.get(attributeTypeClass), data);
        }
    }

    return data;
}

From source file:io.prestosql.execution.BenchmarkNodeScheduler.java

@Benchmark
@OperationsPerInvocation(SPLITS)/* w  w w  .j ava 2s  .c o m*/
public Object benchmark(BenchmarkData data) {
    List<RemoteTask> remoteTasks = ImmutableList.copyOf(data.getTaskMap().values());
    Iterator<MockRemoteTaskFactory.MockRemoteTask> finishingTask = Iterators.cycle(data.getTaskMap().values());
    Iterator<Split> splits = data.getSplits().iterator();
    Set<Split> batch = new HashSet<>();
    while (splits.hasNext() || !batch.isEmpty()) {
        Multimap<Node, Split> assignments = data.getNodeSelector().computeAssignments(batch, remoteTasks)
                .getAssignments();
        for (Node node : assignments.keySet()) {
            MockRemoteTaskFactory.MockRemoteTask remoteTask = data.getTaskMap().get(node);
            remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder()
                    .putAll(new PlanNodeId("sourceId"), assignments.get(node)).build());
            remoteTask.startSplits(MAX_SPLITS_PER_NODE);
        }
        if (assignments.size() == batch.size()) {
            batch.clear();
        } else {
            batch.removeAll(assignments.values());
        }
        while (batch.size() < SPLIT_BATCH_SIZE && splits.hasNext()) {
            batch.add(splits.next());
        }
        finishingTask.next().finishSplits((int) Math.ceil(MAX_SPLITS_PER_NODE / 50.0));
    }

    return remoteTasks;
}

From source file:org.sonar.server.qualityprofile.BuiltInQualityProfilesUpdateListener.java

void onChange(Multimap<QProfileName, ActiveRuleChange> changedProfiles, long startDate, long endDate) {
    if (config.getBoolean(DISABLE_NOTIFICATION_ON_BUILT_IN_QPROFILES).orElse(false)) {
        return;//from  www  .  j ava  2 s .c  o  m
    }
    BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification();
    changedProfiles.keySet().stream().map(changedProfile -> {
        String profileName = changedProfile.getName();
        Language language = languages.get(changedProfile.getLanguage());
        Collection<ActiveRuleChange> activeRuleChanges = changedProfiles.get(changedProfile);
        int newRules = (int) activeRuleChanges.stream().map(ActiveRuleChange::getType).filter(ACTIVATED::equals)
                .count();
        int updatedRules = (int) activeRuleChanges.stream().map(ActiveRuleChange::getType)
                .filter(UPDATED::equals).count();
        int removedRules = (int) activeRuleChanges.stream().map(ActiveRuleChange::getType)
                .filter(DEACTIVATED::equals).count();
        return Profile.newBuilder().setProfileName(profileName).setLanguageKey(language.getKey())
                .setLanguageName(language.getName()).setNewRules(newRules).setUpdatedRules(updatedRules)
                .setRemovedRules(removedRules).setStartDate(startDate).setEndDate(endDate).build();
    }).forEach(notification::addProfile);
    notificationManager.scheduleForSending(notification.serialize());
}