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

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

Introduction

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

Prototype

boolean putAll(Multimap<? extends K, ? extends V> multimap);

Source Link

Document

Stores all key-value pairs of multimap in this multimap, in the order returned by multimap.entries() .

Usage

From source file:org.opendaylight.controller.config.yang.store.impl.ExtenderYangTracker.java

@Override
public synchronized Object addingBundle(Bundle bundle, BundleEvent event) {

    // Ignore system bundle:
    // system bundle might have config-api on classpath &&
    // config-api contains yang files =>
    // system bundle might contain yang files from that bundle
    if (bundle.getBundleId() == 0)
        return bundle;

    if (maybeBlacklist.isPresent()) {
        Matcher m = maybeBlacklist.get().matcher(bundle.getSymbolicName());
        if (m.matches()) {
            logger.debug("Ignoring {} because it is in blacklist {}", bundle, maybeBlacklist);
            return bundle;
        }/*w w w.  j  a  va2s  .com*/
    }

    Enumeration<URL> enumeration = bundle.findEntries("META-INF/yang", "*.yang", false);
    if (enumeration != null && enumeration.hasMoreElements()) {
        synchronized (this) {
            List<URL> addedURLs = new ArrayList<>();
            while (enumeration.hasMoreElements()) {
                URL url = enumeration.nextElement();
                addedURLs.add(url);
            }
            logger.trace("Bundle {} has event {}, bundle state {}, URLs {}", bundle, event, bundle.getState(),
                    addedURLs);
            // test that yang store is consistent
            Multimap<Bundle, URL> proposedNewState = HashMultimap.create(consistentBundlesToYangURLs);
            proposedNewState.putAll(inconsistentBundlesToYangURLs);
            proposedNewState.putAll(bundle, addedURLs);

            Preconditions.checkArgument(addedURLs.size() > 0, "No change can occur when no URLs are changed");

            try (YangStoreSnapshotImpl snapshot = createSnapshot(mbeParser, proposedNewState)) {
                onSnapshotSuccess(proposedNewState, snapshot);
            } catch (YangStoreException e) {
                onSnapshotFailure(bundle, addedURLs, e);
            }
        }
    }
    return bundle;
}

From source file:org.yakindu.sct.ui.editor.validation.DefaultValidationIssueStore.java

@Override
public void processIssues(List<Issue> issues, IProgressMonitor monitor) {

    final Multimap<String, SCTIssue> newVisibleIssues = ArrayListMultimap.create();
    for (Issue issue : issues) {
        if (issue instanceof SCTIssue) {
            String semanticURI = ((SCTIssue) issue).getSemanticURI();
            newVisibleIssues.put(semanticURI, (SCTIssue) issue);
        }/* ww  w  .j av a2  s . com*/
    }

    final Multimap<String, SCTIssue> oldVisibleIssues = ArrayListMultimap.create();
    synchronized (visibleIssues) {
        oldVisibleIssues.putAll(visibleIssues);
        // normal and expensive checks will not be executed by the live
        // validation, so persistent markers have to be copied
        Iterable<SCTIssue> persistentIssues = Iterables.filter(visibleIssues.values(),
                new Predicate<SCTIssue>() {
                    public boolean apply(SCTIssue input) {
                        CheckType type = input.getType();
                        Severity severity = input.getSeverity();
                        return CheckType.NORMAL == type || CheckType.EXPENSIVE == type
                                || Severity.INFO == severity;
                    }
                });
        for (SCTIssue sctIssue : persistentIssues) {
            newVisibleIssues.put(sctIssue.getSemanticURI(), sctIssue);
        }
        visibleIssues.clear();
        visibleIssues.putAll(newVisibleIssues);
    }

    SetView<String> changes = Sets.symmetricDifference(oldVisibleIssues.keySet(), newVisibleIssues.keySet());
    for (String string : changes) {
        notifyListeners(string);
    }

    SetView<String> intersection = Sets.intersection(oldVisibleIssues.keySet(), newVisibleIssues.keySet());
    for (String string : intersection) {
        if (changedSeverity(string, oldVisibleIssues, newVisibleIssues)
                || changedErrorCount(string, oldVisibleIssues, newVisibleIssues)) {
            notifyListeners(string);
        }
    }

}

