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

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this multimap contains no key-value pairs.

Usage

From source file:org.sosy_lab.cpachecker.cpa.octagon.refiner.OctagonDelegatingRefiner.java

private boolean performOctagonAnalysisRefinement(final ARGReachedSet reached,
        final OctagonAnalysisFeasabilityChecker checker) {
    UnmodifiableReachedSet reachedSet = reached.asReachedSet();
    Precision precision = reachedSet.getPrecision(reachedSet.getLastState());
    VariableTrackingPrecision octPrecision = (VariableTrackingPrecision) Precisions.asIterable(precision)
            .filter(VariableTrackingPrecision.isMatchingCPAClass(OctagonCPA.class)).get(0);

    Multimap<CFANode, MemoryLocation> increment = checker.getPrecisionIncrement(octPrecision);
    // no newly tracked variables, so the refinement was not successful, TODO why is this code commented out?
    if (increment.isEmpty()) {
        //  return false;
    }/*from   ww w  .j  a  va  2s. c om*/

    reached.removeSubtree(((ARGState) reachedSet.getFirstState()).getChildren().iterator().next(),
            octPrecision.withIncrement(increment),
            VariableTrackingPrecision.isMatchingCPAClass(OctagonCPA.class));
    logger.log(Level.INFO,
            "Refinement successful, precision incremented, following variables are now tracked additionally:\n"
                    + increment);

    return true;
}

From source file:org.opencms.ui.dialogs.CmsDeleteDialog.java

/**
 * Displays the broken links.<p>//from ww  w .  j ava 2  s .  c  o m
 */
void displayBrokenLinks() {

    CmsObject cms = A_CmsUI.getCmsObject();
    m_resourceBox.removeAllComponents();
    m_deleteResource.setValue(CmsVaadinUtils
            .getMessageText(org.opencms.workplace.commons.Messages.GUI_DELETE_MULTI_CONFIRMATION_0));
    m_okButton.setVisible(true);
    boolean canIgnoreBrokenLinks = OpenCms.getWorkplaceManager().getDefaultUserSettings()
            .isAllowBrokenRelations() || OpenCms.getRoleManager().hasRole(cms, CmsRole.VFS_MANAGER);
    try {
        Multimap<CmsResource, CmsResource> brokenLinks = getBrokenLinks(cms, m_context.getResources(),
                CmsResource.DELETE_REMOVE_SIBLINGS.equals(m_deleteSiblings.getValue()));
        if (brokenLinks.isEmpty()) {
            m_linksLabel.setVisible(false);
            String noLinksBroken = CmsVaadinUtils
                    .getMessageText(org.opencms.workplace.commons.Messages.GUI_DELETE_RELATIONS_NOT_BROKEN_0);
            m_resourceBox.addComponent(new Label(noLinksBroken));
        } else {
            if (!canIgnoreBrokenLinks) {
                m_deleteResource.setValue(CmsVaadinUtils.getMessageText(
                        org.opencms.workplace.commons.Messages.GUI_DELETE_RELATIONS_NOT_ALLOWED_0));
                m_okButton.setVisible(false);
            }
            for (CmsResource source : brokenLinks.keySet()) {
                m_resourceBox.addComponent(new CmsResourceInfo(source));
                for (CmsResource target : brokenLinks.get(source)) {
                    m_resourceBox.addComponent(indent(new CmsResourceInfo(target)));
                }

            }
        }
    } catch (CmsException e) {
        m_context.error(e);
        return;
    }
}

From source file:org.sosy_lab.cpachecker.cpa.apron.refiner.ApronDelegatingRefiner.java

