List of usage examples for com.google.common.collect ImmutableSet stream
default Stream<E> stream()
From source file:com.facebook.buck.features.project.intellij.IjProjectSubCommand.java
private ExitCode runBuild(CommandRunnerParams params, ImmutableSet<BuildTarget> targets, boolean disableCaching) throws IOException, InterruptedException { BuildCommand buildCommand = new BuildCommand( targets.stream().map(Object::toString).collect(ImmutableList.toImmutableList())); buildCommand.setKeepGoing(true);/*ww w . j av a 2 s . co m*/ try { return buildCommand .run(disableCaching ? params.withArtifactCacheFactory(new NoopArtifactCacheFactory()) : params); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:io.github.mywarp.mywarp.command.util.printer.InfoPrinter.java
/** * Gets information text./*w w w. java2s .c om*/ * * @param receiver the Actor who will receive the text * @return the text */ public Message getText(Actor receiver) { Message.Builder info = Message.builder(); // heading info.append(Message.Style.HEADLINE_1); info.append(msg.getString("info.heading")); info.append(" '"); info.append(warp); info.append("':"); info.appendNewLine(); // creator info.append(Message.Style.KEY); info.append(msg.getString("info.created-by")); info.append(" "); info.append(Message.Style.VALUE); UUID creator = warp.getCreator(); info.append(CommandUtil.toName(creator, playerNameResolver)); if (receiver instanceof LocalPlayer && warp.isCreator(((LocalPlayer) receiver).getUniqueId())) { info.append(" "); info.append(msg.getString("info.created-by-you")); } info.appendNewLine(); // location info.append(Message.Style.KEY); info.append(msg.getString("info.location")); info.append(" "); info.append(Message.Style.VALUE); info.append(msg.getString("info.location.position", warp.getPosition().getFloorX(), warp.getPosition().getFloorY(), warp.getPosition().getFloorZ(), worldName(warp.getWorldIdentifier()))); info.appendNewLine(); // if the warp is modifiable, show information about invitations if (authorizationResolver.isModifiable(warp, receiver)) { // criteria players info.append(Message.Style.KEY); info.append(msg.getString("info.invited-players")); info.append(" "); info.append(Message.Style.VALUE); ImmutableSet<PlayerMatcher> invitations = warp.getInvitations(); List<String> invitedPlayers = invitations.stream().filter(UuidPlayerMatcher.class::isInstance) .map(i -> CommandUtil.toName(((UuidPlayerMatcher) i).getCriteria(), playerNameResolver)) .sorted().collect(Collectors.toList()); if (invitedPlayers.isEmpty()) { info.append("-"); } else { info.appendWithSeparators(invitedPlayers); } info.appendNewLine(); // criteria groups info.append(Message.Style.KEY); info.append(msg.getString("info.invited-groups")); info.append(" "); info.append(Message.Style.VALUE); List<String> invitedGroups = invitations.stream().filter(GroupPlayerMatcher.class::isInstance) .map(Object::toString).sorted().collect(Collectors.toList()); if (invitedGroups.isEmpty()) { info.append("-"); } else { info.appendWithSeparators(invitedGroups); } info.appendNewLine(); } // creation date info.append(Message.Style.KEY); info.append(msg.getString("info.creation-date", warp.getCreationDate())); info.append(" "); info.append(Message.Style.VALUE); info.append(TIME_FORMATTER.withLocale(LocaleManager.getLocale()).format(warp.getCreationDate())); info.appendNewLine(); // visits info.append(Message.Style.KEY); info.append(msg.getString("info.visits")); info.append(" "); info.append(Message.Style.VALUE); info.append(msg.getString("info.visits.per-day", warp.getVisits(), WarpUtils.visitsPerDay(warp))); return info.build(); }
From source file:com.facebook.buck.ide.intellij.IjProjectCommandHelper.java
private ImmutableSet<BuildTarget> getTargetsWithAnnotations(final TargetGraph targetGraph, ImmutableSet<BuildTarget> buildTargets) { return buildTargets.stream().filter(input -> { TargetNode<?, ?> targetNode = targetGraph.get(input); return targetNode != null && isTargetWithAnnotations(targetNode); }).collect(MoreCollectors.toImmutableSet()); }
From source file:com.facebook.buck.apple.AppleDescriptions.java
public static Optional<SceneKitAssets> createBuildRulesForSceneKitAssetsDependencies(TargetGraph targetGraph, BuildRuleParams params, AppleCxxPlatform appleCxxPlatform) { TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget()); ImmutableSet<AppleWrapperResourceArg> sceneKitAssetsArgs = AppleBuildRules.collectTransitiveBuildRules( targetGraph, Optional.empty(), AppleBuildRules.SCENEKIT_ASSETS_DESCRIPTION_CLASSES, ImmutableList.of(targetNode)); BuildRuleParams sceneKitAssetsParams = params.copyWithChanges( params.getBuildTarget().withAppendedFlavors(SceneKitAssets.FLAVOR), Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())); if (sceneKitAssetsArgs.isEmpty()) { return Optional.empty(); } else {/*from w ww .jav a 2 s .c o m*/ return Optional.of(new SceneKitAssets(sceneKitAssetsParams, appleCxxPlatform, sceneKitAssetsArgs.stream() .map(input -> new PathSourcePath(params.getProjectFilesystem(), input.path)) .collect(MoreCollectors.toImmutableSet()))); } }
From source file:com.facebook.buck.core.config.AbstractAliasConfig.java
public ImmutableSet<String> getBuildTargetForAliasAsString(String possiblyFlavoredAlias) { String[] parts = possiblyFlavoredAlias.split("#", 2); String unflavoredAlias = parts[0]; ImmutableSet<BuildTarget> buildTargets = getBuildTargetsForAlias(unflavoredAlias); if (buildTargets.isEmpty()) { return ImmutableSet.of(); }/*from w w w. j a va2s . com*/ String suffix = parts.length == 2 ? "#" + parts[1] : ""; return buildTargets.stream().map(buildTarget -> buildTarget.getFullyQualifiedName() + suffix) .collect(ImmutableSet.toImmutableSet()); }
From source file:com.facebook.buck.apple.AppleDescriptions.java
public static Optional<CoreDataModel> createBuildRulesForCoreDataDependencies(TargetGraph targetGraph, BuildRuleParams params, String moduleName, AppleCxxPlatform appleCxxPlatform) { TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget()); ImmutableSet<AppleWrapperResourceArg> coreDataModelArgs = AppleBuildRules.collectTransitiveBuildRules( targetGraph, Optional.empty(), AppleBuildRules.CORE_DATA_MODEL_DESCRIPTION_CLASSES, ImmutableList.of(targetNode)); BuildRuleParams coreDataModelParams = params.copyWithChanges( params.getBuildTarget().withAppendedFlavors(CoreDataModel.FLAVOR), Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())); if (coreDataModelArgs.isEmpty()) { return Optional.empty(); } else {//from ww w . ja v a 2 s . c o m return Optional.of(new CoreDataModel(coreDataModelParams, appleCxxPlatform, moduleName, coreDataModelArgs.stream() .map(input -> new PathSourcePath(params.getProjectFilesystem(), input.path)) .collect(MoreCollectors.toImmutableSet()))); } }
From source file:com.facebook.buck.android.AndroidPackageableCollector.java
public AndroidPackageableCollection build() { collectionBuilder.setBuildConfigs(ImmutableMap.copyOf(buildConfigs)); final ImmutableSet<HasJavaClassHashes> javaClassProviders = javaClassHashesProviders.build(); collectionBuilder.addAllJavaLibrariesToDex(javaClassProviders.stream().map(HasBuildTarget::getBuildTarget) .collect(MoreCollectors.toImmutableSet())); collectionBuilder.setClassNamesToHashesSupplier(Suppliers.memoize(() -> { ImmutableMap.Builder<String, HashCode> builder = ImmutableMap.builder(); for (HasJavaClassHashes hasJavaClassHashes : javaClassProviders) { builder.putAll(hasJavaClassHashes.getClassNamesToHashes()); }//w w w. j a va2s .c o m return builder.build(); })); ImmutableSet<BuildTarget> resources = ImmutableSet.copyOf(resourcesWithNonEmptyResDir.build()); for (BuildTarget buildTarget : resourcesWithAssets.build()) { if (!resources.contains(buildTarget)) { resourceDetailsBuilder.addResourcesWithEmptyResButNonEmptyAssetsDir(buildTarget); } } // Reverse the resource directories/targets collections because we perform a post-order // traversal of the action graph, and we need to return these collections topologically // sorted. resourceDetailsBuilder.setResourceDirectories( resourceDirectories.build().reverse().stream().distinct().collect(Collectors.toList())); resourceDetailsBuilder.setResourcesWithNonEmptyResDir(resourcesWithNonEmptyResDir.build().reverse()); collectionBuilder.setResourceDetails(resourceDetailsBuilder.build()); return collectionBuilder.build(); }
From source file:com.google.errorprone.bugpatterns.MutableMethodReturnType.java
@Override public Description matchMethod(MethodTree methodTree, VisitorState state) { MethodSymbol methodSymbol = ASTHelpers.getSymbol(methodTree); if (methodSymbol.isConstructor()) { return Description.NO_MATCH; }/*from w w w.j av a 2s .c om*/ if (ASTHelpers.methodCanBeOverridden(methodSymbol)) { return Description.NO_MATCH; } if (ANNOTATED_WITH_PRODUCES_OR_PROVIDES.matches(methodTree, state)) { return Description.NO_MATCH; } Type returnType = methodSymbol.getReturnType(); if (ImmutableCollections.isImmutableType(returnType)) { return Description.NO_MATCH; } ImmutableSet<ClassType> returnStatementsTypes = getMethodReturnTypes(methodTree); if (returnStatementsTypes.isEmpty()) { return Description.NO_MATCH; } boolean alwaysReturnsImmutableType = returnStatementsTypes.stream() .allMatch(ImmutableCollections::isImmutableType); if (!alwaysReturnsImmutableType) { return Description.NO_MATCH; } Optional<String> immutableReturnType = ImmutableCollections .mutableToImmutable(getTypeQualifiedName(returnType)); if (!immutableReturnType.isPresent()) { immutableReturnType = getCommonImmutableTypeForAllReturnStatementsTypes(returnStatementsTypes); } if (!immutableReturnType.isPresent()) { return Description.NO_MATCH; } Type newReturnType = state.getTypeFromString(immutableReturnType.get()); SuggestedFix.Builder fixBuilder = SuggestedFix.builder(); Tree typeTree = ASTHelpers.getErasedTypeTree(methodTree.getReturnType()); verify(typeTree != null, "Could not find return type of %s", methodTree); fixBuilder.replace(typeTree, SuggestedFixes.qualifyType(state, fixBuilder, newReturnType.asElement())); SuggestedFix fix = fixBuilder.build(); return describeMatch(methodTree.getReturnType(), fix); }
From source file:ai.grakn.graql.internal.gremlin.ConjunctionQuery.java
/** * @param patternConjunction a pattern containing no disjunctions to find in the graph *//*from w ww .j a v a 2s .c o m*/ ConjunctionQuery(Conjunction<VarPatternAdmin> patternConjunction, GraknGraph graph) { vars = patternConjunction.getPatterns(); if (vars.size() == 0) { throw GraqlQueryException.noPatterns(); } ImmutableSet<EquivalentFragmentSet> fragmentSets = vars.stream() .flatMap(ConjunctionQuery::equivalentFragmentSetsRecursive).collect(toImmutableSet()); // Get all variable names mentioned in non-starting fragments Set<Var> names = fragmentSets.stream().flatMap(EquivalentFragmentSet::stream) .filter(fragment -> !fragment.isStartingFragment()) .flatMap(fragment -> fragment.getVariableNames().stream()).collect(toImmutableSet()); // Get all dependencies fragments have on certain variables existing Set<Var> dependencies = fragmentSets.stream().flatMap(EquivalentFragmentSet::stream) .flatMap(fragment -> fragment.getDependencies().stream()).collect(toImmutableSet()); Set<Var> validNames = Sets.difference(names, dependencies); // Filter out any non-essential starting fragments (because other fragments refer to their starting variable) Set<EquivalentFragmentSet> initialEquivalentFragmentSets = fragmentSets.stream() .filter(set -> set.stream().anyMatch( fragment -> !fragment.isStartingFragment() || !validNames.contains(fragment.getStart()))) .collect(toSet()); // Apply final optimisations EquivalentFragmentSets.optimiseFragmentSets(initialEquivalentFragmentSets, graph); this.equivalentFragmentSets = ImmutableSet.copyOf(initialEquivalentFragmentSets); }
From source file:com.facebook.buck.features.project.intellij.aggregation.AggregationTree.java
private ImmutableMap<Path, AggregationModule> collectModulesToAggregate(IjModuleType rootModuleType, AggregationTreeNode parentNode, ImmutableSet<Path> modulePathsToAggregate) { int aggregationLimit = rootModuleType.getAggregationLimit(projectConfig); ImmutableMap<Path, AggregationModule> modules = modulePathsToAggregate.stream() .collect(ImmutableMap.toImmutableMap(path -> path, path -> parentNode.getChild(path).getModule())); if (aggregationLimit == Integer.MAX_VALUE) { return modules; }/*from ww w .j av a 2 s. c o m*/ ImmutableMap.Builder<Path, AggregationModule> filteredModules = ImmutableMap.builder(); int count = 0; if (parentNode.getModule() != null) { count += parentNode.getModule().getTargets().size(); } for (Map.Entry<Path, AggregationModule> pathWithModule : modules.entrySet()) { int childTargetsSize = pathWithModule.getValue().getTargets().size(); if (count + childTargetsSize > aggregationLimit) { continue; } filteredModules.put(pathWithModule.getKey(), pathWithModule.getValue()); count += childTargetsSize; if (count == aggregationLimit) { break; } } return filteredModules.build(); }