Example usage for com.google.common.collect ListMultimap removeAll

List of usage examples for com.google.common.collect ListMultimap removeAll

Introduction

In this page you can find the example usage for com.google.common.collect ListMultimap removeAll.

Prototype

@Override
List<V> removeAll(@Nullable Object key);

Source Link

Document

Because the values for a given key may have duplicates and follow the insertion ordering, this method returns a List , instead of the java.util.Collection specified in the Multimap interface.

Usage

From source file:msi.gama.lang.gaml.resource.GamlResource.java

private ModelDescription buildModelDescription(final LinkedHashMultimap<String, GamlResource> resources) {

    // Initializations
    GAML.getExpressionFactory().resetParser();
    final ModelFactory f = GAML.getModelFactory();
    final String modelPath = GamlResourceServices.getModelPathOf(this);
    final String projectPath = GamlResourceServices.getProjectPathOf(this);
    final boolean isEdited = GamlResourceServices.isEdited(this);
    final ValidationContext context = GamlResourceServices.getValidationContext(this);
    // If the resources imported are null, no need to go through their
    // validation
    if (resources == null) {
        final List<ISyntacticElement> self = Collections.singletonList(getSyntacticContents());
        return f.createModelDescription(projectPath, modelPath, self, context, isEdited, null);
    }//  ww w  . j a va 2  s  .co  m
    // If there are no micro-models
    final Set<String> keySet = resources.keySet();
    if (keySet.size() == 1 && keySet.contains(null)) {
        final Iterable<ISyntacticElement> selfAndImports = Iterables.concat(
                Collections.singleton(getSyntacticContents()),
                Multimaps.transformValues(resources, TO_SYNTACTIC_CONTENTS).get(null));
        return f.createModelDescription(projectPath, modelPath, selfAndImports, context, isEdited, null);
    }
    final ListMultimap<String, ISyntacticElement> models = ArrayListMultimap.create();
    models.put(null, getSyntacticContents());
    models.putAll(Multimaps.transformValues(resources, TO_SYNTACTIC_CONTENTS));
    final List<ISyntacticElement> ownImports = models.removeAll(null);
    final Map<String, ModelDescription> compiledMicroModels = new THashMap<String, ModelDescription>();
    for (final String aliasName : models.keySet()) {
        final ModelDescription mic = GAML.getModelFactory().createModelDescription(projectPath, modelPath,
                models.get(aliasName), context, isEdited, null);
        mic.setAlias(aliasName);
        compiledMicroModels.put(aliasName, mic);
    }
    return f.createModelDescription(projectPath, modelPath, ownImports, context, isEdited, compiledMicroModels);
}

From source file:org.apache.cassandra.service.BatchlogEndpointSelector.java

/**
 * @param endpoints nodes in the local datacenter, grouped by rack name
 * @return list of candidates for batchlog hosting.  if possible these will be two nodes from different racks.
 *///from  w ww  . j a  v a2  s.  c  om
public Collection<InetAddress> chooseEndpoints(Multimap<String, InetAddress> endpoints) {
    // strip out dead endpoints and localhost
    ListMultimap<String, InetAddress> validated = ArrayListMultimap.create();
    for (Map.Entry<String, InetAddress> entry : endpoints.entries()) {
        if (isValid(entry.getValue()))
            validated.put(entry.getKey(), entry.getValue());
    }
    if (validated.size() <= 2)
        return validated.values();

    if ((validated.size() - validated.get(localRack).size()) >= 2) {
        // we have enough endpoints in other racks
        validated.removeAll(localRack);
    }

    if (validated.keySet().size() == 1) {
        // we have only 1 `other` rack
        Collection<InetAddress> otherRack = Iterables.getOnlyElement(validated.asMap().values());
        return Lists.newArrayList(Iterables.limit(otherRack, 2));
    }

    // randomize which racks we pick from if more than 2 remaining
    Collection<String> racks;
    if (validated.keySet().size() == 2) {
        racks = validated.keySet();
    } else {
        racks = Lists.newArrayList(validated.keySet());
        Collections.shuffle((List) racks);
    }

    // grab a random member of up to two racks
    List<InetAddress> result = new ArrayList<>(2);
    for (String rack : Iterables.limit(racks, 2)) {
        List<InetAddress> rackMembers = validated.get(rack);
        result.add(rackMembers.get(getRandomInt(rackMembers.size())));
    }

    return result;
}

From source file:org.opendaylight.mdsal.dom.broker.DOMRpcRoutingTable.java