From source file:com.github.sprial404.ss.item.crafting.RecipeRegistry.java

private void init() {
    Multimap<CustomWrappedStack, List<CustomWrappedStack>> recipes = HashMultimap.create();

    // Add potion recipes
    recipes.putAll(RecipesPotions.getPotionRecipes());

    // Add smelting recipes in the vanilla smelting manager
    recipes.putAll(RecipesSmelting.getSmeltingRecipes());

    // Add recipes in the vanilla crafting manager
    recipes.putAll(RecipesVanilla.getVanillaRecipes());

    // Add recipes gathered via IMC
    // TODO Gather IMC recipes

    // Populate the discovered stacks list with all stacks that we are
    // involved in a recipe we are aware of
    discoverStacks(recipes);/* ww  w.jav a 2s.  c  o  m*/

    // Add items that have no recipe, using the list of discovered stacks to
    // determine if it's in a recipe or not
    for (CustomWrappedStack stack : recipelessStacks) {
        recipes.put(stack, new ArrayList<CustomWrappedStack>());
    }

    // Iterate through every recipe in the map, and add them to the registry
    Set<CustomWrappedStack> recipeKeySet = recipes.keySet();
    Iterator<CustomWrappedStack> recipeKeySetIterator = recipeKeySet.iterator();
    CustomWrappedStack recipeOutput = null;

    while (recipeKeySetIterator.hasNext()) {
        recipeOutput = recipeKeySetIterator.next();

        for (List<CustomWrappedStack> recipeInputs : recipes.get(recipeOutput)) {
            addRecipe(recipeOutput, recipeInputs);
        }
    }
}

From source file:com.google.enterprise.connector.ldap.LdapSchemaFinder.java

public SchemaResult find(int maxResults) {
    Multimap<String, String> tempSchema = ArrayListMultimap.create();
    Set<SchemaResultError> errors = Sets.newHashSet();
    int resultCount = 0;
    for (Entry<String, Multimap<String, String>> entry : supplier.get().entrySet()) {
        String key = entry.getKey();
        Multimap<String, String> person = entry.getValue();
        tempSchema.putAll(person);
        resultCount++;//from w ww . jav  a  2s. co  m
        if (resultCount >= maxResults) {
            break;
        }
    }
    ImmutableMultimap<String, String> schema = ImmutableMultimap.copyOf(tempSchema);
    SchemaResult schemaResult = new SchemaResult(schema, resultCount, errors);
    return schemaResult;
}

From source file:org.codice.ddf.transformer.xml.streaming.lib.SaxEventToXmlElementConverter.java

