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

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

Introduction

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

Prototype

@Beta
public static <K, V> ImmutableListMultimap<K, V> copyOf(
        Iterable<? extends Entry<? extends K, ? extends V>> entries) 

Source Link

Document

Returns an immutable multimap containing the specified entries.

Usage

From source file:org.nmdp.ngs.variant.vcf.VcfRecord.java

/**
 * Create a new VCF record.//from   w w w  .j a  v  a2s  .  com
 *
 * @param lineNumber line number
 * @param chrom chromosome
 * @param pos position
 * @param id array of ids, must not be null
 * @param ref reference allele
 * @param alt array of alternate alleles, must not be null
 * @param qual QUAL score
 * @param filter filter
 * @param info INFO key-value(s) pairs, must not be null
 * @param format format
 * @param genotypes genotypes keyed by sample id, must not be null
 */
VcfRecord(final long lineNumber, final String chrom, final long pos, final String[] id, final String ref,
        final String[] alt, final double qual, final String[] filter, final ListMultimap<String, String> info,
        final String[] format, final Map<String, VcfGenotype> genotypes) {

    checkNotNull(id);
    checkNotNull(alt);
    checkNotNull(info);
    checkNotNull(genotypes);
    this.lineNumber = lineNumber;
    this.chrom = chrom;
    this.pos = pos;
    this.id = id;
    this.ref = ref;
    this.alt = alt;
    this.qual = qual;
    this.filter = filter;
    this.info = ImmutableListMultimap.copyOf(info);
    this.format = format;
    this.genotypes = ImmutableMap.copyOf(genotypes);
}

From source file:com.google.gerrit.server.notedb.RobotCommentNotes.java

@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
    metaId = handle.id();// w ww. j a v  a 2 s  .c om
    if (metaId == null) {
        loadDefaults();
        return;
    }
    metaId = metaId.copy();

    RevCommit tipCommit = handle.walk().parseCommit(metaId);
    ObjectReader reader = handle.walk().getObjectReader();
    revisionNoteMap = RevisionNoteMap.parseRobotComments(args.noteUtil, reader,
            NoteMap.read(reader, tipCommit));
    ListMultimap<RevId, RobotComment> cs = MultimapBuilder.hashKeys().arrayListValues().build();
    for (RobotCommentsRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
        for (RobotComment c : rn.getComments()) {
            cs.put(new RevId(c.revId), c);
        }
    }
    comments = ImmutableListMultimap.copyOf(cs);
}

From source file:org.dishevelled.bio.variant.vcf.header.VcfInfoHeaderLine.java

/**
 * Create a new VCF INFO header line./*ww w  .j a va  2s . c  o m*/
 *
 * @param id header line ID, must not be null
 * @param number INFO header line number, must not be null
 * @param type INFO header line type, must not be null
 * @param description header line description, must not be null
 * @param source INFO header line source, if any
 * @param version INFO header line version, if any
 * @param attributes header line attributes, must not be null
 */
VcfInfoHeaderLine(final String id, final VcfHeaderLineNumber number, final VcfHeaderLineType type,
        final String description, final String source, final String version,
        final ListMultimap<String, String> attributes) {
    checkNotNull(id);
    checkNotNull(number);
    checkNotNull(type);
    checkNotNull(description);
    checkNotNull(attributes);

    this.id = id;
    this.number = number;
    this.type = type;
    this.description = description;
    this.source = source;
    this.version = version;
    this.attributes = ImmutableListMultimap.copyOf(attributes);
}

From source file:com.google.gerrit.server.notedb.ChangeNotesState.java

