Example usage for com.google.common.collect ImmutableListMultimap get

List of usage examples for com.google.common.collect ImmutableListMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableListMultimap get.

Prototype

@Override
public ImmutableList<V> get(@Nullable K key) 

Source Link

Document

Returns an immutable list of the values for the given key.

Usage

From source file:ru.org.linux.topic.TopicPrepareService.java

/**
 *   , ???  TopicListController /*from   w  ww . jav  a  2s .c om*/
 * ?? ??? ? ? cut
 * @param messages ?? 
 * @param secure ????  ? https
 * @return ??  
 */
public List<PreparedTopic> prepareMessages(List<Topic> messages) {
    List<PreparedTopic> pm = new ArrayList<>(messages.size());

    Map<Integer, MessageText> textMap = loadTexts(messages);
    ImmutableListMultimap<Integer, TagRef> tags = topicTagService.getTagRefs(messages);

    for (Topic message : messages) {
        PreparedTopic preparedMessage = prepareMessage(message, tags.get(message.getId()), true, null, true,
                null, textMap.get(message.getId()), null);

        pm.add(preparedMessage);
    }

    return pm;
}

From source file:net.bunselmeyer.mongo.maven.plugin.MigrateMojo.java

public void execute() throws MojoExecutionException {

    if (StringUtils.isBlank(host)) {
        host = "localhost";
    }// w  w w. j av  a2 s .co  m

    Set<Class<? extends Migration>> allMigrations = scanProjectForMigrations();

    ImmutableListMultimap<MIGRATION_CHECK, MigrationDetails> statusIndex = buildStatusIndex(allMigrations);

    ImmutableList<MigrationDetails> errors = statusIndex.get(MIGRATION_CHECK.ERROR);
    if (!errors.isEmpty()) {
        getLog().error("Fail: Please correct the following issues...");
        for (MigrationDetails error : errors) {
            getLog().error("    " + error.migration.getName() + ": " + error.message);
        }
        return;
    }

    ImmutableList<MigrationDetails> warnings = statusIndex.get(MIGRATION_CHECK.WARNING);
    if (!warnings.isEmpty()) {
        getLog().warn("Warnings...");
        for (MigrationDetails warning : warnings) {
            getLog().warn("    " + warning.migration.getName() + ": " + warning.message);
        }
    }

    ImmutableList<MigrationDetails> goodMigrations = statusIndex.get(MIGRATION_CHECK.GOOD);

    getLog().info("Found " + goodMigrations.size() + " migrations.");

    ImmutableListMultimap<String, MigrationDetails> index = buildIndex(goodMigrations);

    List<String> keys = Lists.newArrayList(index.keySet());
    Collections.sort(keys);

    for (String connectionDef : keys) {
        runMigrations(Lists.newArrayList(index.get(connectionDef)));
    }
}

From source file:ru.org.linux.topic.TopicPrepareService.java

/**
 *    ? ?//  w  ww .  j  a  va 2  s  .co m
 * ?? ??? ? ? cut
 * @param messages ?? 
 * @param secure ????  ? https
 * @param user 
 * @param profile  ?
 * @param loadUserpics   
 * @return ??  
 */
public List<PersonalizedPreparedTopic> prepareMessagesForUser(List<Topic> messages, boolean secure, User user,
        Profile profile, boolean loadUserpics) {
    List<PersonalizedPreparedTopic> pm = new ArrayList<>(messages.size());

    Map<Integer, MessageText> textMap = loadTexts(messages);
    ImmutableListMultimap<Integer, TagRef> tags = topicTagService.getTagRefs(messages);

    for (Topic message : messages) {
        PreparedTopic preparedMessage = prepareMessage(message, tags.get(message.getId()), true, null, secure,
                user, textMap.get(message.getId()), null);

        TopicMenu topicMenu = getTopicMenu(preparedMessage, user, profile, loadUserpics);

        pm.add(new PersonalizedPreparedTopic(preparedMessage, topicMenu));
    }

    return pm;
}

From source file:org.impressivecode.depress.mg.po.PeopleOrganizationMetricProcessor.java

private String getMasterOwnership(final ChangeData change) {
    ImmutableListMultimap<String, String> indexed = groupByOrganization(change);
    String dmo = null;//from w  ww  .  ja va  2 s .c  o  m
    double majorChange = change.getInvolvedEngineers().size() * PERCENTAGE_OF_MAJOR_ORGANISATION_INVOLVED;
    for (String key : indexed.keySet()) {
        int editsCount = indexed.get(key).size();
        if (editsCount >= majorChange) {
            dmo = key;
        }
    }
    return dmo;
}

From source file:org.jboss.metrics.agenda.impl.IntervalGrouping.java

@Override
public Set<TaskGroup> apply(final List<Task> tasks) {
    ImmutableListMultimap<Interval, Task> tasksByInterval = Multimaps.index(tasks,
            new Function<Task, Interval>() {
                @Override/* www .  j  av  a  2s  . co m*/
                public Interval apply(final Task definition) {
                    return definition.getInterval();
                }
            });

    Set<TaskGroup> groups = new HashSet<>();
    for (Interval interval : tasksByInterval.keys()) {
        TaskGroup group = new TaskGroup(interval);
        group.addTasks(tasksByInterval.get(interval));
        groups.add(group);
    }
    return groups;
}

From source file:com.facebook.buck.rules.Manifest.java

/**
 * Adds a new output file to the manifest.
 *///w ww . j a  va  2 s .c  om