private SaxEventToXmlElementConverter startConstructingElement(String uri, String localName, Attributes atts)
        throws XMLStreamException {
    Multimap<String, String> addedNamespaces = ArrayListMultimap.create();
    if (scopeOfNamespacesAdded.peek() != null) {
        addedNamespaces.putAll(scopeOfNamespacesAdded.peek());
    }/* w w  w  .  ja  v  a  2 s .  co m*/
    scopeOfNamespacesAdded.push(addedNamespaces);
    // URI to prefix
    Map<String, String> scopedNamespaces = new HashMap<>();
    Iterator<NamespaceMapping> iter = namespaceStack.descendingIterator();
    while (iter.hasNext()) {
        NamespaceMapping tmpPair = iter.next();

        // switch prefix and URI
        scopedNamespaces.put(tmpPair.getUri(), tmpPair.getPrefix());
    }

    /*
     * Use the uri to look up the namespace prefix and append it and the localName to the start tag
     */
    out.writeStartElement(scopedNamespaces.get(uri), localName, uri);
    if (!checkNamespaceAdded(uri, scopedNamespaces)) {
        out.writeNamespace(scopedNamespaces.get(uri), uri);
        addedNamespaces.put(uri, scopedNamespaces.get(uri));
    }
    /*
     * Loop through the attributes and append them, prefixed with the proper namespace
     * We loop through the attributes twice to ensure all "xmlns" attributes are declared before
     * other attributes
     */
    for (int i = 0; i < atts.getLength(); i++) {
        if (atts.getURI(i).isEmpty()) {
            out.writeAttribute(atts.getLocalName(i), atts.getValue(i));
        } else {
            String attUri = atts.getURI(i);

            if (!checkNamespaceAdded(attUri, scopedNamespaces)) {
                out.writeNamespace(scopedNamespaces.get(attUri), attUri);
                addedNamespaces.put(attUri, scopedNamespaces.get(attUri));
            }
            try {
                out.writeAttribute(scopedNamespaces.get(attUri), attUri, atts.getLocalName(i),
                        atts.getValue(i));

                /*
                 * XML doesn't allow for duplicate attributes in an element, e.g.
                 * no <element attribute=1 attribute=2>
                 * no <element ns1:attribute=1 ns2:attribute=2 xlmns:ns1=foobar xlmns:ns2=foobar>
                 * however - if one of the namespaces is the default namespace, this duplication is okay,
                 * yes <element attribute=1 ns1:attribute=2 xlmns=foobar xmlns:ns1=foobar>
                 *
                 * This catch block handles this edge case
                 */
            } catch (XMLStreamException e) {
                /*
                 * Get the first non-empty prefix that is associated with the URI (the other, non-default prefix)
                 */
                handleNamespaceDupes(atts, addedNamespaces, i, attUri);
            }
        }
    }

    return this;
}

From source file:edu.buaa.satla.analysis.core.predicate.PredicatePrecision.java

/**
 * Create a new precision which is a copy of the current one with some
 * additional location-specific predicates.
 *///from   ww  w  .j  a v  a2  s.com
public PredicatePrecision addLocalPredicates(Multimap<CFANode, AbstractionPredicate> newPredicates) {
    Multimap<CFANode, AbstractionPredicate> predicates = ArrayListMultimap.create(getLocalPredicates());
    predicates.putAll(newPredicates);

    // During lookup, we do not look into getGlobalPredicates() and getFunctionPredicates(),
    // if there is something for the key in predicates.
    // Thus, we copy the relevant items into the predicates set here.
    if (!getGlobalPredicates().isEmpty() || !getFunctionPredicates().isEmpty()) {
        for (CFANode newLoc : newPredicates.keySet()) {
            predicates.putAll(newLoc, getFunctionPredicates().get(newLoc.getFunctionName()));
            predicates.putAll(newLoc, getGlobalPredicates());
        }
    }

    return new PredicatePrecision(getLocationInstancePredicates(), predicates, getFunctionPredicates(),
            getGlobalPredicates());
}

From source file:edu.buaa.satla.analysis.core.predicate.PredicatePrecision.java

/**
 * Create a new precision which is a copy of the current one with some
 * additional function-specific predicates.
 *//*from   ww w. j a  v  a  2s.c  om*/
public PredicatePrecision addFunctionPredicates(Multimap<String, AbstractionPredicate> newPredicates) {
    Multimap<String, AbstractionPredicate> predicates = ArrayListMultimap.create(getFunctionPredicates());
    predicates.putAll(newPredicates);

    // During lookup, we do not look into getGlobalPredicates(),
    // if there is something for the key in predicates.
    // Thus, we copy the relevant items into the predicates set here.
    if (!getGlobalPredicates().isEmpty()) {
        for (String function : newPredicates.keySet()) {
            predicates.putAll(function, getGlobalPredicates());
        }
    }

    return new PredicatePrecision(getLocationInstancePredicates(), getLocalPredicates(), predicates,
            getGlobalPredicates());
}

From source file:uk.ac.ebi.mdk.io.text.kegg.KEGGReactionEntry.java

