Example usage for com.google.common.collect SetMultimap put

List of usage examples for com.google.common.collect SetMultimap put

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:eu.esdihumboldt.hale.ui.style.handler.SpectrumColorSchemeHandler.java

/**
 * @see IHandler#execute(ExecutionEvent)
 *///  www  . jav a  2s  .  c  om
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    // collect all types
    SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
    SchemaService schemas = PlatformUI.getWorkbench().getService(SchemaService.class);
    for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.SOURCE).getMappingRelevantTypes()) {
        types.put(DataSet.SOURCE, type);
    }
    for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.TARGET).getMappingRelevantTypes()) {
        types.put(DataSet.TRANSFORMED, type);
    }

    Style style = StyleHelper.getSpectrumStyles(types);

    StyleService styleService = PlatformUI.getWorkbench().getService(StyleService.class);
    styleService.addStyles(style);

    return null;
}

From source file:ome.services.blitz.repo.path.ClientFilePathTransformer.java

/**
 * Get the files that are too similarly named.
 * @param files a set of files/* w w w.j  ava  2 s .  c o m*/
 * @return the files grouped by those to which they are too similar,
 * or <code>null</code> if all the files are named sufficiently distinctly
 * @throws IOException if the absolute path of any of the {@link File}s could not be found
 */
public Set<Collection<File>> getTooSimilarFiles(Set<File> files) throws IOException {
    final SetMultimap<String, File> filesByFsFile = HashMultimap.create();
    for (final File file : files) {
        final String path = getFsFileFromClientFile(file, Integer.MAX_VALUE).toString().toLowerCase();
        filesByFsFile.put(path, file);
    }
    final Set<Collection<File>> tooSimilarFiles = new HashSet<Collection<File>>();
    for (final Collection<File> similarFiles : filesByFsFile.asMap().values()) {
        if (similarFiles.size() > 1) {
            tooSimilarFiles.add(similarFiles);
        }
    }
    return tooSimilarFiles.isEmpty() ? null : tooSimilarFiles;
}

From source file:org.carrot2.output.metrics.IdealPartitioningBasedMetric.java

/**
 * Returns documents grouped by partitions.
 *///  w ww.ja  v  a  2 s  . c o m
SetMultimap<Object, Document> getDocumentsByPartition(List<Document> documents) {
    final SetMultimap<Object, Document> index = HashMultimap.create();
    for (Document document : documents) {
        final Collection<Object> partitions = document.getField(partitionIdFieldName);
        for (Object partition : partitions) {
            index.put(partition, document);
        }
    }

    return ImmutableSetMultimap.copyOf(index);
}

From source file:org.eclipse.gef4.mvc.examples.logo.rcp.parts.FXGeometricShapePart.java

@Override
protected SetMultimap<? extends Object, String> doGetContentAnchorages() {
    SetMultimap<Object, String> anchorages = HashMultimap.create();
    for (AbstractFXGeometricElement<? extends IGeometry> anchorage : getContent().getAnchorages()) {
        anchorages.put(anchorage, "link");
    }//from   w w  w.ja va 2  s .co  m
    return anchorages;
}

From source file:org.onosproject.net.intent.impl.compiler.LinkCollectionIntentFlowObjectivesCompiler.java

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();

    for (Link link : intent.links()) {
        inputPorts.put(link.dst().deviceId(), link.dst().port());
        outputPorts.put(link.src().deviceId(), link.src().port());
    }//from   w ww.  j  a  v a 2  s .co  m

    for (ConnectPoint ingressPoint : intent.ingressPoints()) {
        inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
    }

    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }

    List<Objective> objectives = new ArrayList<>();
    List<DeviceId> devices = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keys()) {
        List<Objective> deviceObjectives = createRules(intent, deviceId, inputPorts.get(deviceId),
                outputPorts.get(deviceId));
        deviceObjectives.forEach(objective -> {
            objectives.add(objective);
            devices.add(deviceId);
        });
    }
    return Collections.singletonList(new FlowObjectiveIntent(appId, devices, objectives, intent.resources()));
}

From source file:org.onos.vpls.Vpls.java

/**
 * Computes the list of configured interfaces with a VLAN Id.
 *
 * @return the interfaces grouped by vlan id
 *//*  w ww.  j  a  va2s  . c  om*/
private SetMultimap<VlanId, ConnectPoint> getConfigCPoints() {
    log.debug("Checking interface configuration");

    SetMultimap<VlanId, ConnectPoint> confCPointsByVlan = HashMultimap.create();

    interfaceService.getInterfaces().forEach(intf -> confCPointsByVlan.put(intf.vlan(), intf.connectPoint()));
    return confCPointsByVlan;
}

From source file:exm.stc.ic.opt.WaitCoalescer.java

