Example usage for com.google.common.collect ImmutableSet.Builder addAll

List of usage examples for com.google.common.collect ImmutableSet.Builder addAll

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet.Builder addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:com.facebook.buck.jvm.java.DefaultJavaLibrary.java

@Override
public ImmutableSet<Path> getImmediateClasspaths() {
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();

    // Add any exported deps.
    for (BuildRule exported : getExportedDeps()) {
        if (exported instanceof JavaLibrary) {
            builder.addAll(((JavaLibrary) exported).getImmediateClasspaths());
        }/*from   ww  w .j ava 2s.co  m*/
    }

    // Add ourselves to the classpath if there's a jar to be built.
    Optional<SourcePath> sourcePathForOutputJar = sourcePathForOutputJar();
    if (sourcePathForOutputJar.isPresent()) {
        builder.add(getResolver().getAbsolutePath(sourcePathForOutputJar.get()));
    }

    return builder.build();
}

From source file:org.eel.kitchen.jsonschema.keyword.ExtendsKeywordValidator.java

public ExtendsKeywordValidator(final JsonNode schema) {
    super("extends", NodeType.values());
    final JsonNode node = schema.get(keyword);
    final ImmutableSet.Builder<JsonNode> builder = new ImmutableSet.Builder<JsonNode>();

    /*//from  ww w.  j a  v  a  2s . c  om
     * Again, the fact that syntax validation has ensured our schema's
     * correctness helps greatly: the keyword value is either an object
     * or an array of objects.
     *
     * If this is an array, just cycle through its elements and stuff
     * them in our schema set. It should be noted that the draft DOES NOT
     * require that elements in the array must be unique,
     * but we swallow duplicates this way.
     */

    if (node.isObject())
        builder.add(node);
    else
        builder.addAll(node);

    schemas = builder.build();
}

From source file:com.publictransitanalytics.scoregenerator.workflow.ProgressiveRangeExecutor.java

private Map<PointLocation, DynamicProgrammingRecord> createNextMap(
        final Map<PointLocation, DynamicProgrammingRecord> previousMap, final LocalDateTime startTime,
        final LocalDateTime cutoffTime, final Set<? extends PointLocation> startLocations,
        final RiderFactory riderFactory, final ReachabilityClient reachabilityClient,
        final TimeTracker timeTracker, final Map<PointLocation, DynamicProgrammingRecord> initialWalks)
        throws InterruptedException {

    final Map<PointLocation, DynamicProgrammingRecord> stateMap = new HashMap<>(previousMap.size());
    for (final Map.Entry<PointLocation, DynamicProgrammingRecord> entry : previousMap.entrySet()) {

        final DynamicProgrammingRecord record = entry.getValue();

        if (timeTracker.meetsCutoff(record.getReachTime(), cutoffTime)) {
            stateMap.put(entry.getKey(), record);
        }//from   w w  w  .  java2 s . c o  m
    }

    final DynamicProgrammingRecord newStartRecord = new DynamicProgrammingRecord(startTime, ModeInfo.NONE,
            null);
    for (final PointLocation startLocation : startLocations) {
        stateMap.put(startLocation, newStartRecord);
    }

    final ImmutableSet.Builder<PointLocation> initialUpdateSetBuilder = ImmutableSet.builder();
    for (final Map.Entry<PointLocation, DynamicProgrammingRecord> entry : initialWalks.entrySet()) {
        final DynamicProgrammingRecord record = entry.getValue();
        final WalkingCosts walk = record.getMode().getWalkCosts();
        final LocalDateTime newReachTime = timeTracker.adjust(startTime, walk.getDuration());

        final PointLocation location = entry.getKey();
        final ModeInfo newModeInfo = new ModeInfo(ModeType.WALKING, null, walk);
        final DynamicProgrammingRecord newWalkRecord = new DynamicProgrammingRecord(newReachTime, newModeInfo,
                record.getPredecessor());

        if (!stateMap.containsKey(location)) {
            stateMap.put(location, newWalkRecord);
            initialUpdateSetBuilder.add(location);
        } else {
            final LocalDateTime reachTime = stateMap.get(location).getReachTime();

            if (timeTracker.shouldReplace(reachTime, newReachTime)) {
                stateMap.put(location, newWalkRecord);
                initialUpdateSetBuilder.add(location);
            }
        }
    }

    Set<PointLocation> updateSet = initialUpdateSetBuilder.build();

    for (int i = 1;; i++) {

        int roundUpdates = 0;
        final ImmutableSet.Builder<PointLocation> updateSetBuilder = ImmutableSet.builder();
        for (final PointLocation priorLocation : updateSet) {
            final DynamicProgrammingRecord priorRecord = stateMap.get(priorLocation);
            final LocalDateTime newReachTime = priorRecord.getReachTime();

            final DynamicProgrammingRecord previousPriorRecord = previousMap.get(priorLocation);
            final LocalDateTime waitCutoffTime;
            if (previousPriorRecord == null) {
                waitCutoffTime = cutoffTime;
            } else {
                waitCutoffTime = previousPriorRecord.getReachTime();
            }

            final ImmutableSet.Builder<ReachabilityOutput> reachabilitiesBuilder = ImmutableSet.builder();
            final FlatTransitRideVisitor transitRideVisitor = new FlatTransitRideVisitor(cutoffTime,
                    waitCutoffTime, newReachTime, riderFactory);
            priorLocation.accept(transitRideVisitor);
            final Set<ReachabilityOutput> transitRides = transitRideVisitor.getOutput();
            reachabilitiesBuilder.addAll(transitRides);

            if (!priorRecord.getMode().getType().equals(ModeType.WALKING)) {
                final FlatWalkVisitor walkVisitor = new FlatWalkVisitor(cutoffTime, newReachTime,
                        reachabilityClient, timeTracker);
                priorLocation.accept(walkVisitor);
                final Set<ReachabilityOutput> walks = walkVisitor.getOutput();
                reachabilitiesBuilder.addAll(walks);
            }

            updateSetBuilder
                    .addAll(updateRow(reachabilitiesBuilder.build(), stateMap, priorLocation, timeTracker));
            roundUpdates += updateSet.size();
        }

        if (roundUpdates == 0) {
            log.debug("Stopped processing at round {} because no updates.", i);
            break;
        }
        updateSet = updateSetBuilder.build();
    }
    return stateMap;
}

