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:org.eclipse.buildship.core.configuration.internal.DefaultProjectConfigurationManager.java

@Override
public ImmutableSet<ProjectConfiguration> getRootProjectConfigurations() {
    // collect all Gradle root project configurations in the workspace by asking each Eclipse
    // project with a Gradle nature for the Gradle root project it belongs to
    ImmutableSet.Builder<ProjectConfiguration> rootConfigurations = ImmutableSet.builder();
    for (IProject workspaceProject : this.workspaceOperations.getAllProjects()) {
        if (GradleProjectNature.isPresentOn(workspaceProject)) {
            // calculate the root configuration to which the current configuration belongs
            Optional<ProjectConfiguration> projectConfiguration = tryReadProjectConfiguration(workspaceProject);
            if (projectConfiguration.isPresent()) {
                ProjectConfiguration rootProjectConfiguration = ProjectConfiguration.from(
                        projectConfiguration.get().getRootProjectDirectory(),
                        projectConfiguration.get().getGradleDistribution());
                rootConfigurations.add(rootProjectConfiguration);
            }//  ww w .  j a  va2  s. c  om
        }
    }

    // make sure there are no projects that point to the same root project but with a different
    // configuration (different java home, etc.)
    // if such an inconsistent state is detected, it means that the Gradle configurations were
    // changed/corrupted manually
    Map<String, ProjectConfiguration> rootProjectDirs = Maps.newHashMap();
    for (ProjectConfiguration rootProjectConfiguration : rootConfigurations.build()) {
        String rootProjectDirPath = rootProjectConfiguration
                .toRequestAttributes(ConversionStrategy.IGNORE_WORKSPACE_SETTINGS).getProjectDir()
                .getAbsolutePath();
        if (!rootProjectDirs.containsKey(rootProjectDirPath)) {
            rootProjectDirs.put(rootProjectDirPath, rootProjectConfiguration);
        } else {
            throw new GradlePluginsRuntimeException(String.format(
                    "Inconsistent Gradle project configuration for project at %s.", rootProjectDirPath));
        }
    }

    // return the validated, unique set of root project configurations
    return rootConfigurations.build();
}

From source file:info.gehrels.voting.web.BallotBuilder.java

public Ballot<GenderedCandidate> createBallotFromForm(BallotLayout ballotLayout) {
    int i = 0;/*ww w . ja  v  a 2s  .c  o  m*/
    Builder<Vote<GenderedCandidate>> preferenceSetBuilder = ImmutableSet.builder();
    for (GenderedElection genderedElection : ballotLayout.getElections()) {
        Optional<Vote<GenderedCandidate>> vote = votesByElectionId.get(i).createVote(genderedElection);
        if (vote.isPresent()) {
            preferenceSetBuilder.add(vote.get());
        }
        i++;
    }

    return new Ballot<>(ballotId, preferenceSetBuilder.build());
}

From source file:com.facebook.buck.jvm.java.intellij.ModuleBuildContext.java

public ModuleBuildContext(ImmutableSet<BuildTarget> circularDependencyInducingTargets) {
    this.circularDependencyInducingTargets = circularDependencyInducingTargets;
    this.androidFacetBuilder = Optional.empty();
    this.extraClassPathDependenciesBuilder = new ImmutableSet.Builder<>();
    this.generatedSourceCodeFoldersBuilder = ImmutableSet.builder();
    this.sourceFoldersMergeMap = new HashMap<>();
    this.dependencyTypeMap = new HashMap<>();
    this.dependencyOriginMap = HashMultimap.create();
}

From source file:com.tngtech.archunit.lang.syntax.Transformers.java

static ClassesTransformer<JavaConstructor> constructors() {
    return new AbstractClassesTransformer<JavaConstructor>("constructors") {
        @Override/* www .j  a v  a 2 s  .co m*/
        public Iterable<JavaConstructor> doTransform(JavaClasses collection) {
            ImmutableSet.Builder<JavaConstructor> result = ImmutableSet.builder();
            for (JavaClass javaClass : collection) {
                result.addAll(javaClass.getConstructors());
            }
            return result.build();
        }
    };
}

From source file:org.parceler.internal.TransactionProcessorParcelJoin.java

@Override
public ImmutableSet<Exception> getErrors() {
    ImmutableSet.Builder<Exception> builder = ImmutableSet.builder();
    builder.addAll(externalProcessor.getErrors());
    builder.addAll(parcelProcessor.getErrors());

    return builder.build();
}

From source file:com.spotify.heroic.metric.QueryResult.java

/**
 * Collect result parts into a complete result.
 *
 * @param range The range which the result represents.
 * @return A complete QueryResult./*from  ww  w . ja va  2  s. c o m*/
 */
