List of usage examples for com.google.common.collect ImmutableSet isEmpty
boolean isEmpty();
From source file:de.metas.ui.web.handlingunits.HUEditorViewBuffer_HighVolume.java
private Stream<HUEditorRow> streamByIds(@NonNull final HUEditorRowFilter filter) { final Stream<HUEditorRowId> huEditorRowIds; final ImmutableSet<HUEditorRowId> onlyRowIds = filter.getOnlyRowIds(); if (onlyRowIds.isEmpty()) { final List<DocumentQueryOrderBy> defaultOrderBys = getDefaultSelection().getOrderBys(); huEditorRowIds = streamHUIdsByPage(0, Integer.MAX_VALUE, defaultOrderBys) .map(HUEditorRowId::ofTopLevelHU); } else {/*from w w w . j a v a2 s. c o m*/ huEditorRowIds = onlyRowIds.stream(); } return HUEditorRowsPagedLoadingIterator.builder().huEditorRepo(huEditorRepo).cache(cache_huRowsById) .rowIds(huEditorRowIds.iterator()).filter(filter).build().stream(); }
From source file:info.gehrels.voting.singleTransferableVote.STVElectionCalculationStep.java
public final ElectionStepResult<CANDIDATE_TYPE> declareWinnerOrStrikeCandidate(BigFraction quorum, ImmutableCollection<VoteState<CANDIDATE_TYPE>> voteStates, VoteWeightRecalculator<CANDIDATE_TYPE> redistributor, long numberOfElectedCandidates, CandidateStates<CANDIDATE_TYPE> candidateStates) { ImmutableSet<CANDIDATE_TYPE> winningCandidates = allCandidatesThatReachedTheQuorum(quorum, voteStates, candidateStates);/*from w w w. j a v a 2s. c o m*/ if (winningCandidates.isEmpty()) { return calculateElectionStepResultByStrikingTheWeakestCandidate(quorum, voteStates, numberOfElectedCandidates, candidateStates); } else { return calculateElectionStepResultByRedistributingTheWinnersExceedingVotes(quorum, voteStates, redistributor, numberOfElectedCandidates, winningCandidates, candidateStates); } }
From source file:com.facebook.buck.android.AndroidTransitiveDependencyGraph.java
/** * @param uberRDotJava that may have produced {@code R.class} files that need to be dexed. *///from ww w . j a v a 2 s. c om public AndroidDexTransitiveDependencies findDexDependencies( ImmutableList<HasAndroidResourceDeps> androidResourceDeps, final ImmutableSet<JavaLibrary> buildRulesToExcludeFromDex, final UberRDotJava uberRDotJava) { // These are paths that will be dex'ed. They may be either directories of compiled .class files, // or paths to compiled JAR files. final ImmutableSet.Builder<Path> pathsToDexBuilder = ImmutableSet.builder(); // Paths to the classfiles to not dex. final ImmutableSet.Builder<Path> noDxPathsBuilder = ImmutableSet.builder(); // These are paths to third-party jars that may contain resources that must be included in the // final APK. final ImmutableSet.Builder<Path> pathsToThirdPartyJarsBuilder = ImmutableSet.builder(); AndroidResourceDetails details = findAndroidResourceDetails(androidResourceDeps); // Update pathsToDex. final ImmutableSetMultimap<JavaLibrary, Path> classpath = Classpaths .getClasspathEntries(rulesToTraverseForTransitiveDeps); for (Map.Entry<JavaLibrary, Path> entry : classpath.entries()) { if (!buildRulesToExcludeFromDex.contains(entry.getKey())) { pathsToDexBuilder.add(entry.getValue()); } else { noDxPathsBuilder.add(entry.getValue()); } } // Include the directory of compiled R.java files on the classpath. final ImmutableSet<String> rDotJavaPackages = details.rDotJavaPackages; if (!rDotJavaPackages.isEmpty()) { Path pathToCompiledRDotJavaFiles = uberRDotJava.getPathToCompiledRDotJavaFiles(); pathsToDexBuilder.add(pathToCompiledRDotJavaFiles); } ImmutableSet<Path> noDxPaths = noDxPathsBuilder.build(); // Filter out the classpath entries to exclude from dex'ing, if appropriate Set<Path> classpathEntries = Sets.difference(pathsToDexBuilder.build(), noDxPaths); Supplier<Map<String, HashCode>> classNamesToHashesSupplier = Suppliers .memoize(new Supplier<Map<String, HashCode>>() { @Override public Map<String, HashCode> get() { ImmutableMap.Builder<String, HashCode> builder = ImmutableMap.builder(); for (JavaLibrary javaLibrary : classpath.keySet()) { if (!buildRulesToExcludeFromDex.contains(javaLibrary)) { builder.putAll(javaLibrary.getClassNamesToHashes()); } } if (!rDotJavaPackages.isEmpty()) { builder.putAll(uberRDotJava.getClassNamesToHashes()); } return builder.build(); } }); // Visit all of the transitive dependencies to populate the above collections. new AbstractDependencyVisitor(rulesToTraverseForTransitiveDeps) { @Override public ImmutableSet<BuildRule> visit(BuildRule rule) { // We need to include the transitive closure of the compiled .class files when dex'ing, as // well as the third-party jars that they depend on. // Update pathsToThirdPartyJars. if (rule.getBuildable() instanceof PrebuiltJar) { PrebuiltJar prebuiltJar = (PrebuiltJar) rule.getBuildable(); pathsToThirdPartyJarsBuilder.add(prebuiltJar.getBinaryJar()); } return maybeVisitAllDeps(rule, rule.getProperties().is(LIBRARY)); } }.start(); // Classpath entries that should be excluded from dexing should also be excluded from // pathsToThirdPartyJars because their resources should not end up in main APK. If they do, // the pre-dexed library may try to load a resource from the main APK rather than from within // the pre-dexed library (even though the resource is available in both locations). This // causes a significant performance regression, as the resource may take more than one second // longer to load. Set<Path> pathsToThirdPartyJars = Sets.difference(pathsToThirdPartyJarsBuilder.build(), noDxPaths); return new AndroidDexTransitiveDependencies(classpathEntries, pathsToThirdPartyJars, noDxPaths, classNamesToHashesSupplier); }
From source file:com.facebook.buck.rules.keys.DefaultRuleKeyCache.java
/** * Invalidate all inputs *not* from the given {@link ProjectFilesystem}s and their transitive * dependents.//from w w w .j a v a 2s . com */ @Override public void invalidateAllExceptFilesystems(ImmutableSet<ProjectFilesystem> filesystems, CacheStatsTracker statsTracker) { if (filesystems.isEmpty()) { invalidateAll(statsTracker); } else { invalidateInputs(inputsIndex.keySet().stream() .filter(input -> !filesystems.contains(input.getFilesystem())).collect(Collectors.toList()), statsTracker); } }
From source file:com.facebook.buck.jvm.java.AbstractUnusedDependenciesFinder.java
private void findUnusedDependenciesAndProcessMessages(MessageHandler messageHandler, ImmutableSet<Path> usedJars, Iterable<BuildTarget> targets, String dependencyType) { ImmutableSet<UnflavoredBuildTarget> unusedDependencies = findUnusedDependencies(usedJars, targets); if (!unusedDependencies.isEmpty()) { processUnusedDependencies(messageHandler, dependencyType, unusedDependencies); }//from www . java 2 s .c om }
From source file:com.google.devtools.build.lib.rules.objc.WatchExtensionSupport.java
void createBundle(NestedSetBuilder<Artifact> filesToBuild, ObjcProvider.Builder exposedObjcProviderBuilder, XcodeProvider.Builder xcodeProviderBuilder) throws InterruptedException { ObjcProvider releaseBundlingObjcProvider = releaseBundlingObjcProvider(); WatchUtils.addXcodeSettings(ruleContext, xcodeProviderBuilder); registerWatchExtensionAutomaticPlistAction(); ImmutableSet<TargetDeviceFamily> families = attributes.families(); if (families.isEmpty()) { ruleContext.attributeError(FAMILIES_ATTR, ReleaseBundling.INVALID_FAMILIES_ERROR); }/*from w w w .j a va 2s .c o m*/ ReleaseBundling.Builder releaseBundling = new ReleaseBundling.Builder().setIpaArtifact(ipaArtifact) .setBundleId(attributes.bundleId()).setProvisioningProfile(attributes.provisioningProfile()) .setProvisioningProfileAttributeName(WATCH_EXT_PROVISIONING_PROFILE_ATTR) .setTargetDeviceFamilies(families).setIntermediateArtifacts(intermediateArtifacts) .setInfoPlistsFromRule(attributes.infoPlists()).addInfoplistInput(watchExtensionAutomaticPlist()) .setEntitlements(attributes.entitlements()); if (attributes.isBundleIdExplicitySpecified()) { releaseBundling.setPrimaryBundleId(attributes.bundleId()); } else { releaseBundling.setFallbackBundleId(attributes.bundleId()); } AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport(ruleContext, releaseBundlingObjcProvider, LinkedBinary.DEPENDENCIES_ONLY, ReleaseBundlingSupport.EXTENSION_BUNDLE_DIR_FORMAT, bundleName, WatchUtils.determineMinimumIosVersion( appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS)), releaseBundling.build(), appleConfiguration.getMultiArchPlatform(PlatformType.IOS)); releaseBundlingSupport.registerActions(DsymOutputType.APP); releaseBundlingSupport.addXcodeSettings(xcodeProviderBuilder); releaseBundlingSupport.addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)).validateResources() .validateAttributes().addExportedDebugArtifacts(exposedObjcProviderBuilder, DsymOutputType.APP); XcodeSupport xcodeSupport = new XcodeSupport(ruleContext).addFilesToBuild(filesToBuild) .addXcodeSettings(xcodeProviderBuilder, releaseBundlingObjcProvider, WatchOSVersion.OS1.getExtensionXcodeProductType(), ruleContext.getFragment(AppleConfiguration.class).getDependencySingleArchitecture(), configurationDistinguisher) .addDummySource(xcodeProviderBuilder); for (Attribute attribute : dependencyAttributes) { xcodeSupport.addDependencies(xcodeProviderBuilder, attribute); } // Generate xcodeproj for watch OS 1 extension as the main target with watch application // target as the dependency. xcodeProviderBuilder.addPropagatedDependencies(ImmutableList.of(watchApplicationXcodeProvider)); xcodeSupport.registerActions(xcodeProviderBuilder.build()); }
From source file:google.registry.flows.domain.DomainFlowUtils.java
static void validateNameserversAllowedOnTld(String tld, Set<String> fullyQualifiedHostNames) throws EppException { ImmutableSet<String> whitelist = Registry.get(tld).getAllowedFullyQualifiedHostNames(); Set<String> hostnames = nullToEmpty(fullyQualifiedHostNames); if (!whitelist.isEmpty()) { // Empty whitelist is ignored. Set<String> disallowedNameservers = difference(hostnames, whitelist); if (!disallowedNameservers.isEmpty()) { throw new NameserversNotAllowedException(disallowedNameservers); }/*w w w . j av a2 s. c o m*/ } }
From source file:com.facebook.buck.rage.AbstractReport.java
public final Optional<DefectSubmitResult> collectAndSubmitResult() throws IOException, InterruptedException { ImmutableSet<BuildLogEntry> selectedBuilds = promptForBuildSelection(); if (selectedBuilds.isEmpty()) { return Optional.empty(); }// ww w. j a v a 2s . c o m Optional<UserReport> userReport = getUserReport(); Optional<SourceControlInfo> sourceControlInfo = getSourceControlInfo(); ImmutableSet<Path> extraInfoPaths = ImmutableSet.of(); Optional<String> extraInfo = Optional.empty(); try { Optional<ExtraInfoResult> extraInfoResultOptional = extraInfoCollector.run(); if (extraInfoResultOptional.isPresent()) { extraInfoPaths = extraInfoResultOptional.get().getExtraFiles(); extraInfo = Optional.of(extraInfoResultOptional.get().getOutput()); } } catch (DefaultExtraInfoCollector.ExtraInfoExecutionException e) { output.printErrorText("There was a problem gathering additional information: %s. " + "The results will not be attached to the report.", e.getMessage()); } Optional<FileChangesIgnoredReport> fileChangesIgnoredReport = getFileChangesIgnoredReport(); UserLocalConfiguration userLocalConfiguration = UserLocalConfiguration.of(isNoBuckCheckPresent(), getLocalConfigs()); ImmutableSet<Path> includedPaths = FluentIterable.from(selectedBuilds) .transformAndConcat(new Function<BuildLogEntry, Iterable<Path>>() { @Override public Iterable<Path> apply(BuildLogEntry input) { ImmutableSet.Builder<Path> result = ImmutableSet.builder(); Optionals.addIfPresent(input.getRuleKeyLoggerLogFile(), result); Optionals.addIfPresent(input.getMachineReadableLogFile(), result); result.add(input.getRelativePath()); return result.build(); } }).append(extraInfoPaths).append(userLocalConfiguration.getLocalConfigsContents().keySet()) .append(getTracePathsOfBuilds(selectedBuilds)).append(fileChangesIgnoredReport .flatMap(r -> r.getWatchmanDiagReport()).map(ImmutableList::of).orElse(ImmutableList.of())) .toSet(); DefectReport defectReport = DefectReport.builder().setUserReport(userReport) .setHighlightedBuildIds(FluentIterable.from(selectedBuilds) .transformAndConcat(new Function<BuildLogEntry, Iterable<BuildId>>() { @Override public Iterable<BuildId> apply(BuildLogEntry input) { return OptionalCompat.asSet(input.getBuildId()); } })) .setBuildEnvironmentDescription(buildEnvironmentDescription).setSourceControlInfo(sourceControlInfo) .setIncludedPaths(includedPaths).setExtraInfo(extraInfo) .setFileChangesIgnoredReport(fileChangesIgnoredReport) .setUserLocalConfiguration(userLocalConfiguration).build(); output.getStdOut().println("Writing report, please wait..\n"); return Optional.of(defectReporter.submitReport(defectReport)); }
From source file:com.facebook.buck.swift.SwiftRuntimeNativeLinkable.java
@Override public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) throws NoSuchBuildTargetException { NativeLinkableInput.Builder inputBuilder = NativeLinkableInput.builder(); ImmutableSet<Path> swiftRuntimePaths = type == Linker.LinkableDepType.SHARED ? ImmutableSet.of() : swiftPlatform.getSwiftStaticRuntimePaths(); // Fall back to shared if static isn't supported on this platform. if (type == Linker.LinkableDepType.SHARED || swiftRuntimePaths.isEmpty()) { inputBuilder.addAllArgs(StringArg.from("-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/Frameworks")); swiftRuntimePaths = swiftPlatform.getSwiftRuntimePaths(); } else {/* w w w. ja v a2 s .co m*/ // Static linking requires force-loading Swift libs, since the dependency // discovery mechanism is disabled otherwise. inputBuilder.addAllArgs(StringArg.from("-Xlinker", "-force_load_swift_libs")); } for (Path swiftRuntimePath : swiftRuntimePaths) { inputBuilder.addAllArgs(StringArg.from("-L", swiftRuntimePath.toString())); } return inputBuilder.build(); }
From source file:com.google.devtools.build.lib.skyframe.GraphBackedRecursivePackageProvider.java
private void collectPackagesUnder(final RepositoryName repository, Set<TraversalInfo> traversals, ImmutableList.Builder<PathFragment> builder) throws InterruptedException { Map<TraversalInfo, SkyKey> traversalToKeyMap = Maps.asMap(traversals, new Function<TraversalInfo, SkyKey>() { @Override//from w w w . ja v a2s. c o m public SkyKey apply(TraversalInfo traversalInfo) { return CollectPackagesUnderDirectoryValue.key(repository, traversalInfo.rootedDir, traversalInfo.excludedSubdirectories); } }); Map<SkyKey, SkyValue> values = graph.getSuccessfulValues(traversalToKeyMap.values()); ImmutableSet.Builder<TraversalInfo> subdirTraversalBuilder = ImmutableSet.builder(); for (Map.Entry<TraversalInfo, SkyKey> entry : traversalToKeyMap.entrySet()) { TraversalInfo info = entry.getKey(); SkyKey key = entry.getValue(); SkyValue val = values.get(key); CollectPackagesUnderDirectoryValue collectPackagesValue = (CollectPackagesUnderDirectoryValue) val; if (collectPackagesValue != null) { if (collectPackagesValue.isDirectoryPackage()) { builder.add(info.rootedDir.getRelativePath()); } ImmutableMap<RootedPath, Boolean> subdirectoryTransitivelyContainsPackages = collectPackagesValue .getSubdirectoryTransitivelyContainsPackages(); for (RootedPath subdirectory : subdirectoryTransitivelyContainsPackages.keySet()) { if (subdirectoryTransitivelyContainsPackages.get(subdirectory)) { PathFragment subdirectoryRelativePath = subdirectory.getRelativePath(); ImmutableSet<PathFragment> excludedSubdirectoriesBeneathThisSubdirectory = PathFragment .filterPathsStartingWith(info.excludedSubdirectories, subdirectoryRelativePath); subdirTraversalBuilder.add( new TraversalInfo(subdirectory, excludedSubdirectoriesBeneathThisSubdirectory)); } } } } ImmutableSet<TraversalInfo> subdirTraversals = subdirTraversalBuilder.build(); if (!subdirTraversals.isEmpty()) { collectPackagesUnder(repository, subdirTraversals, builder); } }