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

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

Introduction

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

Prototype

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

Source Link

Document

Removes a single key-value pair with the key key and the value value from this multimap, if such exists.

Usage

From source file:org.sonar.java.checks.verifier.CheckVerifier.java

private static void validateIssue(Multimap<Integer, Map<IssueAttribute, String>> expected,
        List<Integer> unexpectedLines, AnalyzerMessage issue,
        @Nullable RemediationFunction remediationFunction) {
    int line = issue.getLine();
    if (expected.containsKey(line)) {
        Map<IssueAttribute, String> attrs = Iterables.getLast(expected.get(line));
        assertEquals(issue.getMessage(), attrs, IssueAttribute.MESSAGE);
        Double cost = issue.getCost();
        if (cost != null) {
            Preconditions.checkState(remediationFunction != RemediationFunction.CONST,
                    "Rule with constant remediation function shall not provide cost");
            assertEquals(Integer.toString(cost.intValue()), attrs, IssueAttribute.EFFORT_TO_FIX);
        } else if (remediationFunction == RemediationFunction.LINEAR) {
            Fail.fail("A cost should be provided for a rule with linear remediation function");
        }/*from   w  w  w .  j a v a2  s .com*/
        validateAnalyzerMessage(attrs, issue);
        expected.remove(line, attrs);
    } else {
        unexpectedLines.add(line);
    }
}

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);
        }//from w  ww. j av a  2 s .  c  om

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

From source file:org.wso2.siddhi.debs2016.graph.CommentLikeGraph.java

/**
 * Register a new like for the comment/*from   w  w  w.ja v a2  s . com*/
 *
 * @param userId is user id of person who likes comment
 * @param componentSizeCommentMap is reference to Map that holds size and comment string of each comment
 */
public void registerLike(long userId, Multimap<Long, String> componentSizeCommentMap) {
    graph.addVertex(userId);
    Set<Long> verticesList = graph.getVerticesList();
    for (long vertex : verticesList) {
        if (friendshipGraph.hasEdge(userId, vertex)) {
            graph.addEdge(userId, vertex);
        }
    }
    if (sizeOfLargestConnectedComponent != 0) {
        componentSizeCommentMap.remove(getSizeOfLargestConnectedComponent(), comment);
    }
    sizeOfLargestConnectedComponent = computeLargestConnectedComponent();
    componentSizeCommentMap.put(sizeOfLargestConnectedComponent, comment);
}

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

@Override
public void remove(final Triple triple) {
    this.rwlock.writeLock().lock();
    try {/*from w w  w. ja  v  a  2  s  . co  m*/
        if (this.contains(triple)) {
            final Multimap<Long, Long> multimap = this.internalstore.get(triple.getPredicate());
            multimap.remove(triple.getSubject(), triple.getObject());
            this.triples--;
            if (multimap.isEmpty()) {
                this.internalstore.remove(triple.getPredicate());
            }
        }
    } catch (final Exception e) {
        logger.error("", e);
    } finally {
        this.rwlock.writeLock().unlock();
    }
}

From source file:nars.op.mental.Anticipate.java

protected void mayHaveHappenedAsExpected(@NotNull Task c) {

    if (!c.isInput() || c.isEternal()) {
        return; //it's not a input task, the system is not allowed to convince itself about the state of affairs ^^
    }/*  w w  w  .  j a  v  a  2s . co  m*/

    float freq = c.freq();
    long cOccurr = c.occurrence();

    final List<Task> toRemove = this.toRemove;

    int tolerance = nar.duration();

    Multimap<Compound, Task> a = this.anticipations;
    Compound ct = c.term();

    a.get(ct).stream().filter(tt -> inTime(freq, tt, cOccurr, tolerance)).forEach(tt -> {
        toRemove.add(tt);
        happeneds++;
    });

    toRemove.forEach(tt -> a.remove(ct, tt));
    toRemove.clear();

}

From source file:edu.uci.ics.jung.graph.DirectedSparseHypergraph.java

@Override
public boolean removeEdge(E edge) {
    if (!containsEdge(edge))
        return false;

    Collection<V> sourceSet = getSourceSet(edge);
    Collection<V> destSet = getDestSet(edge);

    // remove vertices from each others' adjacency maps
    for (V source : sourceSet) {
        Multimap<V, E> sourceOut = vertices.get(source).getSecond();
        for (V dest : destSet) {
            sourceOut.remove(dest, edge);
        }//  w w w  . ja v a  2  s  . com
    }
    for (V dest : destSet) {
        Multimap<V, E> destIn = vertices.get(dest).getFirst();
        for (V source : sourceSet) {
            destIn.remove(source, edge);
        }
    }

    edges.remove(edge);
    return true;
}

From source file:co.cask.cdap.internal.app.verification.FlowVerification.java

/**
 * Verifies a single {@link FlowSpecification} for a {@link co.cask.cdap.api.flow.Flow}.
 *
 * @param input to be verified//from ww  w  .  j  a v a 2s.  co m
 * @return An instance of {@link VerifyResult} depending of status of verification.
 */