private static void findBlockingContinuations(Block block, SetMultimap<Var, InstOrCont> waitMap) {
    for (Continuation c : block.getContinuations()) {
        List<BlockingVar> blockingVars = c.blockingVars(false);
        if (blockingVars != null) {
            for (BlockingVar v : blockingVars) {
                waitMap.put(v.var, new InstOrCont(c));
            }/*  w ww  .j a  v  a2 s  . c om*/
        }
    }
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.ShapeDistanceCollectiveAnswerScorer.java

@SuppressWarnings("unchecked")
@Override//from  ww w.  j  a va  2 s. c  o  m
public void prepare(JCas jcas) {
    answers = TypeUtil.getRankedAnswers(jcas);
    distances = HashBasedTable.create();
    bdistances = HashBasedTable.create();
    ImmutableSet<Answer> answerSet = ImmutableSet.copyOf(answers);
    SetMultimap<Answer, String> answer2shapes = HashMultimap.create();
    answers.forEach(answer -> TypeUtil.getCandidateAnswerVariantNames(answer).stream()
            .map(ShapeDistanceCollectiveAnswerScorer::shape)
            .forEach(shape -> answer2shapes.put(answer, shape)));
    for (List<Answer> pair : Sets.cartesianProduct(answerSet, answerSet)) {
        Answer answer1 = pair.get(0);
        Answer answer2 = pair.get(1);
        if (answer1.equals(answer2)) {
            distances.put(answer1, answer2, 1.0);
            bdistances.put(answer1, answer2, 1.0);
        } else {
            OptionalDouble distance = Sets
                    .cartesianProduct(answer2shapes.get(answer1), answer2shapes.get(answer2)).stream()
                    .mapToDouble(shapepair -> getDistance(shapepair.get(0), shapepair.get(1))).min();
            if (distance.isPresent()) {
                distances.put(answer1, answer2, 1.0 - distance.getAsDouble());
                bdistances.put(answer1, answer2, distance.getAsDouble() == 0.0 ? 1.0 : 0.0);
            }
        }
    }
}

From source file:com.google.errorprone.bugpatterns.RedundantThrows.java

@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
    List<? extends ExpressionTree> thrown = tree.getThrows();
    if (thrown.isEmpty()) {
        return NO_MATCH;
    }/*from  w w w .  j  a va2  s. co  m*/
    SetMultimap<Symbol, ExpressionTree> exceptionsBySuper = LinkedHashMultimap.create();
    for (ExpressionTree exception : thrown) {
        Type type = getType(exception);
        do {
            type = state.getTypes().supertype(type);
            exceptionsBySuper.put(type.tsym, exception);
        } while (!state.getTypes().isSameType(type, state.getSymtab().objectType));
    }
    Set<ExpressionTree> toRemove = new HashSet<>();
    List<String> messages = new ArrayList<>();
    for (ExpressionTree exception : thrown) {
        Symbol sym = getSymbol(exception);
        if (exceptionsBySuper.containsKey(sym)) {
            Set<ExpressionTree> sub = exceptionsBySuper.get(sym);
            messages.add(String.format("%s %s of %s", oxfordJoin(", ", sub),
                    sub.size() == 1 ? "is a subtype" : "are subtypes", sym.getSimpleName()));
            toRemove.addAll(sub);
        }
    }
    if (toRemove.isEmpty()) {
        return NO_MATCH;
    }
    // sort by order in input
    List<ExpressionTree> delete = ImmutableList
            .<ExpressionTree>copyOf(Iterables.filter(tree.getThrows(), Predicates.in(toRemove)));
    return buildDescription(delete.get(0)).setMessage("Redundant throws clause: " + oxfordJoin("; ", messages))
            .addFix(SuggestedFixes.deleteExceptions(tree, state, delete)).build();
}

From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext.java

public EffectiveSchemaContext(final List<DeclaredStatement<?>> rootDeclaredStatements,
        final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
    this.rootDeclaredStatements = ImmutableList.copyOf(rootDeclaredStatements);
    this.rootEffectiveStatements = ImmutableList.copyOf(rootEffectiveStatements);

    Set<Module> modulesInit = new HashSet<>();
    for (EffectiveStatement<?, ?> rootEffectiveStatement : rootEffectiveStatements) {
        if (rootEffectiveStatement instanceof ModuleEffectiveStatementImpl) {
            Module module = (Module) rootEffectiveStatement;
            modulesInit.add(module);//www.  j  ava 2  s .c  o m
        }
    }

    Module[] moduleArray = new Module[modulesInit.size()];
    List<Module> sortedModuleList = ModuleDependencySort.sort(modulesInit.toArray(moduleArray));
    this.modules = ImmutableSet.copyOf(sortedModuleList);

    final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER);
    final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER);
    Set<ModuleIdentifier> modIdBuilder = new HashSet<>();
    for (Module m : modulesInit) {
        nameMap.put(m.getName(), m);
        nsMap.put(m.getNamespace(), m);
        modIdBuilder.add(ModuleIdentifierImpl.create(m.getName(), Optional.of(m.getNamespace()),
                Optional.of(m.getRevision())));
        resolveSubmoduleIdentifiers(m.getSubmodules(), modIdBuilder);
    }

    namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
    nameToModules = ImmutableSetMultimap.copyOf(nameMap);
    moduleIdentifiers = ImmutableSet.copyOf(modIdBuilder);
}