DOMRpcRoutingTable remove(final DOMRpcImplementation implementation, final Set<DOMRpcIdentifier> rpcs) {
    if (rpcs.isEmpty()) {
        return this;
    }/* w w  w  .  j  a  v  a 2  s .c  om*/

    // First decompose the identifiers to a multimap
    final ListMultimap<SchemaPath, YangInstanceIdentifier> toRemove = decomposeIdentifiers(rpcs);

    // Now iterate over existing entries, modifying them as appropriate...
    final Builder<SchemaPath, AbstractDOMRpcRoutingTableEntry> b = ImmutableMap.builder();
    for (Entry<SchemaPath, AbstractDOMRpcRoutingTableEntry> e : this.rpcs.entrySet()) {
        final List<YangInstanceIdentifier> removed = new ArrayList<>(toRemove.removeAll(e.getKey()));
        if (!removed.isEmpty()) {
            final AbstractDOMRpcRoutingTableEntry ne = e.getValue().remove(implementation, removed);
            if (ne != null) {
                b.put(e.getKey(), ne);
            }
        } else {
            b.put(e);
        }
    }

    // All done, whatever is in toRemove, was not there in the first place
    return new DOMRpcRoutingTable(b.build(), schemaContext);
}

From source file:org.opendaylight.mdsal.dom.broker.DOMRpcRoutingTable.java

DOMRpcRoutingTable add(final DOMRpcImplementation implementation, final Set<DOMRpcIdentifier> rpcs) {
    if (rpcs.isEmpty()) {
        return this;
    }/*  w w w .  j a  va 2 s. c om*/

    // First decompose the identifiers to a multimap
    final ListMultimap<SchemaPath, YangInstanceIdentifier> toAdd = decomposeIdentifiers(rpcs);

    // Now iterate over existing entries, modifying them as appropriate...
    final Builder<SchemaPath, AbstractDOMRpcRoutingTableEntry> mb = ImmutableMap.builder();
    for (Entry<SchemaPath, AbstractDOMRpcRoutingTableEntry> re : this.rpcs.entrySet()) {
        List<YangInstanceIdentifier> newRpcs = new ArrayList<>(toAdd.removeAll(re.getKey()));
        if (!newRpcs.isEmpty()) {
            final AbstractDOMRpcRoutingTableEntry ne = re.getValue().add(implementation, newRpcs);
            mb.put(re.getKey(), ne);
        } else {
            mb.put(re);
        }
    }

    // Finally add whatever is left in the decomposed multimap
    for (Entry<SchemaPath, Collection<YangInstanceIdentifier>> e : toAdd.asMap().entrySet()) {
        final Builder<YangInstanceIdentifier, List<DOMRpcImplementation>> vb = ImmutableMap.builder();
        final List<DOMRpcImplementation> v = Collections.singletonList(implementation);
        for (YangInstanceIdentifier i : e.getValue()) {
            vb.put(i, v);
        }

        mb.put(e.getKey(), createRpcEntry(schemaContext, e.getKey(), vb.build()));
    }

    return new DOMRpcRoutingTable(mb.build(), schemaContext);
}

From source file:org.rf.ide.core.testdata.model.table.RobotExecutableRowView.java

private static void collectPrettyAlignsAndAssignmentAfterToken(
        final ListMultimap<RobotToken, RobotToken> specialTokens, final RobotToken token,
        final RobotLine robotLine) {
    final Optional<Integer> elementPositionInLine = robotLine.getElementPositionInLine(token);
    if (elementPositionInLine.isPresent()) {
        int lastAssignment = -1;
        final List<IRobotLineElement> lineElements = robotLine.getLineElements();
        final int lineElementsSize = lineElements.size();
        final List<RobotToken> tokensView = specialTokens.get(token);
        for (int i = elementPositionInLine.get() + 1; i < lineElementsSize; i++) {
            final IRobotLineElement lineElement = lineElements.get(i);
            final List<IRobotTokenType> elementTypes = lineElement.getTypes();
            if (lineElement.getClass() == RobotToken.class) {
                final RobotToken currentToken = (RobotToken) lineElement;
                if (elementTypes.contains(RobotTokenType.ASSIGNMENT)
                        || elementTypes.contains(RobotTokenType.PRETTY_ALIGN_SPACE)) {
                    specialTokens.put(token, currentToken);
                    if (elementTypes.contains(RobotTokenType.ASSIGNMENT)) {
                        lastAssignment = tokensView.size();
                    }/* www . j av a  2s.  c  om*/
                } else {
                    break;
                }
            } else {
                break;
            }
        }

        if (lastAssignment == -1) {
            specialTokens.removeAll(token);
        } else if (lastAssignment != tokensView.size()) {
            while (lastAssignment != tokensView.size()) {
                tokensView.remove(lastAssignment);
            }
        }
    }
}

From source file:org.eclipse.incquery.runtime.base.core.NavigationHelperContentAdapter.java

