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

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

Introduction

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

Prototype

boolean containsEntry(@Nullable Object key, @Nullable Object value);

Source Link

Document

Returns true if this multimap contains at least one key-value pair with the key key and the value value .

Usage

From source file:org.sosy_lab.cpachecker.cpa.bam.BAMARGUtils.java

private static void gatherReachedSets(BAMCPA cpa, Block block, ReachedSet reachedSet,
        Multimap<Block, ReachedSet> blockToReachedSet) {
    if (blockToReachedSet.containsEntry(block, reachedSet)) {
        return; //avoid looping in recursive block calls
    }/*from   ww  w .jav a  2s.co  m*/

    blockToReachedSet.put(block, reachedSet);

    ARGState firstElement = (ARGState) reachedSet.getFirstState();

    Deque<ARGState> worklist = new LinkedList<>();
    Set<ARGState> processed = new HashSet<>();

    worklist.add(firstElement);

    while (worklist.size() != 0) {
        ARGState currentElement = worklist.removeLast();

        assert reachedSet.contains(currentElement);

        if (processed.contains(currentElement)) {
            continue;
        }
        processed.add(currentElement);

        for (ARGState child : currentElement.getChildren()) {
            CFAEdge edge = currentElement.getEdgeToChild(child);
            if (edge == null) {
                //this is a summary edge
                Pair<Block, ReachedSet> pair = cpa.getTransferRelation().getCachedReachedSet(currentElement,
                        reachedSet.getPrecision(currentElement));
                gatherReachedSets(cpa, pair.getFirst(), pair.getSecond(), blockToReachedSet);
            }
            if (!worklist.contains(child)) {
                if (reachedSet.contains(child)) {
                    worklist.add(child);
                }
            }
        }
    }
}

From source file:com.palantir.atlasdb.keyvalue.partition.util.MergeResults.java

private static void mergeAllTimestampsMapIntoMap(Multimap<Cell, Long> globalResult,
        Multimap<Cell, Long> partResult) {
    for (Map.Entry<Cell, Long> e : partResult.entries()) {
        if (!globalResult.containsEntry(e.getKey(), e.getValue())) {
            globalResult.put(e.getKey(), e.getValue());
        }//  w w  w  . j av a  2s  . c  o m
    }
}

From source file:com.wrmsr.wava.basic.BasicLoopInfo.java

public static Set<Name> getLoopContents(Name loop, Multimap<Name, Name> inputs,
        Multimap<Name, Name> backEdges) {
    Set<Name> seen = new HashSet<>();
    seen.add(loop);/* w w w . j  a  v a  2  s .c  om*/
    Queue<Name> queue = new LinkedList<>();
    inputs.get(loop).stream().filter(n -> !n.equals(loop) && backEdges.containsEntry(loop, n))
            .forEach(queue::add);
    queue.forEach(seen::add);
    while (!queue.isEmpty()) {
        Name cur = queue.poll();
        inputs.get(cur).stream().filter(input -> !seen.contains(input)).forEach(input -> {
            seen.add(input);
            queue.add(input);
        });
    }
    return seen;
}

From source file:com.android.tools.lint.checks.ViewTypeDetector.java

private static void addViewTags(Multimap<String, String> map, Element element) {
    String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
    if (id != null && !id.isEmpty()) {
        id = LintUtils.stripIdPrefix(id);
        if (!map.containsEntry(id, element.getTagName())) {
            map.put(id, element.getTagName());
        }/* w  w w  .  j  a va 2 s .  c o m*/
    }

    NodeList children = element.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            addViewTags(map, (Element) child);
        }
    }
}

From source file:com.forerunnergames.tools.common.Utils.java

/**
 * Finds the key from its associated value in a multiMap.
 *
 * @param value//w  w  w .j  a va 2 s  .co  m
 *          The value whose key is to be searched for.
 * @param multiMap
 *          The multiMap to search in.
 *
 * @return The key, if found; Integer.MIN_VALUE otherwise.
 */
public static int findKeyFromValue(final int value, Multimap<Integer, Integer> multiMap) {
    Arguments.checkIsNotNull(value, "value");
    Arguments.checkIsNotNull(multiMap, "multiMap");

    boolean foundKey = false;

    java.util.Iterator<Integer> keyIterator = multiMap.keySet().iterator();

    Integer boxedKey = Integer.MIN_VALUE;
    Integer boxedValue = Integer.valueOf(value);

    while (keyIterator.hasNext() && !foundKey) {
        boxedKey = keyIterator.next();

        if (multiMap.containsEntry(boxedKey, boxedValue))
            foundKey = true;
    }

    assert foundKey;

    return boxedKey;
}

From source file:org.waveprotocol.box.server.waveserver.MemoryPerUserWaveViewHandlerImpl.java

@Override
public ListenableFuture<Void> onParticipantRemoved(WaveletName waveletName, ParticipantId user) {
    Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user);
    if (perUserView != null) {
        if (perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) {
            perUserView.remove(waveletName.waveId, waveletName.waveletId);
            LOG.fine("Removed wavelet: " + waveletName + " from the view of user: " + user.getAddress());
        }//from   ww w .j  a v  a  2 s .c  o m
    }
    SettableFuture<Void> task = SettableFuture.create();
    task.set(null);
    return task;
}

From source file:org.waveprotocol.box.server.waveserver.MemoryPerUserWaveViewHandlerImpl.java

