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.spotify.styx.Scheduler.java

private Set<String> workflowResources(Optional<Long> globalConcurrency, WorkflowId workflowId) {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    globalConcurrency.ifPresent(concurrency -> builder.add(GLOBAL_RESOURCE_ID));

    workflowCache.workflow(workflowId)//from  ww w . j  a va 2 s.c o m
            .ifPresent(workflow -> builder.addAll(workflow.configuration().resources()));

    return builder.build();
}

From source file:org.apache.sentry.provider.file.Roles.java

public ImmutableSet<String> getRoles(@Nullable String database, String group, Boolean isURI) {
    ImmutableSet.Builder<String> resultBuilder = ImmutableSet.builder();
    String allowURIPerDbFile = System.getProperty(SimplePolicyEngine.ACCESS_ALLOW_URI_PER_DB_POLICYFILE);
    Boolean consultPerDbRolesForURI = isURI && ("true".equalsIgnoreCase(allowURIPerDbFile));

    if (database != null) {
        ImmutableSetMultimap<String, String> dbPolicies = perDatabaseRoles.get(database);
        if (dbPolicies != null && dbPolicies.containsKey(group)) {
            resultBuilder.addAll(dbPolicies.get(group));
        }/*from www . j a v a2s .c  o m*/
    }
    if (consultPerDbRolesForURI) {
        for (String db : perDatabaseRoles.keySet()) {
            ImmutableSetMultimap<String, String> dbPolicies = perDatabaseRoles.get(db);
            if (dbPolicies != null && dbPolicies.containsKey(group)) {
                resultBuilder.addAll(dbPolicies.get(group));
            }
        }
    }

    if (globalRoles.containsKey(group)) {
        resultBuilder.addAll(globalRoles.get(group));
    }
    ImmutableSet<String> result = resultBuilder.build();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Database {}, Group {}, Result {}", new Object[] { database, group, result });
    }
    return result;
}

From source file:org.spongepowered.common.data.manipulator.item.SpongeStoredEnchantmentData.java

@Override
public DataTransactionResult set(Enchantment... mapped) {
    checkNotNull(mapped);/*from  ww w  .java2  s .  c o  m*/
    ImmutableSet.Builder<DataManipulator<?>> builder = ImmutableSet.builder();
    for (Enchantment enchantment : mapped) {
        DataTransactionResult result = set(enchantment, enchantment.getMinimumLevel());
        if (result.getType() == DataTransactionResult.Type.SUCCESS) {
            if (result.getReplacedData().isPresent()) {
                builder.addAll(result.getReplacedData().get());
            }
        } else {
            rejected(result, builder.build());
        }
    }
    return succesReplaced(builder.build());
}

From source file:org.wisdom.api.router.Route.java

/**
 * Sets the set of media types accepted by the route.
 *
 * @param types the set of type/*ww w  .  j av a  2s  .  c o  m*/
 * @return the current route
 */
public Route accepts(String... types) {
    Preconditions.checkNotNull(types);
    final ImmutableSet.Builder<MediaType> builder = new ImmutableSet.Builder<>();
    builder.addAll(this.acceptedMediaTypes);
    for (String s : types) {
        builder.add(MediaType.parse(s));
    }
    this.acceptedMediaTypes = builder.build();
    return this;
}

From source file:org.onosproject.segmentrouting.config.DeviceConfiguration.java

/**
 * Returns the configured subnet prefixes for a segment router.
 *
 * @param deviceId device identifier// w  ww . j  av  a 2s.  c  o  m
 * @return list of ip prefixes or null if not found
 */
public Set<Ip4Prefix> getSubnets(DeviceId deviceId) {
    SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
    if (srinfo != null) {
        log.trace("getSubnets for device{} is {}", deviceId, srinfo.subnets.values());

        ImmutableSet.Builder<Ip4Prefix> builder = ImmutableSet.builder();
        builder.addAll(srinfo.subnets.values());
        SegmentRoutingAppConfig appConfig = srManager.cfgService.getConfig(srManager.appId,
                SegmentRoutingAppConfig.class);
        if (appConfig != null) {
            if (deviceId.equals(appConfig.vRouterId().orElse(null))) {
                builder.add(Ip4Prefix.valueOf("0.0.0.0/0"));
            }
        }
        return builder.build();
    }
    return null;
}

From source file:org.wisdom.api.router.Route.java

/**
 * Sets the set of media types produced by the route.
 *
 * @param types the set of type//from   w  w w . j  ava 2s  .co m
 * @return the current route
 */
public Route produces(String... types) {
    Preconditions.checkNotNull(types);
    final ImmutableSet.Builder<MediaType> builder = new ImmutableSet.Builder<>();
    builder.addAll(this.producedMediaTypes);
    for (String s : types) {
        final MediaType mt = MediaType.parse(s);
        if (mt.hasWildcard()) {
            throw new RoutingException("A route cannot `produce` a mime type with a wildcard: " + mt);
        }
        builder.add(mt);
    }
    this.producedMediaTypes = builder.build();
    return this;
}

