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

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

Introduction

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

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:org.eclipse.incquery.validation.runtime.ConstraintExtensionRegistry.java

/**
 * Processes the given configuration element: in case if it is an instance of IConstraintSpecification it puts it in
 * the provided Multimap with the editor Ids it is registered for.
 * //  w  ww.  j  a  v  a  2 s .c  o  m
 * @param result
 *            The Multimap in which the constraint specification will be placed with it's editorIds.
 * @param ce
 *            The configuration element to be processed.
 */
private static void processConstraintSpecificationConfigurationElement(
        Multimap<String, IProvider<IConstraintSpecification>> result, IConfigurationElement ce) {
    List<String> ids = new ArrayList<String>();
    for (IConfigurationElement child : ce.getChildren()) {
        if (child.getName().equals(ENABLED_FOR_EDITOR_ATTRIBUTE_NAME)) {
            String id = child.getAttribute(EDITOR_ID_ATTRIBUTE_NAME);
            if (id != null && !id.equals("")) {
                ids.add(id);
            }
        }
    }

    ConstraintSpecificationProvider constraintSpecificationProvider = new ConstraintSpecificationProvider(ce);
    if (ids.isEmpty()) {
        ids.add("*");
    }
    for (String id : ids) {
        result.put(id, constraintSpecificationProvider);
    }
}

From source file:de.tuberlin.dima.cuttlefish.preprocessing.parsing.NewsItemXmlParser.java

public static NewsItem toNewsItem(InputStream xml) throws Exception {

    Document doc = DB_FACTORY.newDocumentBuilder().parse(xml);

    doc.getDocumentElement().normalize();

    String title = textContentOrEmptyString(doc, "title");
    String headline = textContentOrEmptyString(doc, "headline");
    String text = textContentOrEmptyString(doc, "text");
    String dateline = textContentOrEmptyString(doc, "dateline");

    Node newsItemNode = doc.getElementsByTagName("newsitem").item(0);
    int itemID = Integer.parseInt(newsItemNode.getAttributes().getNamedItem("itemid").getNodeValue());
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date date = df.parse(newsItemNode.getAttributes().getNamedItem("date").getNodeValue());

    Multimap<String, String> codes = ArrayListMultimap.create();
    NodeList codesNodes = doc.getElementsByTagName("codes");
    int numCodes = codesNodes.getLength();
    for (int codesIndex = 0; codesIndex < numCodes; codesIndex++) {
        Node codesNode = codesNodes.item(codesIndex);
        String codeClass = codesNode.getAttributes().getNamedItem("class").getNodeValue();

        NodeList codeNodes = codesNode.getChildNodes();
        for (int codeIndex = 0; codeIndex < codeNodes.getLength(); codeIndex++) {

            if ("code".equals(codeNodes.item(codeIndex).getNodeName())) {
                String codeValue = codeNodes.item(codeIndex).getAttributes().getNamedItem("code")
                        .getNodeValue();
                codes.put(codeClass, codeValue);
            }//from   w w w  .  j  a  v a2  s .c om
        }
    }

    Map<String, String> dcs = Maps.newHashMap();
    NodeList dcNodes = doc.getElementsByTagName("dc");
    int numDcs = dcNodes.getLength();
    for (int index = 0; index < numDcs; index++) {
        String dcElement = dcNodes.item(index).getAttributes().getNamedItem("element").getNodeValue();
        String dcValue = dcNodes.item(index).getAttributes().getNamedItem("value").getNodeValue();
        dcs.put(dcElement, dcValue);
    }

    return new NewsItem(itemID, date, title, headline, text, dateline, codes, dcs);
}

From source file:com.celebihacker.ml.preprocess.rcv1.indexing.parsing.XmlToNewsItemParser.java

public static NewsItem toNewsItem(InputStream xml) throws Exception {
    Document doc = DB_FACTORY.newDocumentBuilder().parse(xml);

    doc.getDocumentElement().normalize();

    Node newsItemNode = doc.getElementsByTagName("newsitem").item(0);
    int itemID = Integer.parseInt(newsItemNode.getAttributes().getNamedItem("itemid").getNodeValue());

    String title = textContentOrEmptyString(doc, "title");
    String headline = textContentOrEmptyString(doc, "headline");
    String text = textContentOrEmptyString(doc, "text");
    String dateline = textContentOrEmptyString(doc, "dateline");

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date date = df.parse(newsItemNode.getAttributes().getNamedItem("date").getNodeValue());

    Multimap<String, String> codes = ArrayListMultimap.create();
    NodeList codesNodes = doc.getElementsByTagName("codes");
    int numCodes = codesNodes.getLength();

    for (int codesIndex = 0; codesIndex < numCodes; codesIndex++) {
        Node codesNode = codesNodes.item(codesIndex);
        String codeClass = codesNode.getAttributes().getNamedItem("class").getNodeValue();

        NodeList codeNodes = codesNode.getChildNodes();
        for (int codeIndex = 0; codeIndex < codeNodes.getLength(); codeIndex++) {

            if ("code".equals(codeNodes.item(codeIndex).getNodeName())) {
                String codeValue = codeNodes.item(codeIndex).getAttributes().getNamedItem("code")
                        .getNodeValue();
                codes.put(codeClass, codeValue);
            }//from   w w w  .  ja va 2s.  c  o m
        }
    }

    Map<String, String> dcs = Maps.newHashMap();
    NodeList dcNodes = doc.getElementsByTagName("dc");
    int numDcs = dcNodes.getLength();
    for (int index = 0; index < numDcs; index++) {
        String dcElement = dcNodes.item(index).getAttributes().getNamedItem("element").getNodeValue();
        String dcValue = dcNodes.item(index).getAttributes().getNamedItem("value").getNodeValue();
        dcs.put(dcElement, dcValue);
    }

    if (NewsItemV2Patcher.patch(codes))
        return new NewsItem(itemID, date, title, headline, text, dateline, codes, dcs);

    return null;
}