@Override
public ListenableFuture<Void> onParticipantAdded(WaveletName waveletName, ParticipantId user) {
    Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user);
    if (perUserView != null) {
        if (!perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) {
            perUserView.put(waveletName.waveId, waveletName.waveletId);
            if (LOG.isFineLoggable()) {
                LOG.fine("Added wavelet: " + waveletName + " to the view of user: " + user.getAddress());
                LOG.fine("View size is now: " + perUserView.size());
            }/* w  w  w .  j  a  v  a  2  s . co  m*/
        }
    }
    SettableFuture<Void> task = SettableFuture.create();
    task.set(null);
    return task;
}

From source file:org.ambraproject.wombat.model.SearchFilterFactory.java

/**
 * Examines the current URL parameters, and toggles the selected parameter.
 *
 * @param displayName used to retrieve the filter value from the filter type map
 * @param params current URL parameters to be modified
 * @param filterType used to retrieve selected filter parameter name and value
 * @return filtered URL parameter List//from   ww w .  ja  va2s. co m
 */
private ListMultimap<String, String> applyFilterToParams(String displayName, Multimap<String, String> params,
        SearchFilterType filterType) {
    String filterValue = filterType.getFilterValue(displayName);
    String parameterName = filterType.getParameterName();

    ListMultimap<String, String> changedParams = LinkedListMultimap.create(params);
    if (params.containsEntry(parameterName, filterValue)) {
        changedParams.remove(parameterName, filterValue);
    } else {
        changedParams.put(parameterName, filterValue);
    }
    return changedParams;
}

From source file:steps.squash.BookingSteps.java

private void assertCourtBooked(Integer court, java.time.LocalTime time, java.time.LocalDate date,
        String shouldOrNot) {//w w w  . ja  v  a2 s .co m
    if (!this.courtAndTimeSlotChooserPage.isLoaded()) {
        this.courtAndTimeSlotChooserPage.get(Optional.empty());
    }
    if (!this.courtAndTimeSlotChooserPage.getDate().equals(date)) {
        this.courtAndTimeSlotChooserPage.selectDate(date);
    }

    Multimap<Integer, java.time.LocalTime> bookedTimes = this.courtAndTimeSlotChooserPage.getBookedStartTimes();
    if (shouldOrNot.equals("should")) {
        assertTrue("Expected court time to be booked: " + time.toString(),
                bookedTimes.containsEntry(court, time));
    } else {
        assertTrue("Expected court time to be unbooked: " + time.toString(),
                !bookedTimes.containsEntry(court, time));
    }
}

From source file:io.bazel.rules.closure.webfiles.Webset.java

/**
 * Loads graph of web files from proto manifests.
 *
 * @param manifests set of web rule target proto files in reverse topological order
 * @return set of web files and relationships between them, which could be mutated, although
 *     adding a single key will most likely result in a full rehash
 *//*from w  w  w. j a v a  2 s.  c o m*/
public static Webset load(Map<Path, WebfileManifestInfo> manifests, WebpathInterner interner) {
    int webfileCapacity = 0;
    int unlinkCapacity = 16; // LinkedHashMultimap#DEFAULT_KEY_CAPACITY
    for (WebfileManifestInfo manifest : manifests.values()) {
        webfileCapacity += manifest.getWebfileCount();
        unlinkCapacity = Math.max(unlinkCapacity, manifest.getUnlinkCount());
    }
    Map<Webpath, Webfile> webfiles = Maps.newLinkedHashMapWithExpectedSize(webfileCapacity);
    Multimap<Webpath, Webpath> links = LinkedHashMultimap.create(webfileCapacity, 4);
    Multimap<Webpath, Webpath> unlinks = LinkedHashMultimap.create(unlinkCapacity, 4);
    for (Map.Entry<Path, WebfileManifestInfo> entry : manifests.entrySet()) {
        Path manifestPath = entry.getKey();
        Path zipPath = WebfilesUtils.getIncrementalZipPath(manifestPath);
        WebfileManifestInfo manifest = entry.getValue();
        String label = manifest.getLabel();
        for (WebfileInfo info : manifest.getWebfileList()) {
            Webpath webpath = interner.get(info.getWebpath());
            webfiles.put(webpath, Webfile.create(webpath, zipPath, label, info));
        }
        for (MultimapInfo mapping : manifest.getLinkList()) {
            Webpath from = interner.get(mapping.getKey());
            for (Webpath to : Iterables.transform(mapping.getValueList(), interner)) {
                // When compiling web_library rules, if the strict dependency checking invariant holds
                // true, we can choose to only load adjacent manifests, rather than transitive ones. The
                // adjacent manifests may contain links to transitive web files which will not be in the
                // webfiles map.
                if (webfiles.containsKey(to)) {
                    links.put(from, to);
                    checkArgument(!unlinks.containsEntry(from, to),
                            "Has a use case for resurrected links been discovered? %s -> %s", from, to);
                }
            }
        }
        for (MultimapInfo mapping : manifest.getUnlinkList()) {
            unlinks.putAll(interner.get(mapping.getKey()),
                    Collections2.transform(mapping.getValueList(), interner));
        }
    }
    for (Map.Entry<Webpath, Webpath> entry : unlinks.entries()) {
        links.remove(entry.getKey(), entry.getValue());
    }
    unlinks.clear();
    return new AutoValue_Webset(webfiles, links, interner);
}