static ChangeNotesState create(@Nullable ObjectId metaId, Change.Id changeId, Change.Key changeKey,
        Timestamp createdOn, Timestamp lastUpdatedOn, Account.Id owner, String branch,
        @Nullable PatchSet.Id currentPatchSetId, String subject, @Nullable String topic,
        @Nullable String originalSubject, @Nullable String submissionId, @Nullable Account.Id assignee,
        @Nullable Change.Status status, @Nullable Set<Account.Id> pastAssignees, @Nullable Set<String> hashtags,
        Map<PatchSet.Id, PatchSet> patchSets, ListMultimap<PatchSet.Id, PatchSetApproval> approvals,
        ReviewerSet reviewers, ReviewerByEmailSet reviewersByEmail, List<Account.Id> allPastReviewers,
        List<ReviewerStatusUpdate> reviewerUpdates, List<SubmitRecord> submitRecords,
        List<ChangeMessage> allChangeMessages,
        ListMultimap<PatchSet.Id, ChangeMessage> changeMessagesByPatchSet,
        ListMultimap<RevId, Comment> publishedComments, @Nullable Timestamp readOnlyUntil,
        @Nullable Boolean isPrivate) {
    if (hashtags == null) {
        hashtags = ImmutableSet.of();/* ww  w .j a v a  2 s  .c om*/
    }
    return new AutoValue_ChangeNotesState(metaId, changeId,
            new AutoValue_ChangeNotesState_ChangeColumns(changeKey, createdOn, lastUpdatedOn, owner, branch,
                    currentPatchSetId, subject, topic, originalSubject, submissionId, assignee, status,
                    isPrivate),
            ImmutableSet.copyOf(pastAssignees), ImmutableSet.copyOf(hashtags),
            ImmutableList.copyOf(patchSets.entrySet()), ImmutableList.copyOf(approvals.entries()), reviewers,
            reviewersByEmail, ImmutableList.copyOf(allPastReviewers), ImmutableList.copyOf(reviewerUpdates),
            ImmutableList.copyOf(submitRecords), ImmutableList.copyOf(allChangeMessages),
            ImmutableListMultimap.copyOf(changeMessagesByPatchSet),
            ImmutableListMultimap.copyOf(publishedComments), readOnlyUntil, isPrivate);
}

From source file:org.dishevelled.bio.feature.Gff3Record.java

/**
 * Create a new GFF3 record.//  w w  w .j a  va 2  s .c  o  m
 *
 * @param seqid seqid, must not be null
 * @param source source, must not be null
 * @param featureType feature type, must not be null
 * @param start start, must be at least 0L
 * @param end end, must be at least zero, and greater than or equal to start
 * @param score score
 * @param strand strand, if present must be <code>-</code>, <code>+</code>, or <code>?</code>
 * @param phase phase, if present must be <code>0</code>, <code>1</code>, or <code>2</code>
 * @param attributes attributes, must not be null
 */
public Gff3Record(final String seqid, final String source, final String featureType, final long start,
        final long end, final Double score, final String strand, final Integer phase,
        final ListMultimap<String, String> attributes) {
    checkNotNull(seqid);
    checkNotNull(source);
    checkNotNull(featureType);
    checkNotNull(attributes);
    checkArgument(start >= 0L, "start must be at least zero, was " + start);
    checkArgument(end >= 0L, "end must be at least zero, was " + end);
    checkArgument(end >= start, "end must be greater than or equal to start, was " + end);

    if (strand != null) {
        checkArgument("-".equals(strand) || "+".equals(strand) || "?".equals(strand),
                "if present, strand must be either -, +, or ?, was " + strand);
    }
    if (phase != null) {
        checkArgument(phase >= 0 && phase < 3, "if present, phase must be either 0, 1, or 2, was " + phase);
    }

    this.seqid = seqid;
    this.source = source;
    this.featureType = featureType;
    this.start = start;
    this.end = end;
    this.score = score;
    this.strand = strand;
    this.phase = phase;
    this.attributes = ImmutableListMultimap.copyOf(attributes);
    hashCode = Objects.hash(this.seqid, this.source, this.featureType, this.start, this.end, this.score,
            this.strand, this.phase, this.attributes);
}

From source file:com.b2international.snowowl.core.compare.CompareResultsDsvExporter.java