From source file:com.facebook.buck.rules.JavaTestRule.java

/**
 * Runs the tests specified by the "srcs" of this class. If this rule transitively depends on
 * other {@code java_test()} rules, then they will be run separately.
 *//*from   ww w  . j  av a2s  . co m*/
@Override
public List<Step> runTests(BuildContext buildContext, ExecutionContext executionContext) {
    Preconditions.checkState(isRuleBuilt(), "%s must be built before tests can be run.", this);

    // If no classes were generated, then this is probably a java_test() that declares a number of
    // other java_test() rules as deps, functioning as a test suite. In this case, simply return an
    // empty list of commands.
    Set<String> testClassNames = getClassNamesForSources();
    if (testClassNames.isEmpty()) {
        return ImmutableList.of();
    }

    // androidResourceDeps will be null if this test is re-run without being rebuilt.
    if (androidResourceDeps == null) {
        androidResourceDeps = AndroidResourceRule.getAndroidResourceDeps(this,
                buildContext.getDependencyGraph());
    }

    ImmutableList.Builder<Step> steps = ImmutableList.builder();

    String pathToTestOutput = getPathToTestOutput();
    MakeCleanDirectoryStep mkdirClean = new MakeCleanDirectoryStep(pathToTestOutput);
    steps.add(mkdirClean);

    // If there are android resources, then compile the uber R.java files and add them to the
    // classpath used to run the test runner.
    ImmutableSet<String> classpathEntries;
    if (isAndroidRule()) {
        BuildTarget buildTarget = getBuildTarget();
        String rDotJavaClasspathEntry;
        UberRDotJavaUtil.createDummyRDotJavaFiles(androidResourceDeps, buildTarget, steps);
        rDotJavaClasspathEntry = UberRDotJavaUtil.getRDotJavaBinFolder(buildTarget);
        ImmutableSet.Builder<String> classpathEntriesBuilder = ImmutableSet.builder();
        classpathEntriesBuilder.add(rDotJavaClasspathEntry);
        classpathEntriesBuilder.addAll(getTransitiveClasspathEntries().values());
        classpathEntries = classpathEntriesBuilder.build();
    } else {
        classpathEntries = ImmutableSet.copyOf(getTransitiveClasspathEntries().values());
    }

    Step junit = new JUnitStep(classpathEntries, testClassNames, vmArgs, pathToTestOutput,
            executionContext.isCodeCoverageEnabled, executionContext.isDebugEnabled());
    steps.add(junit);

    return steps.build();
}

From source file:ca.cutterslade.match.scheduler.MatchMaker.java

ImmutableSet<Match> getMatches() throws InterruptedException {
    ImmutableSet<ImmutableSet<Team>> matches = executor
            .interleaf(PossibleMatchesCallable.forTiers(this.tiers.asMap().values(), teamSize));
    ImmutableSet.Builder<Match> b = ImmutableSet.builder();
    final Collection<Day> days;
    if (configuration.isRandomizeDayOrder()) {
        List<Day> d = Lists.newArrayList(this.days.keySet());
        Collections.shuffle(d);/* w  w w  .j av  a2s . com*/
        days = d;
    } else
        days = this.days.keySet();
    for (Day d : days)
        b.addAll(getMatchesForDay(d, b.build(), matches));
    return b.build();
}

From source file:com.facebook.buck.parser.PerBuildState.java

public ImmutableSet<TargetGroup> getAllGroups() throws BuildFileParseException {
    ImmutableSet.Builder<TargetGroup> allGroups = ImmutableSet.builder();
    for (Cell cell : cells.values()) {
        Path cellRootBuildFile = cell.getRoot().resolve(cell.getBuildFileName());
        if (Files.exists(cellRootBuildFile)) {
            allGroups.addAll(targetGroupParsePipeline.getAllNodes(cell, cellRootBuildFile));
        }/* ww  w .  ja v  a 2s.  c  o  m*/
    }
    return allGroups.build();
}

From source file:org.spongepowered.common.data.manipulator.item.SpongeStoredEnchantmentData.java

@Override
public DataTransactionResult set(Map<Enchantment, Integer> mapped) {
    checkNotNull(mapped);//from   ww w  .  jav a 2 s  .c o m
    ImmutableSet.Builder<DataManipulator<?>> builder = ImmutableSet.builder();
    for (Map.Entry<Enchantment, Integer> entry : mapped.entrySet()) {
        DataTransactionResult result = set(entry.getKey(), entry.getValue());
        if (result.getType() == DataTransactionResult.Type.SUCCESS) {
            if (result.getReplacedData().isPresent()) {
                builder.addAll(result.getReplacedData().get());
            }
        } else {
            rejected(result, builder.build());
        }
    }
    return succesReplaced(builder.build());
}