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:com.demigodsrpg.data.battle.Report.java

public void sendToServer() {
    Multimap<Participant, String> scores = getParticipantScores();
    List<Participant> participants = new ArrayList<>(scores.keySet());
    if (participants.size() == 2) {
        double delta = getWeightedKillDeathRatio(participants.get(0))
                - getWeightedKillDeathRatio(participants.get(1));
        delta = delta < 0 ? delta * -1 : delta;
        if (delta > 0.8) {
            Participant one = participants.get(0);
            Participant two = participants.get(1);
            Bukkit.broadcastMessage(one.getFaction().getColor() + one.getLastKnownName() + ChatColor.GRAY
                    + " and " + two.getFaction().getColor() + two.getLastKnownName() + ChatColor.GRAY
                    + " just tied in a duel.");
        } else {/*from  w w w . j a va 2 s  . c om*/
            int winnerIndex = getWeightedKillDeathRatio(participants.get(0)) > getWeightedKillDeathRatio(
                    participants.get(1)) ? 0 : 1;
            Participant winner = participants.get(winnerIndex);
            Participant loser = participants.get(winnerIndex == 0 ? 1 : 0);
            Bukkit.broadcastMessage(winner.getFaction().getColor() + winner.getLastKnownName() + ChatColor.GRAY
                    + " just won in a duel against " + loser.getFaction().getColor() + loser.getLastKnownName()
                    + ChatColor.GRAY + ".");
        }
    } else if (participants.size() > 2) {
        double winningScore = 0;
        Faction winningfaction = null;
        List<Participant> MVPs = getMVPs();
        boolean oneMVP = MVPs.size() == 1;
        for (Map.Entry<Faction, Double> entry : weightedFactionRatios.entrySet()) {
            double score = entry.getValue();
            if (score > winningScore) {
                winningfaction = entry.getKey();
                winningScore = score;
            }
        }
        if (winningfaction != null) {
            Bukkit.broadcastMessage(ChatColor.GRAY + "The " + ChatColor.YELLOW + winningfaction.getName()
                    + " faction " + ChatColor.GRAY + "just won a battle involving " + participants.size()
                    + " participants.");
            Bukkit.broadcastMessage(ChatColor.GRAY + "The " + ChatColor.YELLOW + "MVP" + (oneMVP ? "" : "s")
                    + ChatColor.GRAY + " from this battle " + (oneMVP ? "is" : "are") + ":");
            for (Participant mvp : MVPs) {
                BattleMetaData data = battle.getInvolved().get(mvp.getPersistentId());
                Bukkit.broadcastMessage(ChatColor.DARK_GRAY + "  " + mvp.getFaction().getColor()
                        + mvp.getLastKnownName() + ChatColor.GRAY + " / " + ChatColor.YELLOW + "Kills"
                        + ChatColor.GRAY + ": " + data.getKills() + " / " + ChatColor.YELLOW + "Deaths"
                        + ChatColor.GRAY + ": " + data.getDeaths());
            }
        }
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.timeseriesExcel.exporter.TimeseriesExcelTemplateGenerator.java

private void generateSheets(TimeseriesWorkbookContext wbContext,
        Multimap<TypeOfBuildingBlock, AttributeType> tobbToAt) {
    List<TypeOfBuildingBlock> tobbs = Lists.newArrayList(tobbToAt.keySet());
    Collections.sort(tobbs, getTobbOrdering());

    for (TypeOfBuildingBlock tobb : tobbs) {
        List<AttributeType> atList = Lists.newArrayList(tobbToAt.get(tobb));
        Collections.sort(atList, getAtOrdering());
        for (AttributeType at : atList) {
            generateSheet(wbContext, tobb, at);
        }//from  w w  w .  j ava 2 s .  c  o m
    }
    TimeseriesIntroSheetGenerator introSheetGenerator = new TimeseriesIntroSheetGenerator(wbContext, logoImage);
    introSheetGenerator.generateIntroduction();
}

From source file:org.robotframework.ide.eclipse.main.plugin.navigator.handlers.ChangeExclusionHandler.java

public void changeExclusion(final IEventBroker eventBroker, final IStructuredSelection selection) {
    final List<IResource> resourcesToChange = Selections.getAdaptableElements(selection, IResource.class);
    final Map<IProject, Collection<RobotSuiteFile>> grouped = RobotSuiteFileCollector
            .collectGroupedByProject(resourcesToChange);
    final Multimap<IProject, IPath> groupedPaths = groupByProject(resourcesToChange);

    for (IResource res : resourcesToChange) {
        removeMarkers(res);/*from w  w w .ja  va  2s  .  c  o  m*/
    }

    for (final IProject groupingProject : groupedPaths.keySet()) {
        changeExclusion(groupingProject, groupedPaths.get(groupingProject));

        final RedProjectConfigEventData<Collection<IPath>> eventData = new RedProjectConfigEventData<>(
                groupingProject.getFile(RobotProjectConfig.FILENAME), groupedPaths.get(groupingProject));
        eventBroker.send(RobotProjectConfigEvents.ROBOT_CONFIG_VALIDATION_EXCLUSIONS_STRUCTURE_CHANGED,
                eventData);
        final Collection<RobotSuiteFile> suiteModels = grouped.get(groupingProject);
        if (suiteModels != null) {
            final ModelUnitValidatorConfig validatorConfig = ModelUnitValidatorConfigFactory
                    .create(suiteModels);
            final Job validationJob = RobotArtifactsValidator.createValidationJob(groupingProject,
                    validatorConfig);
            validationJob.schedule(REVALIDATE_JOB_DELAY);
        }

    }

    SwtThread.asyncExec(new Runnable() {
        @Override
        public void run() {
            final IDecoratorManager manager = PlatformUI.getWorkbench().getDecoratorManager();
            manager.update(RobotValidationExcludedDecorator.ID);

        }
    });

}

From source file:com.b2international.snowowl.snomed.importer.rf2.refset.SnomedLanguageRefSetImporter.java

@Override
protected void attach(Collection<SnomedLanguageRefSetMember> componentsToAttach) {
    final Multimap<String, SnomedLanguageRefSetMember> membersByReferencedComponent = Multimaps
            .index(componentsToAttach, SnomedRefSetMember::getReferencedComponentId);
    final Collection<Component> components = getComponents(membersByReferencedComponent.keySet());
    for (Component component : components) {
        if (component instanceof Description) {
            final Collection<SnomedLanguageRefSetMember> newDescriptionMembers = membersByReferencedComponent
                    .get(component.getId());
            ((Description) component).getLanguageRefSetMembers().addAll(newDescriptionMembers);
        }//from   ww  w  .  j  ava 2 s.co  m
    }
}

From source file:com.android.build.gradle.integration.common.truth.NativeAndroidProjectSubject.java

@SuppressWarnings("NonBooleanMethodNameMayNotStartWithQuestion")
public void hasArtifactGroupsOfSize(long size) {
    Multimap<String, NativeArtifact> groups = getArtifactsGroupedByGroupName();
    for (String groupName : groups.keySet()) {
        if (groups.get(groupName).size() != size) {
            failWithRawMessage("Not true that %s artifact group %s has size %s. " + "Actual size is <%s>",
                    getDisplaySubject(), groupName, size, groups.get(groupName).size());
        }/*w w  w  .  ja  va2  s . c om*/
    }
}

From source file:org.eclipse.ocl.xtext.oclstdlib.ui.refactoring.OCLstdlibReferenceUpdater.java

@Override
protected void createReferenceUpdates(ElementRenameArguments elementRenameArguments,
        Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, "Creating reference updates",
            resource2references.keySet().size());
    for (URI referringResourceURI : resource2references.keySet()) {
        if (progress.isCanceled())
            return;
        //         Resource referringResource = resourceSet.getResource(referringResourceURI, false);
        //         if (!(referringResource instanceof XtextResource)) {
        //            throw new RefactoringStatusException("Resource " + notNull(referringResourceURI)
        //                  + " is not an XtextResource", true);
        //         }
        //         ((XtextResource) referringResource).getCache().clear(referringResource);
        for (IReferenceDescription referenceDescription : resource2references.get(referringResourceURI)) {
            createReferenceUpdate(referenceDescription, referringResourceURI, elementRenameArguments,
                    resourceSet, updateAcceptor);
        }//  ww w  .  j a  v  a2s.com
        progress.worked(1);
    }
}

From source file:fr.ujm.tse.lt2c.satin.rules.run.RunRHODF6d.java

@Override
protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) {

    final long domain = AbstractDictionary.domain;
    final long range = AbstractDictionary.range;
    final long subPropertyOf = AbstractDictionary.subPropertyOf;

    int loops = 0;

    final Multimap<Long, Long> domainMultiMap = ts2.getMultiMapForPredicate(domain);
    final Multimap<Long, Long> rangeMultiMap = ts2.getMultiMapForPredicate(range);
    if (domainMultiMap != null && !domainMultiMap.isEmpty()) {
        for (final Long s : domainMultiMap.keySet()) {
            loops++;/*from   ww  w.j a  v a 2  s . co  m*/
            final Triple result = new ImmutableTriple(s, subPropertyOf, s);
            outputTriples.add(result);
        }
    }
    if (rangeMultiMap != null && !rangeMultiMap.isEmpty()) {
        for (final Long s : rangeMultiMap.keySet()) {
            loops++;
            final Triple result = new ImmutableTriple(s, subPropertyOf, s);
            outputTriples.add(result);
        }
    }

    return loops;

}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcMultiRowRecordWriter.java

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override/*  w w w  . j  a va2 s  .c  o  m*/
public List<OnRecordErrorException> writeBatch(Collection<Record> batch) throws StageException {
    List<OnRecordErrorException> errorRecords = new LinkedList<>();
    Connection connection = null;
    try {
        connection = getDataSource().getConnection();

        // Since we are doing multi-row inserts we have to partition the batch into groups of the same
        // set of fields. We'll also sort each partition for optimal inserts into column stores.
        Multimap<Long, Record> partitions = partitionBatch(batch);

        for (Long partitionKey : partitions.keySet()) {
            processPartition(connection, partitions, partitionKey, errorRecords);
        }
    } catch (SQLException e) {
        handleSqlException(e);
    } finally {
        if (connection != null) {
            try {
                connection.commit();
                connection.close();
            } catch (SQLException e) {
                handleSqlException(e);
            }
        }
    }
    return errorRecords;
}

