Example usage for com.google.common.collect ImmutableSet builder

List of usage examples for com.google.common.collect ImmutableSet builder

Introduction

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

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.publictransitanalytics.scoregenerator.schedule.TripCreatingTransitNetwork.java

@Override
public Set<EntryPoint> getEntryPoints(final TransitStop stop, final LocalDateTime startTime,
        final LocalDateTime endTime) {
    final ImmutableSet.Builder<EntryPoint> builder = ImmutableSet.builder();

    final EntryPointTimeKey startKey = EntryPointTimeKey.getMinimalKey(startTime);
    final EntryPointTimeKey endKey = EntryPointTimeKey.getMaximalKey(endTime);
    builder.addAll(entryPoints.row(stop).subMap(startKey, endKey).values());
    if (entryPoints.contains(stop, endKey)) {
        builder.add(entryPoints.get(stop, endKey));
    }/*from   w  w  w  .j ava  2s.c om*/
    return builder.build();
}

From source file:com.google.devtools.build.lib.skyframe.serialization.ImmutableSetRuntimeCodec.java

@SuppressWarnings("unchecked") // Adding object to untyped builder.
@Override/*from w  w  w  .jav  a  2  s. c  o m*/
public ImmutableSet deserialize(DeserializationContext context, CodedInputStream codedIn)
        throws SerializationException, IOException {
    int size = codedIn.readInt32();
    ImmutableSet.Builder builder = ImmutableSet.builderWithExpectedSize(size);
    for (int i = 0; i < size; i++) {
        // Don't inline so builder knows this is an object, not an array.
        Object item = context.deserialize(codedIn);
        builder.add(item);
    }
    return builder.build();
}

From source file:org.sonar.plugins.protobuf.api.visitors.SyntaxHighlighterVisitor.java

public SyntaxHighlighterVisitor(ResourcePerspectives resourcePerspectives, FileSystem fs) {
    super(resourcePerspectives, fs);

    ImmutableSet.Builder<String> keywordsBuilder = ImmutableSet.builder();
    keywordsBuilder.add(ProtoBufKeyword.getKeywordValues());
    keywords = keywordsBuilder.build();//from  ww  w .j ava2s .  c  o m
}

From source file:com.google.devtools.build.lib.skyframe.CoverageReportFunction.java

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    Preconditions.checkState(CoverageReportValue.SKY_KEY.equals(skyKey),
            String.format("Expected %s for SkyKey but got %s instead", CoverageReportValue.SKY_KEY, skyKey));

    ImmutableList<ActionAnalysisMetadata> actions = PrecomputedValue.COVERAGE_REPORT_KEY.get(env);
    if (actions == null) {
        return null;
    }/*w  w  w .  j  a  v a2s  .com*/

    ImmutableSet.Builder<Artifact> outputs = new ImmutableSet.Builder<>();

    for (ActionAnalysisMetadata action : actions) {
        outputs.addAll(action.getOutputs());
    }

    return new CoverageReportValue(outputs.build(), actions);
}

From source file:com.stackframe.sarariman.tasks.TasksImpl.java

public Set<Task> getAll() {
    try {//www.j  a  va 2  s  .  co  m
        Connection connection = dataSource.getConnection();
        try {
            Statement s = connection.createStatement();
            try {
                ResultSet r = s.executeQuery("SELECT id FROM tasks");
                try {
                    ImmutableSet.Builder<Task> builder = ImmutableSet.<Task>builder();
                    while (r.next()) {
                        builder.add(get(r.getInt("id")));
                    }

                    return builder.build();
                } finally {
                    r.close();
                }
            } finally {
                s.close();
            }
        } finally {
            connection.close();
        }
    } catch (SQLException se) {
        throw new RuntimeException(se);
    }
}

From source file:com.google.devtools.build.lib.buildeventstream.transports.BuildEventTransportFactory.java

/**
 * Creates a {@link ImmutableSet} of {@link BuildEventTransport} based on the specified {@link
 * BuildEventStreamOptions}./* w  w w.j  a  v  a 2s  . c  o m*/
 *
 * @param options Options used configure and create the returned BuildEventTransports.
 * @return A {@link ImmutableSet} of BuildEventTransports. This set may be empty.
 * @throws IOException Exception propagated from a {@link BuildEventTransport} creation failure.
 */
