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:com.google.template.soy.passes.CheckDelegatesVisitor.java

/**
 * Performs checks that only involve templates (uses templateRegistry only).
 *///w  ww . j  ava2 s  .c o  m
private void checkTemplates() {

    Map<String, TemplateBasicNode> basicTemplatesMap = templateRegistry.getBasicTemplatesMap();
    ImmutableListMultimap<DelTemplateKey, DelegateTemplateDivision> delTemplatesMap = templateRegistry
            .getDelTemplatesMap();
    ImmutableSetMultimap<String, DelTemplateKey> delTemplateNameToKeysMap = templateRegistry
            .getDelTemplateNameToKeysMap();

    // Check that no name is reused for both basic and delegate templates.
    for (DelTemplateKey delTemplateKey : delTemplatesMap.keySet()) {
        String name = delTemplateKey.name();
        if (basicTemplatesMap.containsKey(name)) {
            SourceLocation sourceLocation = basicTemplatesMap.get(name).getSourceLocation();
            errorReporter.report(sourceLocation, BASIC_AND_DELTEMPLATE_WITH_SAME_NAME, name);
        }
    }

    // Check that all delegate templates with the same name have the same declared params and
    // content kind.
    for (Iterable<DelTemplateKey> delTemplateKeys : delTemplateNameToKeysMap.asMap().values()) {

        TemplateDelegateNode firstDelTemplate = null;
        Set<TemplateParam> firstRequiredParamSet = null;
        ContentKind firstContentKind = null;

        // Then, loop over keys that share the same name (effectively, over variants):
        for (DelTemplateKey delTemplateKey : delTemplateKeys) {
            // Then, loop over divisions with the same key (effectively, over priorities):
            for (DelegateTemplateDivision division : delTemplatesMap.get(delTemplateKey)) {
                // Now, over templates in the division (effectively, delpackages):
                for (TemplateDelegateNode delTemplate : division.delPackageNameToDelTemplateMap.values()) {
                    if (firstDelTemplate == null) {
                        // First template encountered.
                        firstDelTemplate = delTemplate;
                        firstRequiredParamSet = getRequiredParamSet(delTemplate);
                        firstContentKind = delTemplate.getContentKind();
                    } else {
                        // Not first template encountered.
                        Set<TemplateParam> currRequiredParamSet = getRequiredParamSet(delTemplate);
                        if (!currRequiredParamSet.equals(firstRequiredParamSet)) {
                            errorReporter.report(delTemplate.getSourceLocation(),
                                    DELTEMPLATES_WITH_DIFFERENT_PARAM_DECLARATIONS,
                                    firstDelTemplate.getDelTemplateName(),
                                    firstDelTemplate.getSourceLocation().toString());
                        }
                        if (delTemplate.getContentKind() != firstContentKind) {
                            // TODO: This is only *truly* a requirement if the strict mode deltemplates are
                            // being called by contextual templates. For a strict-to-strict call, everything
                            // is escaped at runtime at the call sites. You could imagine delegating between
                            // either a plain-text or rich-html template. However, most developers will write
                            // their deltemplates in a parallel manner, and will want to know when the
                            // templates differ. Plus, requiring them all to be the same early-on will allow
                            // future optimizations to avoid the run-time checks, so it's better to start out
                            // as strict as possible and only open up if needed.
                            errorReporter.report(delTemplate.getSourceLocation(),
                                    STRICT_DELTEMPLATES_WITH_DIFFERENT_CONTENT_KIND,
                                    String.valueOf(firstContentKind),
                                    String.valueOf(delTemplate.getContentKind()),
                                    firstDelTemplate.getSourceLocation().toString());
                        }
                    }
                }
            }
        }
    }
}

From source file:com.google.devtools.build.lib.rules.objc.AppleStaticLibrary.java