private boolean performApronAnalysisRefinement(final ARGReachedSet reached,
        final ApronAnalysisFeasabilityChecker checker) {
    UnmodifiableReachedSet reachedSet = reached.asReachedSet();
    Precision precision = reachedSet.getPrecision(reachedSet.getLastState());
    VariableTrackingPrecision apronPrecision = (VariableTrackingPrecision) Precisions.asIterable(precision)
            .filter(VariableTrackingPrecision.isMatchingCPAClass(ApronCPA.class)).get(0);

    Multimap<CFANode, MemoryLocation> increment = checker.getPrecisionIncrement(apronPrecision);
    // no newly tracked variables, so the refinement was not successful // TODO why is this commented out
    if (increment.isEmpty()) {
        //  return false;
    }//from ww w. j  a va  2 s. co  m

    reached.removeSubtree(((ARGState) reachedSet.getFirstState()).getChildren().iterator().next(),
            apronPrecision.withIncrement(increment),
            VariableTrackingPrecision.isMatchingCPAClass(ApronCPA.class));

    logger.log(Level.INFO,
            "Refinement successful, precision incremented, following variables are now tracked additionally:\n"
                    + increment);

    return true;
}

From source file:hu.bme.mit.trainbenchmark.benchmark.fourstore.driver.FourStoreDriver.java

public void insertEdgesWithVertex(final Multimap<String, String> edges, final String edgeType,
        final String targetVertexType) throws IOException {
    if (edges.isEmpty()) {
        return;/*w  w w  . j  ava  2 s.  co m*/
    }

    final ArrayList<String> sourceVertices = new ArrayList<>(edges.keySet());
    final List<List<String>> sourceVerticesPartitions = Lists.partition(sourceVertices, PARTITION_SIZE);
    for (final List<String> sourceVerticesPartition : sourceVerticesPartitions) {

        final Multimap<String, String> edgePartition = ArrayListMultimap.create();
        for (final String sourceVertexURI : sourceVerticesPartition) {
            final Collection<String> targetVertexURIs = edges.get(sourceVertexURI);
            edgePartition.putAll(sourceVertexURI, targetVertexURIs);
        }

        insertEdgesWithVertexPartition(edgePartition, edgeType, targetVertexType);
    }

}

From source file:com.facebook.presto.accumulo.index.IndexLookup.java

/**
 * Scans the index table, applying the index based on the given column constraints to return a set of tablet splits.
 * <p>//from   w  ww .ja  v  a 2 s .  c o  m
 * If this function returns true, the output parameter tabletSplits contains a list of TabletSplitMetadata objects.
 * These in turn contain a collection of Ranges containing the exact row IDs determined using the index.
 * <p>
 * If this function returns false, the secondary index should not be used. In this case,
 * either the accumulo session has disabled secondary indexing,
 * or the number of row IDs that would be used by the secondary index is greater than the configured threshold
 * (again retrieved from the session).
 *
 * @param schema Schema name
 * @param table Table name
 * @param session Current client session
 * @param constraints All column constraints (this method will filter for if the column is indexed)
 * @param rowIdRanges Collection of Accumulo ranges based on any predicate against a record key
 * @param tabletSplits Output parameter containing the bundles of row IDs determined by the use of the index.
 * @param serializer Instance of a row serializer
 * @param auths Scan-time authorizations
 * @return True if the tablet splits are valid and should be used, false otherwise
 * @throws Exception If something bad happens. What are the odds?
 */
public boolean applyIndex(String schema, String table, ConnectorSession session,
        Collection<AccumuloColumnConstraint> constraints, Collection<Range> rowIdRanges,
        List<TabletSplitMetadata> tabletSplits, AccumuloRowSerializer serializer, Authorizations auths)
        throws Exception {
    // Early out if index is disabled
    if (!isOptimizeIndexEnabled(session)) {
        LOG.debug("Secondary index is disabled");
        return false;
    }

    LOG.debug("Secondary index is enabled");

    // Collect Accumulo ranges for each indexed column constraint
    Multimap<AccumuloColumnConstraint, Range> constraintRanges = getIndexedConstraintRanges(constraints,
            serializer);

    // If there is no constraints on an index column, we again will bail out
    if (constraintRanges.isEmpty()) {
        LOG.debug("Query contains no constraints on indexed columns, skipping secondary index");
        return false;
    }

    // If metrics are not enabled
    if (!isIndexMetricsEnabled(session)) {
        LOG.debug("Use of index metrics is disabled");
        // Get the ranges via the index table
        List<Range> indexRanges = getIndexRanges(getIndexTableName(schema, table), constraintRanges,
                rowIdRanges, auths);

        if (!indexRanges.isEmpty()) {
            // Bin the ranges into TabletMetadataSplits and return true to use the tablet splits
            binRanges(getNumIndexRowsPerSplit(session), indexRanges, tabletSplits);
            LOG.debug("Number of splits for %s.%s is %d with %d ranges", schema, table, tabletSplits.size(),
                    indexRanges.size());
        } else {
            LOG.debug("Query would return no results, returning empty list of splits");
        }

        return true;
    } else {
        LOG.debug("Use of index metrics is enabled");
        // Get ranges using the metrics
        return getRangesWithMetrics(session, schema, table, constraintRanges, rowIdRanges, tabletSplits, auths);
    }
}