From source file:t9.T9algo.java

private static String nums_to_text(String num_string) throws FileNotFoundException, IOException {

    //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    String li[] = num_string.split("\\*");
    TreeMap<String, String[]> z = new TreeMap<>();
    for (String num_word : li) {
        String tmp[] = textonyms(num_word);
        z.put(num_word, tmp);//from   w ww  .j  av  a  2  s .  c om
    }
    String bnc_str;
    StringBuilder sb = new StringBuilder();

    BufferedReader br = new BufferedReader(
            new FileReader("/home/rb/NetBeansProjects/Test/src/test/all.num.o5.txt"));
    try {

        String line = br.readLine();

        while (line != null) {
            sb.append(line);
            sb.append(System.lineSeparator());
            line = br.readLine();
        }
        bnc_str = sb.toString();//.split("\\n");
        //   System.out.println(everything[1]);
    } finally {
        br.close();
    }
    Multimap<String, String> d3 = ArrayListMultimap.create();
    StringBuilder s_words = new StringBuilder();
    StringBuilder all_words = new StringBuilder();
    //      TreeMap<String,String> d3= new TreeMap<>();
    for (Map.Entry<String, String[]> entry : z.entrySet()) {
        String key = entry.getKey();
        String[] value = entry.getValue();
        for (String item : value) {
            String pattern = "(\\S*)" + item;
            Pattern r = Pattern.compile(pattern);
            Matcher m = r.matcher(bnc_str);
            int i;
            for (i = m.start() - 2; i >= 0; --i)
                if (bnc_str.charAt(i) == 32)
                    break;
            d3.put(item, bnc_str.substring(i + 1, m.start() - 1));

        }
        //   all_words.append(bnc_str.substring(i+1,m.start()-1)+" ");

        all_words.append(d3.get(key) + " ");

    }
    return all_words.toString();
}

From source file:org.eclipse.viatra.addon.validation.runtime.ConstraintExtensionRegistry.java

/**
 * Processes the given configuration element: in case if it is an instance of IConstraintSpecification it puts it in
 * the provided Multimap with the editor Ids it is registered for.
 * //  w  w  w  .  j ava2  s .c o m
 * @param result
 *            The Multimap in which the constraint specification will be placed with it's editorIds.
 * @param ce
 *            The configuration element to be processed.
 */
private static void processConstraintSpecificationConfigurationElement(
        Multimap<String, IProvider<IConstraintSpecification>> result, IConfigurationElement ce) {
    List<String> ids = new ArrayList<String>();
    for (IConfigurationElement child : ce.getChildren()) {
        if (child.getName().equals(ENABLED_FOR_EDITOR_ATTRIBUTE_NAME)) {
            String id = child.getAttribute(EDITOR_ID_ATTRIBUTE_NAME);
            if (id != null && !id.equals("")) {
                ids.add(id);
            }
        }
    }

    ConstraintSpecificationProvider constraintSpecificationProvider = new ConstraintSpecificationProvider(ce);
    if (ids.isEmpty()) {
        ids.add(WILDCARD_EDITOR_ID);
    }
    for (String id : ids) {
        result.put(id, constraintSpecificationProvider);
    }
}

From source file:com.google.idea.blaze.java.sync.source.SourceDirectoryCalculator.java

private static Multimap<WorkspacePath, SourceArtifact> sortArtifactLocationsByRootDirectory(
        BlazeContext context, Collection<WorkspacePath> rootDirectories, Collection<SourceArtifact> sources) {

    Multimap<WorkspacePath, SourceArtifact> result = ArrayListMultimap.create();

    for (SourceArtifact sourceArtifact : sources) {
        WorkspacePath foundWorkspacePath = rootDirectories.stream()
                .filter(rootDirectory -> isUnderRootDirectory(rootDirectory,
                        sourceArtifact.artifactLocation.getRelativePath()))
                .findFirst().orElse(null);

        if (foundWorkspacePath != null) {
            result.put(foundWorkspacePath, sourceArtifact);
        } else if (sourceArtifact.artifactLocation.isSource()) {
            ArtifactLocation sourceFile = sourceArtifact.artifactLocation;
            String message = String
                    .format("Did not add %s. You're probably using a java file from outside the workspace"
                            + " that has been exported using export_files. Don't do that.", sourceFile);
            IssueOutput.warn(message).submit(context);
        }//ww  w .  j  a v a  2 s. c  om
    }
    return result;
}