public File export(IProgressMonitor monitor) throws IOException {

    CsvMapper mapper = new CsvMapper();
    CsvSchema schema = mapper.schemaFor(CompareData.class).withColumnSeparator(delimiter).withHeader().sortedBy(
            "componentType", "componentId", "componentType", "label", "changeKind", "attribute", "from", "to");

    try (SequenceWriter writer = mapper.writer(schema).writeValues(outputPath.toFile())) {
        monitor.beginTask("Exporting compare results to DSV", compareResults.getTotalNew()
                + compareResults.getTotalChanged() + compareResults.getTotalDeleted());

        ListMultimap<Short, ComponentIdentifier> newComponentIdentifiers = Multimaps
                .index(compareResults.getNewComponents(), ComponentIdentifier::getTerminologyComponentId);
        ListMultimap<Short, String> newComponentIds = ImmutableListMultimap.copyOf(
                Multimaps.transformValues(newComponentIdentifiers, ComponentIdentifier::getComponentId));

        for (short terminologyComponentId : newComponentIds.keySet()) {
            for (List<String> componentIds : Lists.partition(newComponentIds.get(terminologyComponentId),
                    PARTITION_SIZE)) {/*from   w w  w  .  jav  a2s .co m*/
                RevisionIndexRequestBuilder<CollectionResource<IComponent>> componentFetchRequest = fetcherFunction
                        .apply(terminologyComponentId, componentIds);

                if (componentFetchRequest == null) {
                    break;
                }

                CollectionResource<IComponent> components = componentFetchRequest
                        .build(repositoryUuid, compareBranch)
                        .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync();

                for (IComponent component : components) {
                    writer.write(new CompareData(component, ChangeKind.ADDED));
                }

                monitor.worked(components.getItems().size());
            }
        }

        ListMultimap<Short, ComponentIdentifier> changedComponentIdentifiers = Multimaps
                .index(compareResults.getChangedComponents(), ComponentIdentifier::getTerminologyComponentId);
        ListMultimap<Short, String> changedComponentIds = ImmutableListMultimap.copyOf(
                Multimaps.transformValues(changedComponentIdentifiers, ComponentIdentifier::getComponentId));
        ListMultimap<String, IComponent> componentPairs = ArrayListMultimap.create(PARTITION_SIZE, 2);

        for (short terminologyComponentId : changedComponentIds.keySet()) {
            for (List<String> componentIds : Lists.partition(changedComponentIds.get(terminologyComponentId),
                    PARTITION_SIZE)) {
                componentPairs.clear();
                RevisionIndexRequestBuilder<CollectionResource<IComponent>> componentFetchRequest = fetcherFunction
                        .apply(terminologyComponentId, componentIds);

                if (componentFetchRequest == null) {
                    break;
                }

                componentFetchRequest.build(repositoryUuid, baseBranch)
                        .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync()
                        .forEach(c -> componentPairs.put(c.getId(), c));

                componentFetchRequest.build(repositoryUuid, compareBranch)
                        .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync()
                        .forEach(c -> componentPairs.put(c.getId(), c));

                for (Entry<String, List<IComponent>> entry : Multimaps.asMap(componentPairs).entrySet()) {
                    IComponent baseComponent = entry.getValue().get(0);
                    IComponent compareComponent = entry.getValue().get(1);
                    Collection<CompareData> compareResults = getCompareResultsOfComponent.apply(baseComponent,
                            compareComponent);

                    for (CompareData d : compareResults) {
                        writer.write(d);
                    }
                }

                monitor.worked(componentPairs.keySet().size());
            }
        }

        ListMultimap<Short, ComponentIdentifier> deletedComponentIdentifiers = Multimaps
                .index(compareResults.getDeletedComponents(), ComponentIdentifier::getTerminologyComponentId);
        ListMultimap<Short, String> deletedComponentIds = ImmutableListMultimap.copyOf(
                Multimaps.transformValues(deletedComponentIdentifiers, ComponentIdentifier::getComponentId));

        for (short terminologyComponentId : deletedComponentIds.keySet()) {
            for (List<String> componentIds : Lists.partition(deletedComponentIds.get(terminologyComponentId),
                    PARTITION_SIZE)) {
                RevisionIndexRequestBuilder<CollectionResource<IComponent>> componentFetchRequest = fetcherFunction
                        .apply(terminologyComponentId, componentIds);

                if (componentFetchRequest == null) {
                    break;
                }

                CollectionResource<IComponent> components = componentFetchRequest
                        .build(repositoryUuid, baseBranch)
                        .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync();

                for (IComponent component : components) {
                    writer.write(new CompareData(component, ChangeKind.DELETED));
                }

                monitor.worked(components.getItems().size());
            }
        }

    } finally {
        monitor.done();
    }

    return outputPath.toFile();
}

From source file:com.bethzur.gcm4j.util.CopyOnWriteArrayListMultimap.java

/**
 * Finishes a write operation by replacing the map with the modified one, if
 * this call corresponds to the outer-most {@link startWrite} call, and
 * unlocking the lock.//from  w  w  w. j  a va2  s.c  om
 * <p>
 * Each call to the reentrant {@code startWrite} method requires a
 * corresponding call to this {code finishWrite}.
 */
private void finishWrite() {
    /*
     * Replace the map with the modified one, if we are releasing the write
     * lock.
     */
    if (lock.getHoldCount() == 1) {
        map = ImmutableListMultimap.copyOf(newMap);
    }
    lock.unlock();
}

From source file:org.lightjason.agentspeak.language.CLiteral.java

/**
 * ctor/* w ww .  j a v  a2 s. com*/
 *
 * @param p_at @ prefix is set
 * @param p_negated negated flag
 * @param p_functor functor of the literal
 * @param p_values initial list of values
 * @param p_annotations initial set of annotations
 */