From source file:com.b2international.snowowl.core.internal.validation.ValidationRepositoryContext.java

void commit() {
    if (!newObjects.isEmpty() || !objectsToDelete.isEmpty()) {
        final Set<String> ruleIdsAffectedByDeletion = Sets.newHashSet();
        service(ValidationRepository.class).write(writer -> {
            writer.putAll(newObjects);//w  w w. ja v  a 2s .c o  m

            final Multimap<String, ComponentIdentifier> addToWhitelist = HashMultimap.create();
            newObjects.values().stream().filter(ValidationWhiteList.class::isInstance)
                    .map(ValidationWhiteList.class::cast).forEach(whitelist -> addToWhitelist
                            .put(whitelist.getRuleId(), whitelist.getComponentIdentifier()));

            if (!addToWhitelist.isEmpty()) {
                ExpressionBuilder filter = Expressions.builder();
                for (String ruleId : addToWhitelist.keySet()) {
                    filter.should(Expressions.builder()
                            .filter(Expressions.exactMatch(ValidationIssue.Fields.RULE_ID, ruleId))
                            .filter(Expressions.matchAny(ValidationIssue.Fields.AFFECTED_COMPONENT_ID,
                                    addToWhitelist.get(ruleId).stream().map(ComponentIdentifier::getComponentId)
                                            .collect(Collectors.toSet())))
                            .build());
                }
                writer.bulkUpdate(
                        new BulkUpdate<>(ValidationIssue.class, filter.build(), ValidationIssue.Fields.ID,
                                ValidationIssue.Scripts.WHITELIST, ImmutableMap.of("whitelisted", true)));
            }

            final Multimap<String, ComponentIdentifier> removeFromWhitelist = HashMultimap.create();
            ValidationRequests.whiteList().prepareSearch().all()
                    .filterByIds(ImmutableSet.copyOf(objectsToDelete.get(ValidationWhiteList.class))).build()
                    .execute(this).forEach(whitelist -> removeFromWhitelist.put(whitelist.getRuleId(),
                            whitelist.getComponentIdentifier()));

            if (!removeFromWhitelist.isEmpty()) {
                ExpressionBuilder filter = Expressions.builder();
                for (String ruleId : removeFromWhitelist.keySet()) {
                    ruleIdsAffectedByDeletion.add(ruleId);
                    filter.should(Expressions.builder()
                            .filter(Expressions.exactMatch(ValidationIssue.Fields.RULE_ID, ruleId))
                            .filter(Expressions.matchAny(ValidationIssue.Fields.AFFECTED_COMPONENT_ID,
                                    removeFromWhitelist.get(ruleId).stream()
                                            .map(ComponentIdentifier::getComponentId)
                                            .collect(Collectors.toSet())))
                            .build());
                }
                writer.bulkUpdate(
                        new BulkUpdate<>(ValidationIssue.class, filter.build(), ValidationIssue.Fields.ID,
                                ValidationIssue.Scripts.WHITELIST, ImmutableMap.of("whitelisted", false)));
            }

            final Map<Class<?>, Set<String>> docsToDelete = newHashMap();
            objectsToDelete.asMap().forEach((type, ids) -> docsToDelete.put(type, ImmutableSet.copyOf(ids)));
            writer.removeAll(docsToDelete);

            writer.commit();
            return null;
        });

        if (!newObjects.isEmpty()) {
            final Set<String> addedWhiteLists = newHashSet();
            final Set<String> affectedRuleIds = newHashSet();
            newObjects.forEach((id, doc) -> {
                if (doc instanceof ValidationWhiteList) {
                    ValidationWhiteList whitelistedDoc = (ValidationWhiteList) doc;
                    affectedRuleIds.add(whitelistedDoc.getRuleId());
                    addedWhiteLists.add(id);
                }
            });
            if (!addedWhiteLists.isEmpty()) {
                WhiteListNotification.added(addedWhiteLists, affectedRuleIds).publish(service(IEventBus.class));
            }
        }

        if (!objectsToDelete.isEmpty()) {
            final Set<String> removedWhiteLists = ImmutableSet
                    .copyOf(objectsToDelete.get(ValidationWhiteList.class));
            if (!removedWhiteLists.isEmpty()) {
                WhiteListNotification.removed(removedWhiteLists, ruleIdsAffectedByDeletion)
                        .publish(service(IEventBus.class));
            }
        }
    }
}