private List<EMFVisitor> popVisitorsSuspendedOnFeature(EObject source, EReference reference, EObject target) {
    ListMultimap<EObject, EMFVisitor> targetToVisitor = unresolvableProxyFeaturesMap.get(source, reference);
    if (targetToVisitor == null) {
        return Collections.emptyList();
    }/*from   w  w  w . ja va 2s .c o m*/
    final List<EMFVisitor> result = targetToVisitor.removeAll(target);
    if (targetToVisitor.isEmpty()) {
        unresolvableProxyFeaturesMap.remove(source, reference);
    }
    return result;
}

From source file:com.google.template.soy.sharedpasses.CheckTemplateParamsVisitor.java

@Override
protected void visitTemplateNode(TemplateNode node) {
    ListMultimap<String, SourceLocation> dataKeys = ArrayListMultimap.create();

    for (VarRefNode varRefNode : SoytreeUtils.getAllNodesOfType(node, VarRefNode.class)) {
        if (varRefNode.isPossibleParam()) {
            dataKeys.put(varRefNode.getName(), varRefNode.getSourceLocation());
        }//from w  w w  .j av  a 2 s  .  c  o m
    }

    IndirectParamsInfo ipi = new FindIndirectParamsVisitor(templateRegistry, errorReporter).exec(node);

    List<String> unusedParams = new ArrayList<>();
    for (TemplateParam param : node.getAllParams()) {
        if (dataKeys.containsKey(param.name())) {
            // Good: Declared and referenced in template. We remove these from dataKeys so
            // that at the end of the for-loop, dataKeys will only contain the keys that are referenced
            // but not declared in SoyDoc.
            dataKeys.removeAll(param.name());
        } else if (ipi.paramKeyToCalleesMultimap.containsKey(param.name())
                || ipi.mayHaveIndirectParamsInExternalCalls || ipi.mayHaveIndirectParamsInExternalDelCalls) {
            // Good: Declared in SoyDoc and either (a) used in a call that passes all data or (b) used
            // in an external call or delcall that passes all data, which may need the param (we can't
            // verify).
        } else {
            // Bad: Declared in SoyDoc but not referenced in template.
            unusedParams.add(param.name());
        }
    }

    // At this point, the only keys left in dataKeys are undeclared.
    for (Entry<String, SourceLocation> undeclared : dataKeys.entries()) {
        errorReporter.report(undeclared.getValue(), UNDECLARED_DATA_KEY, undeclared.getKey());
    }

    // Delegate templates can declare unused params because other implementations
    // of the same delegate may need to use those params.
    if (node instanceof TemplateBasicNode) {
        for (String unusedParam : unusedParams) {
            errorReporter.report(node.getSourceLocation(), UNUSED_PARAM, unusedParam);
        }
    }
}

From source file:com.google.template.soy.passes.CheckTemplateParamsVisitor.java

@Override
protected void visitTemplateNode(TemplateNode node) {
    ListMultimap<String, SourceLocation> dataKeys = ArrayListMultimap.create();

    for (VarRefNode varRefNode : SoytreeUtils.getAllNodesOfType(node, VarRefNode.class)) {
        if (varRefNode.isPossibleParam()) {
            dataKeys.put(varRefNode.getName(), varRefNode.getSourceLocation());
        }//from   w ww . java2  s  . co m
    }

    IndirectParamsInfo ipi = new FindIndirectParamsVisitor(templateRegistry).exec(node);

    Set<String> allParamNames = new HashSet<>();
    List<String> unusedParams = new ArrayList<>();
    for (TemplateParam param : node.getAllParams()) {
        allParamNames.add(param.name());
        if (dataKeys.containsKey(param.name())) {
            // Good: Declared and referenced in template. We remove these from dataKeys so
            // that at the end of the for-loop, dataKeys will only contain the keys that are referenced
            // but not declared in SoyDoc.
            dataKeys.removeAll(param.name());
        } else if (ipi.paramKeyToCalleesMultimap.containsKey(param.name())
                || ipi.mayHaveIndirectParamsInExternalCalls || ipi.mayHaveIndirectParamsInExternalDelCalls) {
            // Good: Declared in SoyDoc and either (a) used in a call that passes all data or (b) used
            // in an external call or delcall that passes all data, which may need the param (we can't
            // verify).
        } else {
            // Bad: Declared in SoyDoc but not referenced in template.
            unusedParams.add(param.name());
        }
    }

    // At this point, the only keys left in dataKeys are undeclared.
    for (Entry<String, SourceLocation> undeclared : dataKeys.entries()) {
        String extraErrorMessage = "";
        errorReporter.report(undeclared.getValue(), UNDECLARED_DATA_KEY, undeclared.getKey(),
                extraErrorMessage);
    }

    // Delegate templates can declare unused params because other implementations
    // of the same delegate may need to use those params.
    if (node instanceof TemplateBasicNode) {
        for (String unusedParam : unusedParams) {
            errorReporter.report(node.getSourceLocation(), UNUSED_PARAM, unusedParam);
        }
    }
}