From source file:fr.exanpe.tapestry.tldgen.taglib.builder.StructureBuilder.java

/**
 * Builds the output taglib structure//  w w w  .  ja v a  2  s .c o  m
 * 
 * @param rootPackage the root package to look the components for
 * @param supportedPackages all sub packages to scan
 * @param urls the urls used to scan the packages
 * @return the structure containing the information on the taglib to generate
 * @throws MojoExecutionException if any unexpected error occurs
 */
public Taglib build(String rootPackage, String[] supportedPackages, URL[] urls) throws MojoExecutionException {
    Taglib taglib = new Taglib();

    log.debug("Creating taglib object model...");

    for (String subPackage : supportedPackages) {
        String pkgname = rootPackage + "." + subPackage;

        log.debug("Processing taglib for full package named : " + pkgname);

        Reflections reflections = new Reflections(new ConfigurationBuilder()
                .filterInputsBy(new FilterBuilder.Include(FilterBuilder.prefix(pkgname))).setUrls(urls)
                .setScanners(new TypesScanner()));

        Store store = reflections.getStore();

        // Return classes anaylised by TypeScanner
        Multimap<String, String> classes = store.getStoreMap().values().iterator().next();

        log.debug(String.format("%s classes to analyse for %s package...", classes.keySet().size(), pkgname));

        // Loop on found classes
        for (final String s : classes.keySet()) {
            Class<?> c;
            try {
                log.debug(String.format("Load class %s into classloader", s));
                c = Thread.currentThread().getContextClassLoader().loadClass(s);
            } catch (ClassNotFoundException e) {
                // should not happen as it has just been parsed by Reflection...
                log.error(e);
                throw new MojoExecutionException("Class loader internal error for class :" + s, e);
            }

            if (!c.isAnnotation() && !c.isAnonymousClass() && !c.isEnum() && !c.isInterface()
                    && !c.isLocalClass() && !c.isMemberClass() && !c.isSynthetic()
                    && !Modifier.isAbstract(c.getModifiers())) {
                log.debug("Processing Tag : " + c.getName());

                Tag tag = buildTagFromClass(rootPackage, c);
                taglib.getTags().add(tag);
            }
        }
    }

    log.debug("Taglib object model completed");
    return taglib;
}

From source file:com.googlesource.gerrit.plugins.auditsl4j.AuditRendererToCsv.java

private Object getFormattedAuditList(Multimap<String, ?> params) {
    if (params == null || params.size() == 0) {
        return "[]";
    }//from   ww w  . java  2 s  .  c  om

    StringBuilder formattedOut = new StringBuilder("[");

    Set<String> paramNames = new TreeSet<>(params.keySet());

    int numParams = 0;
    for (String paramName : paramNames) {
        if (numParams++ > 0) {
            formattedOut.append(",");
        }
        formattedOut.append(paramName);
        formattedOut.append("=");
        formattedOut.append(getFormattedAudit(params.get(paramName)));
    }

    formattedOut.append(']');

    return formattedOut.toString();
}