public CLiteral(final boolean p_at, final boolean p_negated, final IPath p_functor,
        final Collection<ITerm> p_values, final Collection<ILiteral> p_annotations) {
    m_at = p_at;
    m_negated = p_negated;
    // create a full copy of the functor, because concurrency modification
    m_functor = new CPath(p_functor);

    // create immutable structures
    final Multimap<IPath, ILiteral> l_annotations = HashMultimap.create();
    p_annotations.forEach(i -> l_annotations.put(i.fqnfunctor(), i));
    m_annotations = ImmutableSetMultimap.copyOf(l_annotations);

    final Multimap<IPath, ITerm> l_values = LinkedListMultimap.create();
    p_values.forEach(i -> l_values.put(i.fqnfunctor(), i));
    m_values = ImmutableListMultimap.copyOf(l_values);

    m_orderedvalues = Collections.unmodifiableList(new LinkedList<>(p_values));

    // calculates hash value
    m_hash = m_functor.hashCode()
            ^ IntStream.range(0, m_orderedvalues.size()).boxed()
                    .mapToInt(i -> (i + 1) * m_orderedvalues.get(i).hashCode()).sum()
            ^ m_annotations.values().stream().mapToInt(Object::hashCode).sum() ^ (m_negated ? 0 : 55529)
            ^ (m_at ? 0 : 8081);

    // calculates the structure hash value (Murmur3) of the value and annotation definition
    // functor will be added iif no literal data exists ( hasher must be existing twice )
    final String l_functor = p_functor.getPath();

    final Hasher l_valuehasher = CCommon.getTermHashing();
    if (m_orderedvalues.stream().filter(i -> i instanceof ILiteral)
            .map(i -> l_valuehasher.putInt(((ILiteral) i).valuehash())).count() == 0) {
        l_valuehasher.putBoolean(m_negated);
        l_valuehasher.putString(l_functor, Charsets.UTF_8);
    }

    final Hasher l_annotationhasher = CCommon.getTermHashing();
    if (m_annotations.values().stream().map(i -> l_annotationhasher.putInt(i.valuehash())).count() == 0) {
        l_annotationhasher.putBoolean(m_negated);
        l_annotationhasher.putString(l_functor, Charsets.UTF_8);
    }

    m_annotationhash = l_annotationhasher.hash().asInt();
    m_valuehash = l_valuehasher.hash().asInt();
}

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

@VisibleForTesting
public ImmutableListMultimap<RobotToken, RobotToken> getTokensWithSuffix() {
    return ImmutableListMultimap.copyOf(specialTokens);
}

From source file:org.ow2.authzforce.core.pdp.impl.ModularAttributeProvider.java

protected ModularAttributeProvider(
        final ImmutableListMultimap<AttributeFqn, NamedAttributeProvider> attributeProviderModulesByAttributeId,
        final Set<AttributeDesignatorType> selectedAttributeSupport, final boolean strictAttributeIssuerMatch) {
    assert attributeProviderModulesByAttributeId != null;

    if (selectedAttributeSupport == null) {
        designatorModsByAttrId = attributeProviderModulesByAttributeId;
    } else {//from  w w  w  . j  ava  2s  . com
        final ListMultimap<AttributeFqn, NamedAttributeProvider> mutableModsByAttrIdMap = ArrayListMultimap
                .create(selectedAttributeSupport.size(), 1);
        for (final AttributeDesignatorType requiredAttr : selectedAttributeSupport) {
            final AttributeFqn requiredAttrGUID = AttributeFqns.newInstance(requiredAttr);
            final ImmutableList<NamedAttributeProvider> requiredAttrProviderMods = attributeProviderModulesByAttributeId
                    .get(requiredAttrGUID);
            /*
             * According to doc, a non-null empty list is returned if no mappings
             */
            assert requiredAttrProviderMods != null;
            /*
             * Empty requiredAttrProviderMod means it should be provided by the request context (in the initial request from PEP)
             */
            if (!requiredAttrProviderMods.isEmpty()) {

                mutableModsByAttrIdMap.putAll(requiredAttrGUID, requiredAttrProviderMods);
            }
        }

        designatorModsByAttrId = ImmutableListMultimap.copyOf(mutableModsByAttrIdMap);
    }

    this.issuedToNonIssuedAttributeCopyMode = strictAttributeIssuerMatch
            ? ISSUED_TO_NON_ISSUED_ATTRIBUTE_COPY_DISABLED_MODE
            : ISSUED_TO_NON_ISSUED_ATTRIBUTE_COPY_ENABLED_MODE;
}