From source file:org.opendaylight.yangtools.yang.model.repo.util.AbstractSchemaRepository.java

private synchronized <T extends SchemaSourceRepresentation> void removeSource(
        final PotentialSchemaSource<?> source, final SchemaSourceRegistration<?> reg) {
    final Multimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> m = sources
            .get(source.getSourceIdentifier());
    if (m != null) {
        m.remove(source.getRepresentation(), reg);

        for (SchemaListenerRegistration l : listeners) {
            l.getInstance().schemaSourceUnregistered(source);
        }/*www  . j av  a2  s.  c o m*/

        if (m.isEmpty()) {
            sources.remove(source.getSourceIdentifier());
        }
    }
}

From source file:com.palantir.atlasdb.cleaner.Scrubber.java

void queueCellsForScrubbing(Multimap<Cell, String> cellToTableNames, long scrubTimestamp) {
    if (cellToTableNames.isEmpty()) {
        return;//from  w  ww . j  a  va 2s.  com
    }
    scrubberStore.queueCellsForScrubbing(cellToTableNames, scrubTimestamp, batchSizeSupplier.get());
}

From source file:org.sonar.java.se.JavaCheckVerifier.java

private void assertMultipleIssue(Set<AnalyzerMessage> issues) throws AssertionError {
    Preconditions.checkState(!issues.isEmpty(), "At least one issue expected");
    List<Integer> unexpectedLines = Lists.newLinkedList();
    Multimap<Integer, Expectations.Issue> expected = expectations.issues;

    for (AnalyzerMessage issue : issues) {
        validateIssue(expected, unexpectedLines, issue);
    }//from   w  w w. ja  v  a 2 s  . c  o m
    if (!expected.isEmpty() || !unexpectedLines.isEmpty()) {
        Collections.sort(unexpectedLines);
        String expectedMsg = !expected.isEmpty() ? ("Expected " + expected) : "";
        String unexpectedMsg = !unexpectedLines.isEmpty()
                ? ((expectedMsg.isEmpty() ? "" : ", ") + "Unexpected at " + unexpectedLines)
                : "";
        fail(expectedMsg + unexpectedMsg);
    }
    assertSuperfluousFlows();
}

From source file:com.btoddb.chronicle.Chronicle.java

/**
 * Should be called by a {@link Catcher} after receiving events.
 *
 * @param catcherId ID of the catcher for reporting and routing
 * @param events list of {@link Event}s//from  ww w.  j  a  v  a2  s.c om
 */
public void handleCatcher(String catcherId, Collection<Event> events) {
    Multimap<PlunkerRunner, Event> routingMap = LinkedListMultimap.create();

    // divide events by route
    for (Event event : events) {
        for (Router router : config.getRouters().values()) {
            PlunkerRunner runner;
            if (null != (runner = router.canRoute(catcherId, event))) {
                routingMap.put(runner, event);
            }
        }
    }

    if (!routingMap.isEmpty()) {
        for (PlunkerRunner runner : routingMap.keySet()) {
            try {
                runner.run(routingMap.get(runner));
            } catch (Exception e) {
                Utils.logAndThrow(logger,
                        String.format("exception while handle events from catcher, %s", catcherId), e);
            }
        }
    } else {
        config.getErrorHandler().handle(events);
    }
}