From source file:com.facebook.buck.ocaml.OCamlBuildContext.java

public ImmutableList<String> getIncludeDirectories(boolean isBytecode, boolean excludeDeps) {
    Preconditions.checkNotNull(mlInput);

    ImmutableSet.Builder<String> includeDirs = ImmutableSet.builder();
    for (Path mlFile : mlInput) {
        Path parent = mlFile.getParent();
        if (parent != null) {
            includeDirs.add(parent.toString());
        }/*from   www.ja  v a  2 s .  c om*/
    }

    if (!excludeDeps) {
        includeDirs.addAll(isBytecode ? this.getBytecodeIncludes() : this.getIncludes());
    }

    return ImmutableList.copyOf(includeDirs.build());
}

From source file:org.androidtransfuse.adapter.element.ASTElementFactory.java

private ASTType buildType(TypeElement typeElement) {
    log.debug("ASTElementType building: " + typeElement.getQualifiedName());
    //build placeholder for ASTElementType and contained data structures to allow for children population
    //while avoiding back link loops
    PackageClass packageClass = buildPackageClass(typeElement);

    if (blacklist.containsKey(packageClass)) {
        return blacklist.get(packageClass);
    }//from w  w  w  .  j  av a2s. c om

    ASTTypeVirtualProxy astTypeProxy = new ASTTypeVirtualProxy(packageClass);
    typeCache.put(typeElement, astTypeProxy);

    ASTType superClass = null;
    if (typeElement.getSuperclass() != null) {
        superClass = typeElement.getSuperclass().accept(astTypeBuilderVisitor, null);
    }

    ImmutableSet<ASTType> interfaces = FluentIterable.from(typeElement.getInterfaces())
            .transform(astTypeBuilderVisitor).toSet();

    ImmutableSet.Builder<ASTAnnotation> annotations = ImmutableSet.builder();
    ImmutableSet.Builder<ASTConstructor> constructors = ImmutableSet.builder();
    ImmutableSet.Builder<ASTField> fields = ImmutableSet.builder();
    ImmutableSet.Builder<ASTMethod> methods = ImmutableSet.builder();

    //iterate and build the contained elements within this TypeElement
    annotations.addAll(getAnnotations(typeElement));
    constructors.addAll(transformAST(typeElement.getEnclosedElements(), ASTConstructor.class));
    fields.addAll(transformAST(typeElement.getEnclosedElements(), ASTField.class));
    methods.addAll(transformAST(typeElement.getEnclosedElements(), ASTMethod.class));

    ASTType astType = new ASTElementType(buildAccessModifier(typeElement), packageClass, typeElement,
            constructors.build(), methods.build(), fields.build(), superClass, interfaces, annotations.build());

    astTypeProxy.load(astType);

    return astType;
}