public static ImmutableSet<BuildEventTransport> createFromOptions(BuildEventStreamOptions options,
        PathConverter pathConverter) throws IOException {
    Builder<BuildEventTransport> buildEventTransportsBuilder = ImmutableSet.builder();
    for (BuildEventTransportFactory transportFactory : BuildEventTransportFactory.values()) {
        if (transportFactory.enabled(options)) {
            buildEventTransportsBuilder.add(transportFactory.create(options, pathConverter));
        }
    }
    return buildEventTransportsBuilder.build();
}

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

@Override
protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
    ObjcProvider objcProvider = common.getObjcProvider();

    ImmutableSet.Builder<LibraryToLink> libraries = new ImmutableSet.Builder<>();
    for (Artifact library : objcProvider.get(ObjcProvider.LIBRARY)) {
        libraries.add(LinkerInputs.opaqueLibraryToLink(library, ArtifactCategory.STATIC_LIBRARY,
                FileSystemUtils.removeExtension(library.getRootRelativePathString())));
    }// w  w  w  . ja v a  2  s. c  om

    libraries.addAll(objcProvider.get(ObjcProvider.CC_LIBRARY));

    builder.addLibraries(libraries.build());
}

From source file:org.apache.sentry.provider.common.CacheProvider.java

public ImmutableSet<String> getPrivileges(Set<String> groups, ActiveRoleSet roleSet,
        Authorizable... authorizableHierarchy) {
    if (!initialized) {
        throw new IllegalStateException("CacheProvider has not been properly initialized");
    }//from  w w  w.j a v a 2s.  c  o m
    ImmutableSet.Builder<String> resultBuilder = ImmutableSet.builder();
    for (String groupName : groups) {
        for (Map.Entry<String, Set<String>> row : cache.getCache().row(groupName).entrySet()) {
            if (roleSet.containsRole(row.getKey())) {
                // TODO: SENTRY-1245: Filter by Authorizables, if provided
                resultBuilder.addAll(row.getValue());
            }
        }
    }
    return resultBuilder.build();
}

From source file:io.prestosql.sql.planner.iterative.rule.PruneWindowColumns.java

@Override
protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, WindowNode windowNode,
        Set<Symbol> referencedOutputs) {
    Map<Symbol, WindowNode.Function> referencedFunctions = Maps.filterKeys(windowNode.getWindowFunctions(),
            referencedOutputs::contains);

    if (referencedFunctions.isEmpty()) {
        return Optional.of(windowNode.getSource());
    }//from  ww  w .  j av  a  2 s.  co m

    ImmutableSet.Builder<Symbol> referencedInputs = ImmutableSet.<Symbol>builder().addAll(
            windowNode.getSource().getOutputSymbols().stream().filter(referencedOutputs::contains).iterator())
            .addAll(windowNode.getPartitionBy());

    windowNode.getOrderingScheme()
            .ifPresent(orderingScheme -> orderingScheme.getOrderBy().forEach(referencedInputs::add));
    windowNode.getHashSymbol().ifPresent(referencedInputs::add);

    for (WindowNode.Function windowFunction : referencedFunctions.values()) {
        referencedInputs.addAll(SymbolsExtractor.extractUnique(windowFunction.getFunctionCall()));
        windowFunction.getFrame().getStartValue().ifPresent(referencedInputs::add);
        windowFunction.getFrame().getEndValue().ifPresent(referencedInputs::add);
    }

    PlanNode prunedWindowNode = new WindowNode(windowNode.getId(),
            restrictOutputs(idAllocator, windowNode.getSource(), referencedInputs.build())
                    .orElse(windowNode.getSource()),
            windowNode.getSpecification(), referencedFunctions, windowNode.getHashSymbol(),
            windowNode.getPrePartitionedInputs(), windowNode.getPreSortedOrderPrefix());

    if (prunedWindowNode.getOutputSymbols().size() == windowNode.getOutputSymbols().size()) {
        // Neither function pruning nor input pruning was successful.
        return Optional.empty();
    }

    return Optional.of(prunedWindowNode);
}

From source file:org.janusgraph.diskstorage.configuration.MergedConfiguration.java

@Override
public Set<String> getContainedNamespaces(ConfigNamespace umbrella, String... umbrellaElements) {
    ImmutableSet.Builder<String> b = ImmutableSet.builder();
    b.addAll(first.getContainedNamespaces(umbrella, umbrellaElements));
    b.addAll(second.getContainedNamespaces(umbrella, umbrellaElements));
    return b.build();
}