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

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

Introduction

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

Prototype

Collection<Map.Entry<K, V>> entries();

Source Link

Document

Returns a view collection of all key-value pairs contained in this multimap, as Map.Entry instances.

Usage

From source file:fr.ujm.tse.lt2c.satin.triplestore.VerticalPartioningTripleStoreRWLock.java

@Override
public Collection<Triple> getAll() {
    this.rwlock.readLock().lock();
    final Collection<Triple> result = new ArrayList<>(this.triples);
    try {//from ww w.  j ava2 s .com
        for (final Long predicate : this.internalstore.keySet()) {
            final Multimap<Long, Long> multimap = this.internalstore.get(predicate);
            for (final Entry<Long, Long> entry : multimap.entries()) {
                result.add(new ImmutableTriple(entry.getKey(), predicate, entry.getValue()));
            }
        }
    } catch (final Exception e) {
        logger.error("", e);
    } finally {
        this.rwlock.readLock().unlock();
    }
    return result;
}

From source file:com.cloudera.flume.master.ConfigManager.java

synchronized void reloadLogicalToPhysical() {
    Multimap<String, String> p2n = getLogicalNodeMap();
    logicalToPhysical.clear();/*from  w  ww  .  j a v a2  s.  c o m*/
    for (Entry<String, String> e : p2n.entries()) {
        if (logicalToPhysical.containsKey(e.getValue())) {
            LOG.warn("logical node mapped to two physical nodes!");
        }
        logicalToPhysical.put(e.getValue(), e.getKey());
    }
}

From source file:ch.uzh.ifi.attempto.aceview.ui.view.ACESnippetEditorViewComponent.java

@Override
protected void displaySnippet(ACESnippet snippet) {
    if (!isSynchronizing())
        return;/*from  ww w.  ja v  a2  s.c o  m*/

    if (snippet == null) {
        resetUI();
        return;
    }

    getView().setHeaderText(snippet.toString());

    SnippetRenderer snippetRenderer = new SnippetRenderer(snippet);
    snippetEditor.setText(snippetRenderer.getRendering());
    snippetEditor.getHighlighter().removeAllHighlights();
    // Snippet editor buttons
    buttonNew.setEnabled(true);

    if (ACETextManager.getActiveACEText().contains(snippet)) {
        buttonUpdate.setEnabled(true);
        buttonDelete.setEnabled(true);
        if (snippet.getAxiom() == null) {
            buttonAnnotate.setEnabled(false);
        } else {
            buttonAnnotate.setEnabled(true);
        }
    } else {
        buttonUpdate.setEnabled(false);
        buttonDelete.setEnabled(false);
        buttonAnnotate.setEnabled(false);
    }

    if (snippet.isQuestion() || !snippet.hasAxioms()) {
        buttonWhy.setEnabled(false);
    } else {
        buttonWhy.setEnabled(true);
    }

    if (snippet.hasACEErrors()) {
        displayErrorMessage("The snippet contains ACE syntax errors.");
        Multimap<Integer, Integer> hlCoords = snippetRenderer.getSpans();

        for (Entry<Integer, Integer> entry : hlCoords.entries()) {
            try {
                logger.info("Added highlighter: coords: " + entry.getKey() + " " + entry.getValue());
                snippetEditor.getHighlighter().addHighlight(entry.getKey(), entry.getValue(),
                        new DefaultHighlighter.DefaultHighlightPainter(Colors.ERROR_COLOR));
            } catch (BadLocationException e) {
                e.printStackTrace();
            }
        }
    } else if (!snippet.hasAxioms()) {
        displayErrorMessage("The snippet contains no ACE syntax errors, but cannot be expressed in OWL/SWRL.");
    } else {
        clearMessage();
    }
}

From source file:com.google.devtools.build.lib.skyframe.TransitiveBaseTraversalFunction.java

/**
 * Return an Iterable of SkyKeys corresponding to the Aspect-related dependencies of target.
 *
 * <p>This method may return a precise set of aspect keys, but may need to request additional
 * dependencies from the env to do so./* ww  w .  j  a  v  a2s  .  c  o  m*/
 */
private Iterable<SkyKey> getStrictLabelAspectKeys(Target target,
        Map<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> depMap, Environment env)
        throws InterruptedException {
    List<SkyKey> depKeys = Lists.newArrayList();
    if (target instanceof Rule) {
        Map<Label, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> labelDepMap = new HashMap<>(
                depMap.size());
        for (Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> entry : depMap
                .entrySet()) {
            labelDepMap.put((Label) entry.getKey().argument(), entry.getValue());
        }

        Multimap<Attribute, Label> transitions = ((Rule) target)
                .getTransitions(DependencyFilter.NO_NODEP_ATTRIBUTES);
        for (Entry<Attribute, Label> entry : transitions.entries()) {
            ValueOrException2<NoSuchPackageException, NoSuchTargetException> value = labelDepMap
                    .get(entry.getValue());
            for (Label label : getAspectLabels((Rule) target, entry.getKey(), entry.getValue(), value, env)) {
                depKeys.add(getKey(label));
            }
        }
    }
    return depKeys;
}

From source file:io.helixservice.feature.restservice.controller.Request.java

/**
 * Create Request/*  w w w . ja  v  a2  s .  c  om*/
 */
public Request(String method, String requestURI, Multimap<String, String> params,
        Multimap<String, String> headers, T body, String remoteAddr, String httpVersion) {
    this.method = method;
    this.requestURI = requestURI;
    this.body = body;
    this.params = HashMultimap.create(params);
    this.headers = HashMultimap.create(headers);
    this.remoteAddr = remoteAddr;
    this.httpVersion = httpVersion;

    headersUppercase = HashMultimap.create();
    headers.entries().forEach(e -> headersUppercase.put(e.getKey().toUpperCase(), e.getValue()));
}