/**
 * Produces a representation of the reaction as a Multimap, where the keys are compound identifiers and values their
 * coefficient as strings, having reactants a minus sign before the number. Multimaps are required because polymeric
 * reactions have the same compounds at both sides. The map doesn't use numbers for the same reason (m, n, m+1, n+1,
 * coefficients used in polymeric reaction case).
 *
 * @return reaction represented as a multimap, keys are compound ids.
 *//*from  w w w .  java 2 s.co  m*/
public Multimap<String, String> getCompId2coeff() {
    if (compId2coeff == null) {
        Joiner joiner = Joiner.on(" ");
        Multimap<String, String> comp2coeff = HashMultimap.create();
        String eqLines = joiner.join(get(KEGGReactionField.EQUATION));
        if (eqLines.length() > 0) {
            String[] eqSides = this.parseReaction(eqLines);
            if (eqSides.length == 2) {
                comp2coeff.putAll(this.parseReactionSide(eqSides[0], "-"));
                comp2coeff.putAll(this.parseReactionSide(eqSides[1], ""));
            }
        }
        this.compId2coeff = comp2coeff;
    }
    return compId2coeff;
}

From source file:edu.buaa.satla.analysis.core.predicate.PredicatePrecision.java

/**
 * Create a new precision which is a copy of the current one with some
 * additional location-instance-specific predicates.
 *///from w ww .  j  a va  2s  . com
public PredicatePrecision addLocationInstancePredicates(
        Multimap<Pair<CFANode, Integer>, AbstractionPredicate> newPredicates) {
    Multimap<Pair<CFANode, Integer>, AbstractionPredicate> predicates = ArrayListMultimap
            .create(getLocationInstancePredicates());
    predicates.putAll(newPredicates);

    // During lookup, we do not look into getGlobalPredicates(),
    // getFunctionPredicates(), and getLocalPredicates(),
    // if there is something for the key in predicates.
    // Thus, we copy the relevant items into the predicates set here.
    if (!getGlobalPredicates().isEmpty() || !getFunctionPredicates().isEmpty()
            || !getLocalPredicates().isEmpty()) {
        for (Pair<CFANode, Integer> key : newPredicates.keySet()) {
            CFANode loc = key.getFirst();
            predicates.putAll(key, getLocalPredicates().get(loc));
            predicates.putAll(key, getFunctionPredicates().get(loc.getFunctionName()));
            predicates.putAll(key, getGlobalPredicates());
        }
    }

    return new PredicatePrecision(predicates, getLocalPredicates(), getFunctionPredicates(),
            getGlobalPredicates());
}

From source file:org.jclouds.cleanup.doclet.ClassDocParser.java

private Collection<String> extractComment(String defaultCommentText, Multimap<String, String> defaultTags,
        ProgramElementDoc... elements) {
    String commentText = null;/*from  w  w  w .j  a v  a 2  s . c o m*/
    for (ProgramElementDoc element : elements) {
        if (element != null && element.commentText() != null && !element.commentText().trim().isEmpty()) {
            commentText = element.commentText();
            break;
        }
    }

    if (commentText == null) {
        commentText = defaultCommentText;
    }

    Multimap<String, String> tagsToOutput = LinkedListMultimap.create();
    if (defaultTags != null)
        tagsToOutput.putAll(defaultTags);

    for (ProgramElementDoc element : elements) {
        if (element != null) {
            for (Tag tag : element.tags()) {
                tagsToOutput.put(tag.name(), tag.text());
            }
        }
    }

    if (commentText == null && tagsToOutput.isEmpty())
        return ImmutableList.of();

    List<String> result = Lists.newArrayList();

    if (commentText != null) {
        for (String line : commentText.split("\n")) {
            result.add(line.trim());
        }
        if (!tagsToOutput.isEmpty()) {
            result.add("");
        }
    }

    for (Map.Entry<String, String> tag : tagsToOutput.entries()) {
        result.add(tag.getKey() + " " + tag.getValue());
    }

    return result;
}