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:org.eclipse.xtext.mwe.Validator.java

protected void appendMessages(StringBuilder result, MWEDiagnostic[] diagnostics) {
    Multimap<URI, MWEDiagnostic> issuesPerURI = groupByURI(diagnostics);
    boolean first = true;
    for (URI uri : issuesPerURI.keySet()) {
        if (!first)
            result.append('\n');
        first = false;/*w  w  w.j  a v a 2 s. c  o m*/
        if (uri != null) {
            result.append('\t').append(uri.lastSegment()).append(" - ");
            if (uri.isFile())
                result.append(uri.toFileString());
            else
                result.append(uri);
        }
        for (MWEDiagnostic diagnostic : issuesPerURI.get(uri)) {
            Issue issue = (Issue) diagnostic.getElement();
            result.append("\n\t\t").append(issue.getLineNumber()).append(": ").append(diagnostic.getMessage());
        }
    }
}

From source file:org.gradle.cache.internal.WrapperDistributionCleanupAction.java

public boolean execute(@Nonnull CleanupProgressMonitor progressMonitor) {
    long maximumTimestamp = Math.max(0, System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
    Set<GradleVersion> usedVersions = this.usedGradleVersions.getUsedGradleVersions();
    Multimap<GradleVersion, File> checksumDirsByVersion = determineChecksumDirsByVersion();
    for (GradleVersion version : checksumDirsByVersion.keySet()) {
        if (!usedVersions.contains(version) && version.compareTo(GradleVersion.current()) < 0) {
            deleteDistributions(checksumDirsByVersion.get(version), maximumTimestamp, progressMonitor);
        } else {/*from  w w  w  . j a  v a 2s  .c om*/
            progressMonitor.incrementSkipped(checksumDirsByVersion.get(version).size());
        }
    }
    return true;
}

From source file:org.sosy_lab.cpachecker.util.precondition.segkro.rules.PatternBasedRule.java

private Collection<Map<String, Formula>> getAllAssignments(Multimap<String, Formula> pFromBindings) {
    final Set<String> boundVariables = pFromBindings.keySet();
    final List<Collection<Formula>> dimensions = new ArrayList<>(boundVariables.size());
    for (String var : boundVariables) {
        dimensions.add(pFromBindings.get(var));
    }/*from  w w w.  j  a  v a 2s  .co m*/

    Collection<Map<String, Formula>> result = Lists.newArrayList();
    for (List<Formula> x : Cartesian.product(dimensions)) {
        final Map<String, Formula> tuple = Maps.newHashMap();
        final Iterator<Formula> xIt = x.iterator();
        for (String var : boundVariables) {
            Formula f = xIt.next();
            tuple.put(var, f);
        }
        result.add(tuple);
    }

    return result;
}

From source file:org.apache.metron.parsing.parsers.BasicFireEyeParser.java

private JSONObject parseMessage(String toParse) {

    // System.out.println("Received message: " + toParse);

    // MetronMatch gm = grok.match(toParse);
    // gm.captures();

    JSONObject toReturn = new JSONObject();
    //toParse = toParse.replaceAll("  ", " ");
    String[] mTokens = toParse.split("\\s+");
    //mTokens = toParse.split(" ");

    // toReturn.putAll(gm.toMap());

    String id = mTokens[4];/*  w  w w. j  a va 2 s.  c o  m*/

    // We are not parsing the fedata for multi part message as we cannot
    // determine how we can split the message and how many multi part
    // messages can there be.
    // The message itself will be stored in the response.

    String[] tokens = id.split("\\.");
    if (tokens.length == 2) {

        String[] array = Arrays.copyOfRange(mTokens, 1, mTokens.length - 1);
        String syslog = Joiner.on(" ").join(array);

        Multimap<String, String> multiMap = formatMain(syslog);

        for (String key : multiMap.keySet()) {

            String value = Joiner.on(",").join(multiMap.get(key));
            toReturn.put(key, value.trim());
        }

    }

    toReturn.put("original_string", toParse);

    String ip_src_addr = (String) toReturn.get("dvc");
    String ip_src_port = (String) toReturn.get("src_port");
    String ip_dst_addr = (String) toReturn.get("dst_ip");
    String ip_dst_port = (String) toReturn.get("dst_port");

    if (ip_src_addr != null)
        toReturn.put("ip_src_addr", ip_src_addr);
    if (ip_src_port != null)
        toReturn.put("ip_src_port", ip_src_port);
    if (ip_dst_addr != null)
        toReturn.put("ip_dst_addr", ip_dst_addr);
    if (ip_dst_port != null)
        toReturn.put("ip_dst_port", ip_dst_port);

    System.out.println(toReturn);

    return toReturn;
}

From source file:org.lanternpowered.server.network.vanilla.message.processor.play.ProcessorPlayOutTabListEntries.java

@Override
public void process(CodecContext context, MessagePlayOutTabListEntries message, List<Message> output)
        throws CodecException {
    final Multimap<Class<?>, Entry> entriesByType = HashMultimap.create();
    for (Entry entry : message.getEntries()) {
        entriesByType.put(entry.getClass(), entry);
    }/*from ww  w  .ja v  a2  s. c  o  m*/
    if (entriesByType.isEmpty()) {
        return;
    }
    if (entriesByType.keySet().size() == 1) {
        output.add(message);
    } else {
        for (java.util.Map.Entry<Class<?>, Collection<Entry>> en : entriesByType.asMap().entrySet()) {
            output.add(new MessagePlayOutTabListEntries(en.getValue()));
        }
    }
}

From source file:com.google.template.soy.pysrc.internal.PySrcMain.java

/**
 * Generates Python source files given a Soy parse tree, an options object, and information on
 * where to put the output files./*from  w  ww . jav  a2  s .  c  o m*/
 *
 * @param soyTree The Soy parse tree to generate Python source code for.
 * @param pySrcOptions The compilation options relevant to this backend.
 * @param outputPathFormat The format string defining how to build the output file path
 *     corresponding to an input file path.
 * @param inputPathsPrefix The input path prefix, or empty string if none.
 * @throws SoySyntaxException If a syntax error is found.
 * @throws IOException If there is an error in opening/writing an output Python file.
 */
public void genPyFiles(SoyFileSetNode soyTree, SoyPySrcOptions pySrcOptions, String outputPathFormat,
        String inputPathsPrefix) throws SoySyntaxException, IOException {

    List<String> pyFileContents = genPySrc(soyTree, pySrcOptions);

    ImmutableList<SoyFileNode> srcsToCompile = ImmutableList
            .copyOf(Iterables.filter(soyTree.getChildren(), SoyFileNode.MATCH_SRC_FILENODE));

    if (srcsToCompile.size() != pyFileContents.size()) {
        throw new AssertionError(String.format("Expected to generate %d code chunk(s), got %d",
                srcsToCompile.size(), pyFileContents.size()));
    }

    Multimap<String, Integer> outputs = MainEntryPointUtils.mapOutputsToSrcs(null, outputPathFormat,
            inputPathsPrefix, srcsToCompile);

    for (String outputFilePath : outputs.keySet()) {
        Writer out = Files.newWriter(new File(outputFilePath), Charsets.UTF_8);
        try {
            for (int inputFileIndex : outputs.get(outputFilePath)) {
                out.write(pyFileContents.get(inputFileIndex));
            }
        } finally {
            out.close();
        }
    }
}

From source file:org.javersion.store.jdbc.DocumentVersionStoreJdbc.java

protected void doAppend(Multimap<Id, VersionNode<PropertyPath, Object, M>> versionsByDocId) {
    DocumentUpdateBatch<Id, M, V> batch = updateBatch(versionsByDocId.keys());

    for (Id docId : versionsByDocId.keySet()) {
        for (VersionNode<PropertyPath, Object, M> version : versionsByDocId.get(docId)) {
            batch.addVersion(docId, version);
        }//  www  . j  ava2  s. c o  m
    }

    batch.execute();
}

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

@SuppressWarnings("NonBooleanMethodNameMayNotStartWithQuestion")
public void hasTargetsNamed(String... artifacts) {
    Set<String> expected = Sets.newHashSet(artifacts);
    Multimap<String, NativeArtifact> groups = getArtifactsByName();
    if (!groups.keySet().equals(expected)) {
        failWithRawMessage("Not true that %s that qualified targets are <%s>. They are <%s>",
                getDisplaySubject(), expected, groups.keySet());
    }/*from   w w w . jav a2s.  c  om*/
}

From source file:net.shibboleth.idp.saml.saml1.profile.impl.FilterByQueriedAttributeDesignators.java

/** {@inheritDoc} */
@Override//w  ww .  j  av  a  2  s. c o  m
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {

    final Collection<IdPAttribute> keepers = new ArrayList<>(query.getAttributeDesignators().size());

    final Multimap<String, IdPAttribute> mapped = mapperService.mapAttributes(query.getAttributeDesignators());
    log.debug("Query content mapped to attribute IDs: {}", mapped.keySet());

    for (final IdPAttribute attribute : attributeContext.getIdPAttributes().values()) {
        if (mapped.containsKey(attribute.getId())) {
            log.debug("Retaining attribute '{}' requested by query", attribute.getId());
            keepers.add(attribute);
        } else {
            log.debug("Removing attribute '{}' not requested by query", attribute.getId());
        }
    }

    attributeContext.setIdPAttributes(keepers);
}

From source file:me.lukasczyk.busybox_preprocessor.core.Algorithm.java

/**
 * Runs the algorithm.//from w  ww. jav  a  2  s. c o m
 *
 * @throws InterruptedException In case of interruption by shutdown notifier
 */
public void run() throws InterruptedException {
    final Path busyBoxFileList = Paths.get(commandLineArguments.getArgumentValue("rootPath"))
            .resolve(commandLineArguments.getArgumentValue("busyboxFileList"));

    try (Stream<String> lines = Files.lines(busyBoxFileList)) {
        for (String line : (Iterable<String>) lines::iterator) {
            shutdownNotifier.shutdownIfNecessary();
            interfaceParsers.add(XMLInterfaceParser.create(commandLineArguments.getArgumentValue("rootPath"),
                    commandLineArguments.getArgumentValue("busyboxFiles"), line));
        }
    } catch (IOException | SAXException | ParserConfigurationException | XPathExpressionException pE) {
        logManager.log(Level.WARNING, pE.getLocalizedMessage());
    }

    final Multimap<String, String> neededFilesPerFile = getNeededFilesPerFile();

    for (String destinationFileName : neededFilesPerFile.keySet()) {
        try (FileWriter fw = new FileWriter(Paths.get(commandLineArguments.getArgumentValue("rootPath"))
                .resolve(commandLineArguments.getArgumentValue("busyboxFiles"))
                .resolve(destinationFileName + ".include.info").toFile(), true);
                BufferedWriter bw = new BufferedWriter(fw);
                PrintWriter destination = new PrintWriter(bw)) {
            for (String sourceFileName : neededFilesPerFile.get(destinationFileName)) {
                if (sourceFileName.equals("")) {
                    continue;
                }

                destination.println(sourceFileName);
            }
            logManager.log(Level.INFO, "Copied library functions to " + destinationFileName);
        } catch (IOException pE) {
            logManager.log(Level.WARNING, pE.getLocalizedMessage());
        }
    }
}