From source file:fr.ujm.tse.lt2c.satin.triplestore.VerticalPartioningTripleStoreRWLock.java

@Override
public Collection<Triple> getbyPredicate(final long p) {
    this.rwlock.readLock().lock();
    final Collection<Triple> result = new ArrayList<>(this.triples);
    try {//w w w  . j  a  v  a 2 s.c  om
        final Multimap<Long, Long> multimap = this.internalstore.get(p);
        if (multimap != null) {
            for (final Entry<Long, Long> entry : multimap.entries()) {
                result.add(new ImmutableTriple(entry.getKey(), p, entry.getValue()));
            }
        }
    } catch (final Exception e) {
        logger.error("", e);
    } finally {
        this.rwlock.readLock().unlock();
    }
    return result;
}

From source file:com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService.java

@Override
public void putWithTimestamps(String tableName, Multimap<Cell, Value> values) {
    putInternal(tableName, values.entries(), false);
}

From source file:org.lanternpowered.server.scoreboard.LanternScore.java

@Override
public void setScore(int score) {
    if (this.score == score) {
        return;/*w w  w. j ava 2s.  c o m*/
    }
    this.score = score;
    final Multimap<Scoreboard, Objective> scoreboards = HashMultimap.create();
    for (Objective objective : this.objectives) {
        for (Scoreboard scoreboard : ((LanternObjective) objective).scoreboards) {
            scoreboards.put(scoreboard, objective);
        }
    }
    if (!scoreboards.isEmpty()) {
        final Map<Objective, Message> messages = new HashMap<>();
        for (Map.Entry<Scoreboard, Objective> entry : scoreboards.entries()) {
            ((LanternScoreboard) entry.getKey())
                    .sendToPlayers(() -> Collections.singletonList(messages.computeIfAbsent(entry.getValue(),
                            obj -> new MessagePlayOutScoreboardScore.CreateOrUpdate(obj.getName(),
                                    this.legacyName, score))));
        }
    }
}

From source file:eu.esdihumboldt.cst.functions.core.join.JoinIterator.java

private void join(FamilyInstance[] currentInstances, int currentType) {
    // Join all types that are direct children of the last type.
    for (int i = currentType + 1; i < parent.length; i++) {
        if (parent[i] == currentType) {
            // Get join condition for the direct child type.
            Multimap<Integer, JoinCondition> joinConditions = joinTable.get(i);
            // Collect intersection of conditions. null marks beginning
            // in contrast to an empty set.
            Set<InstanceReference> possibleInstances = null;
            // ParentType -> JoinConditions
            for (Map.Entry<Integer, JoinCondition> joinCondition : joinConditions.entries()) {
                Collection<Object> currentValues = AlignmentUtil.getValues(
                        currentInstances[joinCondition.getKey()], joinCondition.getValue().baseProperty, true);

                if (currentValues == null) {
                    possibleInstances = Collections.emptySet();
                    break;
                }//  w  w w .j ava 2  s  .  c om

                // Allow targets with any of the property values.
                HashSet<InstanceReference> matches = new HashSet<InstanceReference>();
                for (Object currentValue : currentValues) {
                    Object keyValue = currentValue;
                    if (valueProcessor != null) {
                        keyValue = valueProcessor.processValue(currentValue,
                                joinCondition.getValue().baseProperty);
                    }
                    matches.addAll(index.get(joinCondition.getValue().joinProperty).get(keyValue));
                }
                if (possibleInstances == null)
                    possibleInstances = matches;
                else {
                    // Intersect!
                    Iterator<InstanceReference> iter = possibleInstances.iterator();
                    while (iter.hasNext()) {
                        InstanceReference ref = iter.next();
                        if (!matches.contains(ref))
                            iter.remove();
                    }
                }

                // Break if set is empty.
                if (possibleInstances.isEmpty())
                    break;
            }

            if (possibleInstances != null && !possibleInstances.isEmpty()) {
                FamilyInstance parent = currentInstances[currentType];
                for (InstanceReference ref : possibleInstances) {
                    FamilyInstance child;
                    if (ref instanceof ResolvableInstanceReference) {
                        child = new FamilyInstanceImpl(((ResolvableInstanceReference) ref).resolve());
                    } else {
                        child = new FamilyInstanceImpl(instances.getInstance(ref));
                    }
                    parent.addChild(child);
                    currentInstances[i] = child;
                    join(currentInstances, i);
                }
                currentInstances[i] = null;
            }
        }
    }
}

From source file:name.marcelomorales.siqisiqi.configuration.ConfigProvider.java

public Iterable<String> possibleConfigFilePositions() {

    // Filter out when APPDATA or HOME or anything else is missing
    final Multimap<String, String> applicableTemplates = Multimaps.filterKeys(TEMPLATES,
            new Predicate<String>() {

                @Override/*w w  w.  j  a  v a  2 s.  c  o  m*/
                public boolean apply(@Nullable String input) {
                    return Strings.isNullOrEmpty(input) || !Strings.isNullOrEmpty(System.getenv(input));
                }
            });

    final Iterable<String> transform = Iterables.transform(applicableTemplates.entries(),
            new Function<Map.Entry<String, String>, String>() {

                @Override
                public String apply(Map.Entry<String, String> input) {
                    return MessageFormat.format(input.getValue(), System.getenv(input.getKey()), vendorName,
                            applicationName);
                }
            });

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Will check all these paths in order {}", Iterables.toString(transform));
    }

    return transform;
}