public void addEntry(FileHashCache fileHashCache, RuleKey key, SourcePathResolver resolver,
        ImmutableSet<SourcePath> universe, ImmutableSet<SourcePath> inputs) throws IOException {
    int index = 0;
    int[] hashIndices = new int[inputs.size()];
    ImmutableListMultimap<String, SourcePath> sortedUniverse = Multimaps.index(universe,
            sourcePathToManifestHeaderFunction(resolver));
    for (SourcePath input : inputs) {
        String relativePath = sourcePathToManifestHeader(input, resolver);
        ImmutableList<SourcePath> paths = sortedUniverse.get(relativePath);
        Preconditions.checkState(!paths.isEmpty());
        hashIndices[index++] = addHash(relativePath, hashSourcePathGroup(fileHashCache, resolver, paths));
    }
    entries.add(new Pair<>(key, hashIndices));
}

From source file:com.facebook.buck.rules.Manifest.java

private boolean hashesMatch(FileHashCache fileHashCache, SourcePathResolver resolver,
        ImmutableListMultimap<String, SourcePath> universe, int[] hashIndices) throws IOException {
    for (int hashIndex : hashIndices) {
        Pair<Integer, HashCode> hashEntry = hashes.get(hashIndex);
        String header = headers.get(hashEntry.getFirst());
        ImmutableList<SourcePath> candidates = universe.get(header);
        if (candidates.isEmpty()) {
            return false;
        }//from www . java2 s .  com
        HashCode onDiskHeaderHash;
        try {
            onDiskHeaderHash = hashSourcePathGroup(fileHashCache, resolver, candidates);
        } catch (NoSuchFileException e) {
            return false;
        }
        HashCode headerHash = hashEntry.getSecond();
        if (!headerHash.equals(onDiskHeaderHash)) {
            return false;
        }
    }
    return true;
}

From source file:com.facebook.buck.core.build.engine.manifest.Manifest.java

private boolean hashesMatch(FileHashCache fileHashCache, SourcePathResolver resolver,
        ImmutableListMultimap<String, SourcePath> universe, int[] hashIndices) throws IOException {
    for (int hashIndex : hashIndices) {
        Pair<Integer, HashCode> hashEntry = hashes.get(hashIndex);
        String input = inputs.get(hashEntry.getFirst());
        ImmutableList<SourcePath> candidates = universe.get(input);
        if (candidates.isEmpty()) {
            return false;
        }//  w w w .  jav a2  s  .com
        HashCode onDiskHeaderHash;
        try {
            onDiskHeaderHash = hashSourcePathGroup(fileHashCache, resolver, candidates);
        } catch (NoSuchFileException e) {
            return false;
        }
        HashCode inputHash = hashEntry.getSecond();
        if (!inputHash.equals(onDiskHeaderHash)) {
            return false;
        }
    }
    return true;
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java

private <R> void ensureNoOverloadedMethods(ModelSchemaExtractionContext<R> extractionContext,
        final ImmutableListMultimap<String, Method> methodsByName) {
    ImmutableSet<String> methodNames = methodsByName.keySet();
    for (String methodName : methodNames) {
        ImmutableList<Method> methods = methodsByName.get(methodName);
        if (methods.size() > 1) {
            List<Method> deduped = CollectionUtils.dedup(methods, METHOD_EQUIVALENCE);
            if (deduped.size() > 1) {
                throw invalidMethods(extractionContext, "overloaded methods are not supported", deduped);
            }//from  w w  w.  j a  v  a  2 s  .  c  o  m
        }
    }
}

From source file:org.mskcc.shenkers.control.track.gene.GTFGeneModelProvider.java

private void createGtfBgz(File gtf_file, File gtf_bgz_file) throws IOException {
    logger.info("reading {}", gtf_file.getAbsolutePath());
    AbstractFeatureReader<GTFContext, LineIterator> afr = AbstractFeatureReader
            .getFeatureReader(gtf_file.getAbsolutePath(), codec, false);
    CloseableTribbleIterator<GTFContext> iterator = afr.iterator();
    List<GTFContext> gtf = new ArrayList<>();
    while (iterator.hasNext()) {
        GTFContext next = iterator.next();
        gtf.add(next);/* w w  w.  ja va 2  s  .  co  m*/
    }
    ImmutableListMultimap<String, GTFContext> transcript_id_multimap = Multimaps.index(gtf.iterator(),
            GTFContext::getTranscriptId);

    logger.info("adding transcript ranges");
    gtf.addAll(transcript_id_multimap.keySet().stream().map(key -> {
        System.out.println(key);
        ImmutableList<GTFContext> contexts = transcript_id_multimap.get(key);
        Range<Integer> span = contexts.stream().map(c -> Range.closed(c.getStart(), c.getEnd()))
                .collect(new RangeSetCollector()).span();

        GTFContext context = new GTFContext(contexts.get(0).getChr(), span.lowerEndpoint(),
                span.upperEndpoint());
        context.setFeature("transcript");
        context.setFrame(".");
        context.setName(".");
        context.setScore(".");
        context.setSource(".");
        context.setStrand('.');
        context.setAttributes(String.format("transcript_id \"%s\";", key));
        return context;
    }).collect(Collectors.toList()));

    logger.info("sorting");
    Collections.sort(gtf, new CoordinateOrderComparator());
    logger.info("writing to compressed output stream");
    BlockCompressedOutputStream os = new BlockCompressedOutputStream(gtf_bgz_file);
    Writer w = new OutputStreamWriter(os);
    for (GTFContext feature : gtf) {
        w.write(codec.encodeToString(feature));
    }
    w.close();
}