public static Collector<QueryResultPart, QueryResult> collectParts(final QueryTrace.Identifier what,
        final DateRange range, final AggregationCombiner combiner, final OptionalLimit groupLimit) {
    final QueryTrace.NamedWatch w = QueryTrace.watch(what);

    return parts -> {
        final List<List<ShardedResultGroup>> all = new ArrayList<>();
        final List<RequestError> errors = new ArrayList<>();
        final ImmutableList.Builder<QueryTrace> queryTraces = ImmutableList.builder();
        final ImmutableSet.Builder<ResultLimit> limits = ImmutableSet.builder();
        long preAggregationSampleSize = 0;

        for (final QueryResultPart part : parts) {
            errors.addAll(part.getErrors());
            queryTraces.add(part.getQueryTrace());
            limits.addAll(part.getLimits().getLimits());
            preAggregationSampleSize += part.getPreAggregationSampleSize();

            if (part.isEmpty()) {
                continue;
            }

            all.add(part.getGroups());
        }

        final List<ShardedResultGroup> groups = combiner.combine(all);
        final QueryTrace trace = w.end(queryTraces.build());

        if (groupLimit.isGreaterOrEqual(groups.size())) {
            limits.add(ResultLimit.GROUP);
        }

        return new QueryResult(range, groupLimit.limitList(groups), errors, trace,
                new ResultLimits(limits.build()), preAggregationSampleSize, Optional.empty());
    };
}

From source file:org.graylog2.indexer.IndexHelper.java

public static Set<String> determineAffectedIndices(IndexRangeService indexRangeService, Deflector deflector,
        TimeRange range) {//from   w w w .j  a  va 2s. c  om
    final Set<IndexRange> indexRanges = determineAffectedIndicesWithRanges(indexRangeService, deflector, range);
    final ImmutableSet.Builder<String> indices = ImmutableSet.builder();
    for (IndexRange indexRange : indexRanges) {
        indices.add(indexRange.indexName());
    }

    return indices.build();
}

From source file:com.facebook.buck.features.project.intellij.IntellijModulesListParser.java

/**
 * @param modulesFile modules.xml input stream
 * @return A list of module entries as specified by the modules.xml file
 * @throws IOException//  www . jav  a  2  s. c o  m
 */
public ImmutableSet<ModuleIndexEntry> getAllModules(InputStream modulesFile) throws IOException {
    final Document doc;
    try {
        doc = XmlDomParser.parse(modulesFile);
    } catch (SAXException e) {
        LOG.error("Cannot read modules.xml file", e);
        throw new HumanReadableException("Could not update 'modules.xml' file because it is malformed", e);
    }
    final Builder<ModuleIndexEntry> builder = ImmutableSet.builder();
    try {
        XPath xpath = XPathFactory.newInstance().newXPath();
        final NodeList moduleList = (NodeList) xpath.compile("/project/component/modules/module").evaluate(doc,
                XPathConstants.NODESET);
        for (int i = 0; i < moduleList.getLength(); i++) {
            final Element moduleEntry = (Element) moduleList.item(i);
            if (!moduleEntry.hasAttribute("filepath")) {
                continue;
            }
            String filepath = moduleEntry.getAttribute("filepath");
            String fileurl = moduleEntry.getAttribute("fileurl");
            String filepathWithoutProjectPrefix;
            // The template has a hardcoded $PROJECT_DIR$/ prefix, so we need to strip that out
            // of the value we pass to ST
            if (filepath.startsWith("$PROJECT_DIR$")) {
                filepathWithoutProjectPrefix = filepath.substring("$PROJECT_DIR$".length() + 1);
            } else {
                filepathWithoutProjectPrefix = filepath;
            }
            builder.add(ModuleIndexEntry.builder().setFilePath(Paths.get(filepathWithoutProjectPrefix))
                    .setFileUrl(fileurl)
                    .setGroup(moduleEntry.hasAttribute("group") ? moduleEntry.getAttribute("group") : null)
                    .build());
        }
    } catch (XPathExpressionException e) {
        throw new HumanReadableException("Illegal xpath expression.", e);
    }
    return builder.build();
}

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

private static ImmutableSet<BuildTargetPattern> getVisibilityPatterns(TargetNode<?> targetNode)
        throws NoSuchBuildTargetException {
    ImmutableSet.Builder<BuildTargetPattern> builder = ImmutableSet.builder();
    BuildRuleFactoryParams params = targetNode.getRuleFactoryParams();
    for (String visibility : params.getOptionalListAttribute("visibility")) {
        builder.add(params.buildTargetPatternParser.parse(visibility, ParseContext.forVisibilityArgument()));
    }/*w w w .java 2s  . c o  m*/
    return builder.build();
}

From source file:org.spongepowered.mod.registry.SpongeForgeGameDictionary.java

@Override
public Set<Entry> get(String key) {
    ImmutableSet.Builder<Entry> items = ImmutableSet.builder();
    for (ItemStack itemStack : OreDictionary.getOres(key)) {
        itemStack = itemStack.copy();/*from w w  w.  ja v  a 2  s .  c  o  m*/
        itemStack.stackSize = 1;
        items.add(SpongeGameDictionaryEntry.of(itemStack, OreDictionary.WILDCARD_VALUE));
    }
    return items.build();
}