From source file:org.phenotips.vocabulary.internal.solr.OrphanetRareDiseaseOntology.java

@Override
Collection<OntClass> getRootClasses(@Nonnull final OntModel ontModel) {
    this.hierarchyRoots = ImmutableSet.<OntClass>builder().add(ontModel.getOntClass(PHENOME_LABEL))
            .add(ontModel.getOntClass(GENETIC_MATERIAL_LABEL)).build();

    final ImmutableSet.Builder<OntClass> selectedRoots = ImmutableSet.builder();
    for (final OntClass hierarchyRoot : this.hierarchyRoots) {
        selectedRoots.addAll(hierarchyRoot.listSubClasses(DIRECT));
    }//from  w  ww. j a  va  2s  .  c o  m
    return selectedRoots.build();
}

From source file:com.facebook.buck.lua.LuaBinaryDescription.java

@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget,
        CellPathResolver cellRoots, Arg constructorArg) {
    ImmutableSet.Builder<BuildTarget> targets = ImmutableSet.builder();
    if (luaConfig.getPackageStyle() == LuaConfig.PackageStyle.STANDALONE) {
        targets.addAll(luaConfig.getPackager().getParseTimeDeps());
    }/*from w ww . ja  v  a  2  s  .  c o m*/
    targets.addAll(getNativeStarterDepTargets());
    return targets.build();
}

From source file:com.facebook.buck.apple.ApplePackageDescription.java

/**
 * Retrieve deps from macros in externally configured rules.
 *
 * This is used for ImplicitDepsInferringDescription, so it is flavor agnostic.
 *//*from  w ww .  j a v  a  2  s. c  o m*/
private void addDepsFromParam(ImmutableSet.Builder<BuildTarget> builder, BuildTarget target,
        CellPathResolver cellNames) {
    // Add all macro expanded dependencies for these platforms.
    for (Flavor flavor : appleCxxPlatformFlavorDomain.getFlavors()) {
        AppleCxxPlatform platform = appleCxxPlatformFlavorDomain.getValue(flavor);
        Optional<ApplePackageConfig> packageConfig = config
                .getPackageConfigForPlatform(platform.getAppleSdk().getApplePlatform());

        if (packageConfig.isPresent()) {
            try {
                builder.addAll(AbstractGenruleDescription.PARSE_TIME_MACRO_HANDLER.extractParseTimeDeps(target,
                        cellNames, packageConfig.get().getCommand()));
            } catch (MacroException e) {
                throw new HumanReadableException(e, "%s (for platform %s): %s", target,
                        platform.getAppleSdk().getApplePlatform().getName(), e.getMessage());
            }
        }
    }
}

From source file:dagger.internal.codegen.ComponentImplementation.java

/**
 * Returns the names of every modifiable method of this implementation and any superclass
 * implementations./* w ww.j a  va2 s. com*/
 */
ImmutableSet<String> getAllModifiableMethodNames() {
    ImmutableSet.Builder<String> names = ImmutableSet.builder();
    modifiableBindingMethods.allMethods().forEach(method -> names.add(method.methodSpec().name));
    names.addAll(modifiableModuleMethods.values());
    superclassImplementation.ifPresent(superclass -> names.addAll(superclass.getAllModifiableMethodNames()));
    return names.build();
}

From source file:com.facebook.buck.cxx.CxxLibraryDescription.java

@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget,
        CellPathResolver cellRoots, Arg constructorArg) {
    ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();

    // Get any parse time deps from the C/C++ platforms.
    deps.addAll(CxxPlatforms.getParseTimeDeps(cxxPlatforms.getValues()));

    try {//w  w w  .  j av a2s  .c o m
        for (String val : Iterables.concat(constructorArg.linkerFlags, constructorArg.exportedLinkerFlags)) {
            deps.addAll(MACRO_HANDLER.extractParseTimeDeps(buildTarget, cellRoots, val));
        }
        for (PatternMatchedCollection<ImmutableList<String>> values : ImmutableList
                .of(constructorArg.platformLinkerFlags, constructorArg.exportedPlatformLinkerFlags)) {
            for (Pair<Pattern, ImmutableList<String>> pav : values.getPatternsAndValues()) {
                for (String val : pav.getSecond()) {
                    deps.addAll(MACRO_HANDLER.extractParseTimeDeps(buildTarget, cellRoots, val));
                }
            }
        }
    } catch (MacroException e) {
        throw new HumanReadableException(e, "%s: %s", buildTarget, e.getMessage());
    }

    return deps.build();
}