From source file:org.sonar.server.computation.task.projectanalysis.filemove.FileMoveDetectionStep.java

private static void electMatches(@Nullable List<Match> matches, ElectedMatches electedMatches,
        Multimap<String, Match> matchesPerFileForScore) {
    // no match for this score value, ignore
    if (matches == null) {
        return;//from  www.  java 2 s.c  o m
    }

    List<Match> matchesToValidate = electedMatches.filter(matches);
    if (matchesToValidate.isEmpty()) {
        return;
    }
    if (matchesToValidate.size() == 1) {
        Match match = matchesToValidate.get(0);
        electedMatches.add(match);
    } else {
        matchesPerFileForScore.clear();
        for (Match match : matchesToValidate) {
            matchesPerFileForScore.put(match.getDbKey(), match);
            matchesPerFileForScore.put(match.getReportKey(), match);
        }
        // validate non ambiguous matches (ie. the match is the only match of either the db file and the report file)
        for (Match match : matchesToValidate) {
            int dbFileMatchesCount = matchesPerFileForScore.get(match.getDbKey()).size();
            int reportFileMatchesCount = matchesPerFileForScore.get(match.getReportKey()).size();
            if (dbFileMatchesCount == 1 && reportFileMatchesCount == 1) {
                electedMatches.add(match);
            }
        }
    }
}

From source file:com.ardor3d.scenegraph.AbstractBufferData.java

public static void cleanAllVBOs(final Renderer deleter, final RenderContext context) {
    final Multimap<Object, Integer> idMap = ArrayListMultimap.create();

    // gather up expired vbos... these don't exist in our cache
    gatherGCdIds(idMap);/*  w w  w  .  j  av  a 2s  .  co m*/

    final Object glRep = context.getGlContextRep();
    // Walk through the cached items and delete those too.
    for (final AbstractBufferData<?> buf : _identityCache.keySet()) {
        // only worry about buffers that have received ids.
        if (buf._vboIdCache != null) {
            final Integer id = buf._vboIdCache.removeValue(glRep);
            if (id != null && id.intValue() != 0) {
                idMap.put(context.getGlContextRep(), id);
            }
        }
    }

    handleVBODelete(deleter, idMap);
}

From source file:org.napile.compiler.lang.types.SubstitutionUtils.java

private static void fillInDeepSubstitutor(@NotNull NapileType context, @NotNull TypeSubstitutor substitutor,
        @NotNull Map<TypeConstructor, NapileType> substitution,
        @Nullable Multimap<TypeConstructor, NapileType> fullSubstitution) {
    List<TypeParameterDescriptor> parameters = context.getConstructor().getParameters();
    List<NapileType> arguments = context.getArguments();

    if (parameters.size() != arguments.size()) {
        throw new IllegalStateException();
    }/*  w w w  . ja  v a 2  s .  c  om*/

    for (int i = 0; i < arguments.size(); i++) {
        NapileType argument = arguments.get(i);
        TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);

        NapileType substitute = substitutor.substitute(argument, null);
        assert substitute != null;

        substitution.put(typeParameterDescriptor.getTypeConstructor(), substitute);
        if (fullSubstitution != null) {
            fullSubstitution.put(typeParameterDescriptor.getTypeConstructor(), substitute);
        }
    }
    if (TypeUtils.isEqualFqName(context, NapileLangPackage.NULL))
        return;
    for (NapileType supertype : context.getConstructor().getSupertypes()) {
        fillInDeepSubstitutor(supertype, substitutor, substitution, fullSubstitution);
    }
}

From source file:com.ardor3d.scenegraph.AbstractBufferData.java

public static void cleanAllVBOs(final Renderer deleter) {
    final Multimap<Object, Integer> idMap = ArrayListMultimap.create();

    // gather up expired vbos... these don't exist in our cache
    gatherGCdIds(idMap);/*  w w  w. j a v a 2s.com*/

    // Walk through the cached items and delete those too.
    for (final AbstractBufferData<?> buf : _identityCache.keySet()) {
        if (buf._vboIdCache != null) {
            if (Constants.useMultipleContexts) {
                final Set<Object> contextObjects = buf._vboIdCache.getContextObjects();
                for (final Object o : contextObjects) {
                    // Add id to map
                    idMap.put(o, buf.getVBOID(o));
                }
            } else {
                idMap.put(ContextManager.getCurrentContext().getGlContextRep(), buf.getVBOID(null));
            }
            buf._vboIdCache.clear();
        }
    }

    handleVBODelete(deleter, idMap);
}