@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    PlatformType platformType = MultiArchSplitTransitionProvider.getPlatformType(ruleContext);
    ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap = ruleContext
            .getPrerequisitesByConfiguration("deps", Mode.SPLIT);
    ImmutableListMultimap<BuildConfiguration, ObjcProvider> configToAvoidDepsMap = ruleContext
            .getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.SPLIT,
                    ObjcProvider.class);

    Set<BuildConfiguration> childConfigurations = getChildConfigurations(ruleContext);

    IntermediateArtifacts ruleIntermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);

    NestedSetBuilder<Artifact> librariesToLipo = NestedSetBuilder.<Artifact>stableOrder();
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder()
            .add(ruleIntermediateArtifacts.combinedArchitectureArchive());

    ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder();

    for (BuildConfiguration childConfig : childConfigurations) {
        ProtobufSupport protoSupport = new ProtobufSupport(ruleContext, childConfig).registerGenerationActions()
                .registerCompilationActions();

        Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();

        IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext,
                childConfig);//from w  w  w .java 2s. c  o m

        ObjcCommon common = common(ruleContext, childConfig, intermediateArtifacts,
                nullToEmptyList(configToDepsCollectionMap.get(childConfig)), protosObjcProvider);
        ObjcProvider objcProvider = common.getObjcProvider()
                .subtractSubtrees(configToAvoidDepsMap.get(childConfig));

        librariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureLibrary());

        CompilationSupport.createForConfig(ruleContext, childConfig).registerCompileAndArchiveActions(common)
                .registerFullyLinkAction(objcProvider,
                        intermediateArtifacts.strippedSingleArchitectureLibrary())
                .validateAttributes();
        ruleContext.assertNoErrors();

        addTransitivePropagatedKeys(objcProviderBuilder, objcProvider);
    }

    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);

    new LipoSupport(ruleContext).registerCombineArchitecturesAction(librariesToLipo.build(),
            ruleIntermediateArtifacts.combinedArchitectureArchive(),
            appleConfiguration.getMultiArchPlatform(platformType));

    RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext,
            filesToBuild.build());

    objcProviderBuilder.add(MULTI_ARCH_LINKED_ARCHIVES,
            ruleIntermediateArtifacts.combinedArchitectureArchive());

    targetBuilder.addProvider(ObjcProvider.class, objcProviderBuilder.build());
    return targetBuilder.build();
}

From source file:com.google.devtools.build.lib.rules.objc.MultiArchBinarySupport.java

/**
 * Returns a map from from dependency configuration to the {@link ObjcCommon} which comprises all
 * information about the dependencies in that configuration. This can be used both to register
 * actions in {@link #registerActions} and collect provider information to be propagated upstream.
 *
 * @param childConfigurations the set of configurations in which dependencies of the current rule
 *     are built/*from   ww  w .j a v  a  2  s  . c om*/
 * @param configToDepsCollectionMap a map from child configuration to providers that "deps" of the
 *     current rule have propagated in that configuration
 * @param configurationToNonPropagatedObjcMap a map from child configuration to providers that
 *     "non_propagated_deps" of the current rule have propagated in that configuration
 * @param dylibObjcProviders {@link ObjcProvider}s that dynamic library dependencies of the
 *     current rule have propagated
 * @param dylibProtoProviders {@link ObjcProtoProvider} providers that dynamic library
 *     dependencies of the current rule have propagated
 * @param bundleLoaderObjcProvider Optional ObjcProvider containing artifacts and paths to be
 *     included in this binary's compilation actions
 * @throws RuleErrorException if there are attribute errors in the current rule context
 */