From source file:com.google.template.soy.passes.CheckTemplateHeaderVarsPass.java

private void checkTemplate(TemplateNode node, TemplateRegistry templateRegistry) {
    if (node.isDeprecatedV1()) {
        return;//  w  w  w .j av a2  s .  c  o m
    }

    ListMultimap<String, SourceLocation> dataKeys = ArrayListMultimap.create();

    for (VarRefNode varRefNode : SoyTreeUtils.getAllNodesOfType(node, VarRefNode.class)) {
        if (varRefNode.isPossibleHeaderVar()) {
            dataKeys.put(varRefNode.getName(), varRefNode.getSourceLocation());
        }
    }

    IndirectParamsInfo ipi = new FindIndirectParamsVisitor(templateRegistry).exec(node);

    Set<String> allHeaderVarNames = new HashSet<>();
    List<TemplateHeaderVarDefn> unusedParams = new ArrayList<>();
    // Process @param header variables.
    for (TemplateParam param : node.getAllParams()) {
        allHeaderVarNames.add(param.name());
        if (dataKeys.containsKey(param.name())) {
            // Good: Declared and referenced in template. We remove these from dataKeys so
            // that at the end of the for-loop, dataKeys will only contain the keys that are referenced
            // but not declared in SoyDoc.
            dataKeys.removeAll(param.name());
        } else if (ipi.paramKeyToCalleesMultimap.containsKey(param.name())
                || ipi.mayHaveIndirectParamsInExternalCalls || ipi.mayHaveIndirectParamsInExternalDelCalls) {
            // Good: Declared in SoyDoc and either (a) used in a call that passes all data or (b) used
            // in an external call or delcall that passes all data, which may need the param (we can't
            // verify).
        } else {
            // Bad: Declared in SoyDoc but not referenced in template.
            unusedParams.add(param);
        }
    }

    // Process @state header variables.
    List<TemplateHeaderVarDefn> unusedStateVars = new ArrayList<>();
    for (TemplateStateVar stateVar : node.getStateVars()) {
        allHeaderVarNames.add(stateVar.name());
        if (dataKeys.containsKey(stateVar.name())) {
            // Good: declared and referenced in the template.
            dataKeys.removeAll(stateVar.name());
        } else {
            // Bad: declared in the header, but not used.
            unusedStateVars.add(stateVar);
        }
    }
    // At this point, the only keys left in dataKeys are undeclared.
    for (Entry<String, SourceLocation> undeclared : dataKeys.entries()) {
        String extraErrorMessage = SoyErrors.getDidYouMeanMessage(allHeaderVarNames, undeclared.getKey());
        errorReporter.report(undeclared.getValue(), UNDECLARED_DATA_KEY, undeclared.getKey(),
                extraErrorMessage);
    }

    // Delegate templates can declare unused params because other implementations
    // of the same delegate may need to use those params.
    if (node instanceof TemplateBasicNode) {
        reportUnusedHeaderVars(errorReporter, unusedParams, UNUSED_PARAM);
        reportUnusedHeaderVars(errorReporter, unusedStateVars, UNUSED_STATE);
    }
}

From source file:eu.stratosphere.sopremo.serialization.SopremoRecordPostPass.java

/**
 * @param node/*w  ww .j  av a2s. co  m*/
 * @return
 */
private void checkNode(PlanNode node) {
    if (node instanceof WorksetIterationPlanNode)
        node = addDummyNode(node, node.getOutgoingChannels(), node.getOutgoingChannels(),
                ((SopremoRecordSerializerFactory) ((WorksetIterationPlanNode) node).getSolutionSetSerializer())
                        .getLayout());

    List<Channel> outgoingChannels = node.getOutgoingChannels();
    if (outgoingChannels.size() > 1) {
        ListMultimap<SopremoRecordLayout, Channel> layouts = ArrayListMultimap.create();
        for (Channel channel : outgoingChannels)
            layouts.put(((SopremoRecordSerializerFactory) channel.getSerializer()).getLayout(), channel);

        // we need indeed different layouts; create a dummy map node for each layout
        if (layouts.keySet().size() > 1) {
            // layout to dummy node is empty, so we can ignore all nodes that also require empty layout
            layouts.removeAll(SopremoRecordLayout.EMPTY);
            for (SopremoRecordLayout layout : layouts.keySet()) {
                List<Channel> channelsToBeChanged = layouts.get(layout);
                addDummyNode(node, outgoingChannels, channelsToBeChanged, SopremoRecordLayout.EMPTY);
            }
        }
        fixInputs(node);
    }

}