Search in sources :

Example 1 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project buck by facebook.

the class DefaultClassUsageFileWriter method relativizeMap.

private static ImmutableSetMultimap<Path, Path> relativizeMap(ImmutableSetMultimap<Path, Path> classUsageMap, ProjectFilesystem filesystem) {
    final ImmutableSetMultimap.Builder<Path, Path> builder = ImmutableSetMultimap.builder();
    // Ensure deterministic ordering.
    builder.orderKeysBy(Comparator.naturalOrder());
    builder.orderValuesBy(Comparator.naturalOrder());
    for (Map.Entry<Path, Collection<Path>> jarClassesEntry : classUsageMap.asMap().entrySet()) {
        Path jarAbsolutePath = jarClassesEntry.getKey();
        Optional<Path> jarRelativePath = filesystem.getPathRelativeToProjectRoot(jarAbsolutePath);
        // Don't include jars that are outside of the filesystem
        if (!jarRelativePath.isPresent()) {
            // outside the project are coming from a build tool (e.g. JDK or Android SDK).
            continue;
        }
        builder.putAll(jarRelativePath.get(), jarClassesEntry.getValue());
    }
    return builder.build();
}
Also used : Path(java.nio.file.Path) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Collection(java.util.Collection) Map(java.util.Map)

Example 2 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project bazel by bazelbuild.

the class ProtobufSupport method getInputsToOutputsMap.

private ImmutableSetMultimap<ImmutableSet<Artifact>, Artifact> getInputsToOutputsMap() {
    Iterable<ObjcProtoProvider> objcProtoProviders = getObjcProtoProviders();
    Iterable<ProtoSourcesProvider> protoProviders = getProtoSourcesProviders();
    ImmutableList.Builder<NestedSet<Artifact>> protoSets = new ImmutableList.Builder<NestedSet<Artifact>>();
    // all the transitive groups of proto.
    for (ObjcProtoProvider objcProtoProvider : objcProtoProviders) {
        protoSets.addAll(objcProtoProvider.getProtoGroups());
    }
    for (ProtoSourcesProvider protoProvider : protoProviders) {
        protoSets.add(protoProvider.getTransitiveProtoSources());
    }
    HashMap<Artifact, Set<Artifact>> protoToGroupMap = new HashMap<>();
    // group will be considered the smallest input group with which the proto can be generated.
    for (NestedSet<Artifact> nestedProtoSet : protoSets.build()) {
        ImmutableSet<Artifact> protoSet = ImmutableSet.copyOf(nestedProtoSet.toSet());
        for (Artifact proto : protoSet) {
            // generated with the runtime library.
            if (attributes.isProtoWellKnown(proto)) {
                continue;
            }
            if (!protoToGroupMap.containsKey(proto)) {
                protoToGroupMap.put(proto, protoSet);
            } else {
                protoToGroupMap.put(proto, Sets.intersection(protoSet, protoToGroupMap.get(proto)));
            }
        }
    }
    // Now that we have the smallest proto inputs groups for each proto to be generated, we reverse
    // that map into a multimap to take advantage of the fact that multiple protos can be generated
    // with the same inputs, to avoid having multiple generation actions with the same inputs and
    // different ouputs. This only applies for the generation actions, as the compilation actions
    // compile one generated file at a time.
    // It's OK to use ImmutableSet<Artifact> as the key, since Artifact caches it's hashCode, and
    // ImmutableSet calculates it's hashCode in O(n).
    ImmutableSetMultimap.Builder<ImmutableSet<Artifact>, Artifact> inputsToOutputsMapBuilder = ImmutableSetMultimap.builder();
    for (Artifact proto : protoToGroupMap.keySet()) {
        inputsToOutputsMapBuilder.put(ImmutableSet.copyOf(protoToGroupMap.get(proto)), proto);
    }
    return inputsToOutputsMapBuilder.build();
}
Also used : NestedSet(com.google.devtools.build.lib.collect.nestedset.NestedSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashMap(java.util.HashMap) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableList(com.google.common.collect.ImmutableList) NestedSet(com.google.devtools.build.lib.collect.nestedset.NestedSet) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) ImmutableSet(com.google.common.collect.ImmutableSet) ProtoSourcesProvider(com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider)

Example 3 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project auto by google.

the class BasicAnnotationProcessor method validElements.

/**
   * Returns the valid annotated elements contained in all of the deferred elements. If none are
   * found for a deferred element, defers it again.
   */