public Map<BuildConfiguration, ObjcProvider> objcProviderByDepConfiguration(
        Set<BuildConfiguration> childConfigurations,
        ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap,
        ImmutableListMultimap<BuildConfiguration, ObjcProvider> configurationToNonPropagatedObjcMap,
        Iterable<ObjcProvider> dylibObjcProviders, Iterable<ObjcProtoProvider> dylibProtoProviders)
        throws RuleErrorException, InterruptedException {
    ImmutableMap.Builder<BuildConfiguration, ObjcProvider> configurationToObjcProviderBuilder = ImmutableMap
            .builder();

    for (BuildConfiguration childConfig : childConfigurations) {
        Optional<ObjcProvider> protosObjcProvider;
        if (ObjcRuleClasses.objcConfiguration(ruleContext).enableAppleBinaryNativeProtos()) {
            ProtobufSupport protoSupport = new ProtobufSupport(ruleContext, childConfig,
                    protoArtifactsToAvoid(dylibProtoProviders)).registerGenerationActions()
                            .registerCompilationActions();
            protosObjcProvider = protoSupport.getObjcProvider();
        } else {
            protosObjcProvider = Optional.absent();
        }

        IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext,
                childConfig);

        Iterable<ObjcProvider> additionalDepProviders = Iterables.concat(dylibObjcProviders,
                ruleContext.getPrerequisites("bundles", Mode.TARGET, ObjcProvider.class),
                protosObjcProvider.asSet());

        ObjcCommon common = common(ruleContext, childConfig, intermediateArtifacts,
                nullToEmptyList(configToDepsCollectionMap.get(childConfig)),
                nullToEmptyList(configurationToNonPropagatedObjcMap.get(childConfig)), additionalDepProviders);
        ObjcProvider objcProvider = common.getObjcProvider().subtractSubtrees(dylibObjcProviders);

        configurationToObjcProviderBuilder.put(childConfig, objcProvider);
    }

    return configurationToObjcProviderBuilder.build();
}

From source file:org.eclipse.xtend.core.validation.XtendJavaValidator.java

@Check
public void checkMultipleAnnotations(final XtendAnnotationTarget annotationTarget) {
    if (annotationTarget.getAnnotations().size() <= 1 || !isRelevantAnnotationTarget(annotationTarget)) {
        return;//from   w  w w  .ja va 2  s.  co m
    }

    ImmutableListMultimap<String, XAnnotation> groupByIdentifier = Multimaps
            .index(annotationTarget.getAnnotations(), new Function<XAnnotation, String>() {
                public String apply(XAnnotation input) {
                    return input.getAnnotationType().getIdentifier();
                }
            });

    for (String qName : groupByIdentifier.keySet()) {
        ImmutableList<XAnnotation> sameType = groupByIdentifier.get(qName);
        if (sameType.size() > 1) {
            JvmType type = sameType.get(0).getAnnotationType();
            if (type instanceof JvmAnnotationType && !type.eIsProxy()
                    && !annotationLookup.isRepeatable((JvmAnnotationType) type)) {
                for (XAnnotation xAnnotation : sameType) {
                    error("Multiple annotations of non-repeatable type @"
                            + xAnnotation.getAnnotationType().getSimpleName()
                            + ". Only annotation types marked @Repeatable can be used multiple times at one target.",
                            xAnnotation, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE,
                            INSIGNIFICANT_INDEX, ANNOTATION_MULTIPLE);
                }
            }
        }
    }
}

From source file:org.apache.hadoop.hive.metastore.utils.MetaStoreServerUtils.java

/**
 * Coalesce list of partitions belonging to a table into a more compact PartitionSpec
 * representation./*ww  w  . j  ava 2 s  .  com*/
 *
 * @param table Table thrift object
 * @param partitions List of partition objects
 * @return collection PartitionSpec objects which is a compressed representation of original
 * partition list.
 */