@Override
public VerifyResult verify(Id.Application appId, final FlowSpecification input) {
    VerifyResult verifyResult = super.verify(appId, input);
    if (!verifyResult.isSuccess()) {
        return verifyResult;
    }

    String flowName = input.getName();

    // Check if there are no flowlets.
    if (input.getFlowlets().isEmpty()) {
        return VerifyResult.failure(Err.Flow.ATLEAST_ONE_FLOWLET, flowName);
    }

    // Check if there no connections.
    if (input.getConnections().isEmpty()) {
        return VerifyResult.failure(Err.Flow.ATLEAST_ONE_CONNECTION, flowName);
    }

    // We go through each Flowlet and verify the flowlets.

    // First collect all source flowlet names
    Set<String> sourceFlowletNames = Sets.newHashSet();
    for (FlowletConnection connection : input.getConnections()) {
        if (connection.getSourceType() == FlowletConnection.Type.FLOWLET) {
            sourceFlowletNames.add(connection.getSourceName());
        }
    }

    for (Map.Entry<String, FlowletDefinition> entry : input.getFlowlets().entrySet()) {
        FlowletDefinition defn = entry.getValue();
        String flowletName = defn.getFlowletSpec().getName();

        // Check if the Flowlet Name is an ID.
        if (!isId(defn.getFlowletSpec().getName())) {
            return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName);
        }

        // We check if all the dataset names used are ids
        for (String dataSet : defn.getDatasets()) {
            if (!isId(dataSet)) {
                return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName + ":" + dataSet);
            }
        }

        // Check if the flowlet has output, it must be appear as source flowlet in at least one connection
        if (entry.getValue().getOutputs().size() > 0 && !sourceFlowletNames.contains(flowletName)) {
            return VerifyResult.failure(Err.Flow.OUTPUT_NOT_CONNECTED, flowName, flowletName);
        }
    }

    // NOTE: We should unify the logic here and the queue spec generation, as they are doing the same thing.
    Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> queueSpecTable = new SimpleQueueSpecificationGenerator(
            appId).create(input);

    // For all connections, there should be an entry in the table.
    for (FlowletConnection connection : input.getConnections()) {
        QueueSpecificationGenerator.Node node = new QueueSpecificationGenerator.Node(connection.getSourceType(),
                connection.getSourceName());
        if (!queueSpecTable.contains(node, connection.getTargetName())) {
            return VerifyResult.failure(Err.Flow.NO_INPUT_FOR_OUTPUT, flowName, connection.getTargetName(),
                    connection.getSourceType(), connection.getSourceName());
        }
    }

    // For each output entity, check for any unconnected output
    for (QueueSpecificationGenerator.Node node : queueSpecTable.rowKeySet()) {
        // For stream output, no need to check
        if (node.getType() == FlowletConnection.Type.STREAM) {
            continue;
        }

        // For all outputs of a flowlet, remove all the matched connected schema, if there is anything left,
        // then it's a incomplete flow connection (has output not connect to any input).
        Multimap<String, Schema> outputs = toMultimap(input.getFlowlets().get(node.getName()).getOutputs());
        for (Map.Entry<String, Set<QueueSpecification>> entry : queueSpecTable.row(node).entrySet()) {
            for (QueueSpecification queueSpec : entry.getValue()) {
                outputs.remove(queueSpec.getQueueName().getSimpleName(), queueSpec.getOutputSchema());
            }
        }

        if (!outputs.isEmpty()) {
            return VerifyResult.failure(Err.Flow.MORE_OUTPUT_NOT_ALLOWED, flowName,
                    node.getType().toString().toLowerCase(), node.getName(), outputs);
        }
    }

    return VerifyResult.success();
}

From source file:org.gradle.plugins.ide.idea.model.internal.IdeaDependenciesOptimizer.java

private void applyScopeToNextDependency(Iterator<Dependency> iterator,
        Multimap<Object, GeneratedIdeaScope> scopesByDependencyKey) {
    Dependency dep = iterator.next();/* ww w  .  j  av a 2s  . c o  m*/
    Object key = getKey(dep);
    Collection<GeneratedIdeaScope> ideaScopes = scopesByDependencyKey.get(key);
    if (ideaScopes.isEmpty()) {
        iterator.remove();
    } else {
        GeneratedIdeaScope scope = ideaScopes.iterator().next();
        dep.setScope(scope.name());
        scopesByDependencyKey.remove(key, scope);
    }
}

From source file:com.android.ide.common.res2.AbstractResourceRepository.java

private void removeItem(@NonNull ResourceItem removedItem) {
    synchronized (ITEM_MAP_LOCK) {
        Multimap<String, ResourceItem> map = getMap(removedItem.getType(), false);
        if (map != null) {
            map.remove(removedItem.getName(), removedItem);
        }//  www.jav  a2  s.  c o  m
    }
}

From source file:com.b2international.snowowl.snomed.reasoner.server.classification.EquivalentConceptMerger.java

private void removeDeprecatedRelationships(final Concept conceptToKeep,
        final Collection<Concept> conceptsToRemove,
        final Multimap<String, Relationship> inboundRelationshipMap) {
    for (final Relationship inboundRelationship : Sets
            .newHashSet(inboundRelationshipMap.get(conceptToKeep.getId()))) {
        if (conceptsToRemove.contains(inboundRelationship.getSource())) {
            if (inboundRelationshipMap.containsValue(inboundRelationship)) {
                inboundRelationshipMap.remove(inboundRelationship.getDestination().getId(),
                        inboundRelationship);
            }//from   ww w .j av a 2  s .  c  o m
            SnomedModelExtensions.removeOrDeactivate(inboundRelationship);
        }
    }

    for (final Relationship outboundRelationship : newArrayList(conceptToKeep.getOutboundRelationships())) {
        if (conceptsToRemove.contains(outboundRelationship.getDestination())) {
            if (inboundRelationshipMap.containsValue(outboundRelationship)) {
                inboundRelationshipMap.remove(outboundRelationship.getDestination().getId(),
                        outboundRelationship);
            }
            SnomedModelExtensions.removeOrDeactivate(outboundRelationship);
        }
    }
}