private ImmutableSetMultimap<Class<? extends Annotation>, Element> validElements(ImmutableMap<String, Optional<? extends Element>> deferredElements, RoundEnvironment roundEnv) {
    ImmutableSetMultimap.Builder<Class<? extends Annotation>, Element> deferredElementsByAnnotationBuilder = ImmutableSetMultimap.builder();
    for (Entry<String, Optional<? extends Element>> deferredTypeElementEntry : deferredElements.entrySet()) {
        Optional<? extends Element> deferredElement = deferredTypeElementEntry.getValue();
        if (deferredElement.isPresent()) {
            findAnnotatedElements(deferredElement.get(), getSupportedAnnotationClasses(), deferredElementsByAnnotationBuilder);
        } else {
            deferredElementNames.add(ElementName.forTypeName(deferredTypeElementEntry.getKey()));
        }
    }
    ImmutableSetMultimap<Class<? extends Annotation>, Element> deferredElementsByAnnotation = deferredElementsByAnnotationBuilder.build();
    ImmutableSetMultimap.Builder<Class<? extends Annotation>, Element> validElements = ImmutableSetMultimap.builder();
    Set<ElementName> validElementNames = new LinkedHashSet<ElementName>();
    // Look at the elements we've found and the new elements from this round and validate them.
    for (Class<? extends Annotation> annotationClass : getSupportedAnnotationClasses()) {
        // This should just call roundEnv.getElementsAnnotatedWith(Class) directly, but there is a bug
        // in some versions of eclipse that cause that method to crash.
        TypeElement annotationType = elements.getTypeElement(annotationClass.getCanonicalName());
        Set<? extends Element> elementsAnnotatedWith = (annotationType == null) ? ImmutableSet.<Element>of() : roundEnv.getElementsAnnotatedWith(annotationType);
        for (Element annotatedElement : Sets.union(elementsAnnotatedWith, deferredElementsByAnnotation.get(annotationClass))) {
            if (annotatedElement.getKind().equals(PACKAGE)) {
                PackageElement annotatedPackageElement = (PackageElement) annotatedElement;
                ElementName annotatedPackageName = ElementName.forPackageName(annotatedPackageElement.getQualifiedName().toString());
                boolean validPackage = validElementNames.contains(annotatedPackageName) || (!deferredElementNames.contains(annotatedPackageName) && validateElement(annotatedPackageElement));
                if (validPackage) {
                    validElements.put(annotationClass, annotatedPackageElement);
                    validElementNames.add(annotatedPackageName);
                } else {
                    deferredElementNames.add(annotatedPackageName);
                }
            } else {
                TypeElement enclosingType = getEnclosingType(annotatedElement);
                ElementName enclosingTypeName = ElementName.forTypeName(enclosingType.getQualifiedName().toString());
                boolean validEnclosingType = validElementNames.contains(enclosingTypeName) || (!deferredElementNames.contains(enclosingTypeName) && validateElement(enclosingType));
                if (validEnclosingType) {
                    validElements.put(annotationClass, annotatedElement);
                    validElementNames.add(enclosingTypeName);
                } else {
                    deferredElementNames.add(enclosingTypeName);
                }
            }
        }
    }
    return validElements.build();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Optional(com.google.common.base.Optional) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) SuperficialValidation.validateElement(com.google.auto.common.SuperficialValidation.validateElement) Annotation(java.lang.annotation.Annotation) PackageElement(javax.lang.model.element.PackageElement)

Example 4 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project wikidata-query-rdf by wikimedia.

the class RdfRepository method resultToMap.

/**
 * Collect results of the query into a multimap by first parameter.
 *
 * @param result Result object
 * @param keyBinding Binding name to serve as key
 * @param valueBinding Binding name to serve as values
 * @return Collection of strings resulting from the query.
 */
private ImmutableSetMultimap<String, String> resultToMap(TupleQueryResult result, String keyBinding, String valueBinding) {
    ImmutableSetMultimap.Builder<String, String> values = ImmutableSetMultimap.builder();
    try {
        while (result.hasNext()) {
            BindingSet bindings = result.next();
            Binding value = bindings.getBinding(valueBinding);
            Binding key = bindings.getBinding(keyBinding);
            if (value == null || key == null) {
                continue;
            }
            values.put(key.getValue().stringValue(), value.getValue().stringValue());
        }
    } catch (QueryEvaluationException e) {
        throw new FatalException("Can't load results: " + e, e);
    }
    return values.build();
}
Also used : Binding(org.openrdf.query.Binding) BindingSet(org.openrdf.query.BindingSet) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) FatalException(org.wikidata.query.rdf.tool.exception.FatalException)

Example 5 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project LanternServer by LanternPowered.

the class LanternChunkManager method getForced.

/**
 * Gets a map with all the forced chunk and the assigned tickets.
 *
 * @return the tickets
 */
public ImmutableSetMultimap<Vector3i, LoadingTicket> getForced() {
    final ImmutableSetMultimap.Builder<Vector3i, LoadingTicket> builder = ImmutableSetMultimap.builder();
    for (Entry<Vector2i, Set<ChunkLoadingTicket>> en : this.ticketsByPos.entrySet()) {
        final Vector2i pos0 = en.getKey();
        final Vector3i pos = new Vector3i(pos0.getX(), 0, pos0.getY());
        for (ChunkLoadingTicket ticket : en.getValue()) {
            builder.put(pos, ticket);
        }
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Vector3i(com.flowpowered.math.vector.Vector3i) Vector2i(com.flowpowered.math.vector.Vector2i) EntityLoadingTicket(org.spongepowered.api.world.ChunkTicketManager.EntityLoadingTicket) PlayerLoadingTicket(org.spongepowered.api.world.ChunkTicketManager.PlayerLoadingTicket) LoadingTicket(org.spongepowered.api.world.ChunkTicketManager.LoadingTicket) PlayerEntityLoadingTicket(org.spongepowered.api.world.ChunkTicketManager.PlayerEntityLoadingTicket)

Aggregations

ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)14 BuildTarget (com.facebook.buck.model.BuildTarget)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 IOException (java.io.IOException)3 Set (java.util.Set)3 Element (javax.lang.model.element.Element)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 TypeElement (javax.lang.model.element.TypeElement)3 TargetNode (com.facebook.buck.rules.TargetNode)2 Vector3i (com.flowpowered.math.vector.Vector3i)2 SuperficialValidation.validateElement (com.google.auto.common.SuperficialValidation.validateElement)2 Path (java.nio.file.Path)2 HashSet (java.util.HashSet)2 Options (com.b2international.commons.options.Options)1 Expression (com.b2international.index.query.Expression)1 Expressions (com.b2international.index.query.Expressions)1 Query (com.b2international.index.query.Query)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 Ecl (com.b2international.snomed.ecl.Ecl)1 Any (com.b2international.snomed.ecl.ecl.Any)1