public static List<PartitionSpec> getPartitionspecsGroupedByStorageDescriptor(Table table,
        Collection<Partition> partitions) {
    final String tablePath = table.getSd().getLocation();

    ImmutableListMultimap<StorageDescriptorKey, Partition> partitionsWithinTableDirectory = Multimaps
            .index(partitions, input -> {
                // if sd is not in the list of projected fields, all the partitions
                // can be just grouped in PartitionSpec object
                if (input.getSd() == null) {
                    return StorageDescriptorKey.UNSET_KEY;
                }
                // if the partition is within table, use the tableSDKey to group it with other partitions
                // within the table directory
                if (input.getSd().getLocation() != null && input.getSd().getLocation().startsWith(tablePath)) {
                    return new StorageDescriptorKey(tablePath, input.getSd());
                }
                // if partitions are located outside table location we treat them as non-standard
                // and do not perform any grouping
                // if the location is not set partitions are grouped according to the rest of the SD fields
                return new StorageDescriptorKey(input.getSd());
            });

    List<PartitionSpec> partSpecs = new ArrayList<>();

    // Classify partitions based on shared SD properties.
    Map<StorageDescriptorKey, List<PartitionWithoutSD>> sdToPartList = new HashMap<>();
    // we don't expect partitions to exist outside directory in most cases
    List<Partition> partitionsOutsideTableDir = new ArrayList<>(0);
    for (StorageDescriptorKey key : partitionsWithinTableDirectory.keySet()) {
        boolean isUnsetKey = key.equals(StorageDescriptorKey.UNSET_KEY);
        // group the partitions together when
        // case I : sd is not set because it was not in the requested fields
        // case II : when sd.location is not set because it was not in the requested fields
        // case III : when sd.location is set and it is located within table directory
        if (isUnsetKey || key.baseLocation == null || key.baseLocation.equals(tablePath)) {
            for (Partition partition : partitionsWithinTableDirectory.get(key)) {

                PartitionWithoutSD partitionWithoutSD = new PartitionWithoutSD();
                partitionWithoutSD.setValues(partition.getValues());
                partitionWithoutSD.setCreateTime(partition.getCreateTime());
                partitionWithoutSD.setLastAccessTime(partition.getLastAccessTime());
                partitionWithoutSD.setRelativePath((isUnsetKey || !partition.getSd().isSetLocation()) ? null
                        : partition.getSd().getLocation().substring(tablePath.length()));
                partitionWithoutSD.setParameters(partition.getParameters());

                if (!sdToPartList.containsKey(key)) {
                    sdToPartList.put(key, new ArrayList<>());
                }
                sdToPartList.get(key).add(partitionWithoutSD);
            }
        } else {
            // Lump all partitions outside the tablePath into one PartSpec.
            // if non-standard partitions need not be deDuped create PartitionListComposingSpec
            // this will be used mostly for keeping backwards compatibility with  some HMS APIs which use
            // PartitionListComposingSpec for non-standard partitions located outside table
            partitionsOutsideTableDir.addAll(partitionsWithinTableDirectory.get(key));
        }
    }
    // create sharedSDPartSpec for all the groupings
    for (Map.Entry<StorageDescriptorKey, List<PartitionWithoutSD>> entry : sdToPartList.entrySet()) {
        partSpecs.add(getSharedSDPartSpec(table, entry.getKey(), entry.getValue()));
    }
    if (!partitionsOutsideTableDir.isEmpty()) {
        PartitionSpec partListSpec = new PartitionSpec();
        partListSpec.setDbName(table.getDbName());
        partListSpec.setTableName(table.getTableName());
        partListSpec.setPartitionList(new PartitionListComposingSpec(partitionsOutsideTableDir));
        partSpecs.add(partListSpec);
    }
    return partSpecs;
}

From source file:org.eclipse.xtend.core.validation.XtendValidator.java

@Check
public void checkMultipleAnnotations(final XtendAnnotationTarget annotationTarget) {
    if (annotationTarget.getAnnotations().size() <= 1 || !isRelevantAnnotationTarget(annotationTarget)) {
        return;/*from  ww w.  java2s  .  c  o  m*/
    }

    ImmutableListMultimap<String, XAnnotation> groupByIdentifier = Multimaps
            .index(annotationTarget.getAnnotations(), new Function<XAnnotation, String>() {
                @Override
                public String apply(XAnnotation input) {
                    return input.getAnnotationType().getIdentifier();
                }
            });

    for (String qName : groupByIdentifier.keySet()) {
        ImmutableList<XAnnotation> sameType = groupByIdentifier.get(qName);
        if (sameType.size() > 1) {
            JvmType type = sameType.get(0).getAnnotationType();
            if (type instanceof JvmAnnotationType && !type.eIsProxy()
                    && !annotationLookup.isRepeatable((JvmAnnotationType) type)) {
                for (XAnnotation xAnnotation : sameType) {
                    error("Multiple annotations of non-repeatable type @"
                            + xAnnotation.getAnnotationType().getSimpleName()
                            + ". Only annotation types marked @Repeatable can be used multiple times at one target.",
                            xAnnotation, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE,
                            INSIGNIFICANT_INDEX, ANNOTATION_MULTIPLE);
                }
            }
        }
    }
}