类com.google.common.collect.ImmutableCollection源码实例Demo

下面列出了怎么用com.google.common.collect.ImmutableCollection的API类实例代码及写法,或者点击链接到github查看源代码。

private ResourcesFilter createResourcesFilter(
    InternalFlavor flavor,
    AndroidPackageableCollection.ResourceDetails resourceDetails,
    ImmutableSortedSet<BuildRule> resourceRules,
    ImmutableCollection<BuildRule> rulesWithResourceDirectories) {
  return new ResourcesFilter(
      buildTarget.withAppendedFlavors(RESOURCES_FILTER_FLAVOR, flavor),
      projectFilesystem,
      resourceRules,
      rulesWithResourceDirectories,
      graphBuilder,
      resourceDetails.getResourceDirectories(),
      ImmutableSet.copyOf(resourceDetails.getWhitelistedStringDirectories()),
      locales,
      localizedStringFileName,
      resourceCompressionMode,
      resourceFilter,
      postFilterResourcesCmd);
}
 
源代码2 项目: buck   文件: IjSourceRootSimplifierTest.java
@Test
public void testDifferentTypesAreNotMergedIntoParent() {
  IjSourceRootSimplifier simplifier = new IjSourceRootSimplifier(fakePackageFinder());
  IjFolder aSource = buildSourceFolder("a");
  IjFolder aaaSource = buildSourceFolder("a/a/a");
  IjFolder aaaaSource = buildSourceFolder("a/a/a/a");
  IjFolder aabSource = buildSourceFolder("a/a/b");
  IjFolder abSource = buildSourceFolder("a/b");
  IjFolder acTest = buildTestFolder("a/c");
  IjFolder adaTest = buildTestFolder("a/d/a");

  ImmutableCollection<IjFolder> mergedFolders =
      simplifier
          .simplify(
              0,
              ImmutableSet.of(
                  aSource, aaaSource, aaaaSource, aabSource, abSource, acTest, adaTest),
              Paths.get(""),
              ImmutableSet.of())
          .values();

  IjFolder adTest = buildTestFolder("a/d");
  assertThat(mergedFolders, Matchers.containsInAnyOrder(aSource, acTest, adTest));
}
 
源代码3 项目: nomulus   文件: IcannReportingStager.java
/** Creates and stores activity reports on GCS, returns a list of files stored. */
private ImmutableList<String> stageActivityReports(
    YearMonth yearMonth,
    String subdir,
    String headerRow,
    ImmutableCollection<Map<TableFieldSchema, Object>> rows)
    throws IOException {
  ImmutableList.Builder<String> manifestBuilder = new ImmutableList.Builder<>();
  // Create a report csv for each tld from query table, and upload to GCS
  for (Map<TableFieldSchema, Object> row : rows) {
    // Get the tld (first cell in each row)
    String tld = row.values().iterator().next().toString();
    if (isNullOrEmpty(tld)) {
      throw new RuntimeException("Found an empty row in the activity report table!");
    }
    ImmutableList<String> rowStrings = ImmutableList.of(constructRow(row.values()));
    // Create and upload the activity report with a single row
    manifestBuilder.add(
        saveReportToGcs(
            tld, yearMonth, subdir, createReport(headerRow, rowStrings), ReportType.ACTIVITY));
  }
  return manifestBuilder.build();
}
 
源代码4 项目: buck   文件: GoTestDescription.java
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractGoTestDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  // Add the C/C++ platform parse time deps.
  GoPlatform platform =
      GoDescriptors.getPlatformForRule(
          getGoToolchain(buildTarget.getTargetConfiguration()),
          this.goBuckConfig,
          buildTarget,
          constructorArg);
  targetGraphOnlyDepsBuilder.addAll(
      CxxPlatforms.getParseTimeDeps(
          buildTarget.getTargetConfiguration(), platform.getCxxPlatform()));
}
 
源代码5 项目: bazel   文件: LocationTemplateContext.java
public LocationTemplateContext(
    TemplateContext delegate,
    RuleContext ruleContext,
    @Nullable ImmutableMap<Label, ImmutableCollection<Artifact>> labelMap,
    boolean execPaths,
    boolean allowData,
    boolean windowsPath) {
  this(
      delegate,
      ruleContext.getLabel(),
      // Use a memoizing supplier to avoid eagerly building the location map.
      Suppliers.memoize(
          () -> LocationExpander.buildLocationMap(ruleContext, labelMap, allowData)),
      execPaths,
      ruleContext.getRule().getPackage().getRepositoryMapping(),
      windowsPath);
}
 
源代码6 项目: buck   文件: CxxPythonExtensionDescription.java
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractCxxPythonExtensionDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  // Get any parse time deps from the C/C++ platforms.
  getCxxPlatforms(buildTarget.getTargetConfiguration())
      .getValues(buildTarget)
      .forEach(
          p -> extraDepsBuilder.addAll(p.getParseTimeDeps(buildTarget.getTargetConfiguration())));

  for (PythonPlatform pythonPlatform :
      getPythonPlatforms(buildTarget.getTargetConfiguration()).getValues()) {
    Optionals.addIfPresent(pythonPlatform.getCxxLibrary(), extraDepsBuilder);
  }
}
 
源代码7 项目: vespa   文件: SearchPath.java
private Group selectGroup(SearchCluster cluster) {
    if (group != null) {
        Optional<Group> specificGroup = cluster.group(group);
        if (specificGroup.isPresent()) {
            return specificGroup.get();
        } else {
            throw new InvalidSearchPathException("Invalid searchPath, cluster does not have " + (group + 1) + " groups");
        }
    }

    // pick "anything": try to find the first working
    ImmutableCollection<Group> groups = cluster.groups().values();
    for (Group g : groups) {
        if (g.hasSufficientCoverage()) {
            return g;
        }
    }

    // fallback: first
    return groups.iterator().next();
}
 
源代码8 项目: buck   文件: CxxWriteArgsToFileStep.java
static ImmutableList<String> stringify(
    ImmutableCollection<Arg> args,
    CanonicalCellName currentCellName,
    SourcePathResolverAdapter pathResolver,
    boolean useUnixPathSeparator) {
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (Arg arg : args) {
    if (arg instanceof FileListableLinkerInputArg) {
      ((FileListableLinkerInputArg) arg)
          .appendToCommandLineRel(
              builder::add, currentCellName, pathResolver, useUnixPathSeparator);
    } else if (arg instanceof SourcePathArg) {
      ((SourcePathArg) arg)
          .appendToCommandLineRel(
              builder::add, currentCellName, pathResolver, useUnixPathSeparator);
    } else if (arg instanceof CompositeArg) {
      ((CompositeArg) arg)
          .appendToCommandLineRel(
              builder::add, currentCellName, pathResolver, useUnixPathSeparator);
    } else {
      arg.appendToCommandLine(builder::add, pathResolver);
    }
  }
  return builder.build();
}
 
源代码9 项目: codebuff   文件: AggregateFuture.java
@CanIgnoreReturnValue
@Override
public final boolean cancel(boolean mayInterruptIfRunning) {
  // Must get a reference to the futures before we cancel, as they'll be cleared out.
  RunningState localRunningState = runningState;
  ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures =
      (localRunningState != null) ? localRunningState.futures : null;
  // Cancel all the component futures.
  boolean cancelled = super.cancel(mayInterruptIfRunning);
  // & is faster than the branch required for &&
  if (cancelled & futures != null) {
    for (ListenableFuture<?> future : futures) {
      future.cancel(mayInterruptIfRunning);
    }
  }
  return cancelled;
}
 
源代码10 项目: buck   文件: CgoLibraryDescription.java
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    CgoLibraryDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  // Add the C/C++ platform deps.
  GoToolchain toolchain = getGoToolchain(buildTarget.getTargetConfiguration());
  toolchain
      .getPlatformFlavorDomain()
      .getValue(buildTarget)
      .ifPresent(
          platform ->
              targetGraphOnlyDepsBuilder.addAll(
                  CxxPlatforms.getParseTimeDeps(
                      buildTarget.getTargetConfiguration(), platform.getCxxPlatform())));
}
 
源代码11 项目: buck   文件: HaskellHaddockDescription.java
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractHaskellHaddockDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {

  HaskellDescriptionUtils.getParseTimeDeps(
      buildTarget.getTargetConfiguration(),
      ImmutableList.of(getPlatform(buildTarget, constructorArg)),
      targetGraphOnlyDepsBuilder);

  constructorArg
      .getDepsQuery()
      .ifPresent(
          depsQuery ->
              QueryUtils.extractParseTimeTargets(buildTarget, cellRoots, depsQuery)
                  .forEach(targetGraphOnlyDepsBuilder::add));
}
 
源代码12 项目: buck   文件: AndroidBinaryResourcesGraphEnhancer.java
private PackageStringAssets createPackageStringAssets(
    ImmutableSortedSet<BuildRule> resourceRules,
    ImmutableCollection<BuildRule> rulesWithResourceDirectories,
    FilteredResourcesProvider filteredResourcesProvider,
    AaptOutputInfo aaptOutputInfo) {
  return new PackageStringAssets(
      buildTarget.withAppendedFlavors(
          AndroidBinaryResourcesGraphEnhancer.PACKAGE_STRING_ASSETS_FLAVOR),
      projectFilesystem,
      graphBuilder,
      resourceRules,
      rulesWithResourceDirectories,
      filteredResourcesProvider,
      locales,
      aaptOutputInfo.getPathToRDotTxt());
}
 
源代码13 项目: LuckPerms   文件: AbstractUserManager.java
/**
 * Check whether the user's state indicates that they should be persisted to storage.
 *
 * @param user the user to check
 * @return true if the user should be saved
 */
@Override
public boolean shouldSave(User user) {
    ImmutableCollection<Node> nodes = user.normalData().immutable().values();
    if (nodes.size() != 1) {
        return true;
    }

    Node onlyNode = nodes.iterator().next();
    if (!(onlyNode instanceof InheritanceNode)) {
        return true;
    }

    if (onlyNode.hasExpiry() || !onlyNode.getContexts().isEmpty()) {
        return true;
    }

    if (!((InheritanceNode) onlyNode).getGroupName().equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) {
        // The user's only node is not the default group one.
        return true;
    }


    // Not in the default primary group
    return !user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME);
}
 
@Test
public void variantsWithoutNativeLibs() throws Exception {
  NativeLibsCompressionVariantGenerator nativeLibsCompressionVariantGenerator =
      new NativeLibsCompressionVariantGenerator(
          ApkGenerationConfiguration.builder()
              .setEnableNativeLibraryCompressionSplitter(true)
              .build());

  BundleModule bundleModule =
      new BundleModuleBuilder("testModule")
          .addFile("assets/leftover.txt")
          .addFile("dex/classes.dex")
          .setManifest(androidManifest("com.test.app"))
          .build();

  ImmutableCollection<VariantTargeting> splits =
      nativeLibsCompressionVariantGenerator.generate(bundleModule).collect(toImmutableList());
  assertThat(splits).isEmpty();
}
 
@Test
public void nativeCompressionSplitter_withM_withLibsWithoutExternalStorage() throws Exception {
  NativeLibrariesCompressionSplitter nativeLibrariesCompressionSplitter =
      new NativeLibrariesCompressionSplitter();
  ImmutableCollection<ModuleSplit> splits =
      nativeLibrariesCompressionSplitter.split(
          ModuleSplit.forNativeLibraries(
              createSingleLibraryModule("testModule", "x86", "lib/x86/libnoname.so"),
              variantSdkTargeting(ANDROID_M_API_VERSION)));

  assertThat(splits).hasSize(1);
  ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);

  assertThat(moduleSplit.getVariantTargeting())
      .isEqualTo(variantSdkTargeting(ANDROID_M_API_VERSION));

  assertThat(extractPaths(moduleSplit.getEntries())).containsExactly("lib/x86/libnoname.so");
  assertThat(moduleSplit.isMasterSplit()).isTrue();
  assertThat(getForceUncompressed(moduleSplit, "lib/x86/libnoname.so")).isTrue();
  assertThat(moduleSplit.getApkTargeting()).isEqualToDefaultInstance();
  assertThat(
          compareManifestMutators(
              moduleSplit.getMasterManifestMutators(), withExtractNativeLibs(false)))
      .isTrue();
}
 
@Test
public void nativeCompressionSplitter_withM_withNativeActivities() throws Exception {
  NativeLibrariesCompressionSplitter nativeLibrariesCompressionSplitter =
      new NativeLibrariesCompressionSplitter();
  ImmutableCollection<ModuleSplit> splits =
      nativeLibrariesCompressionSplitter.split(
          ModuleSplit.forNativeLibraries(
              createSingleLibraryModule(
                  "testModule", "x86", "lib/x86/libnoname.so", withNativeActivity("noname")),
              variantSdkTargeting(ANDROID_M_API_VERSION)));

  assertThat(splits).hasSize(1);
  ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);

  assertThat(moduleSplit.getVariantTargeting())
      .isEqualTo(variantSdkTargeting(ANDROID_M_API_VERSION));

  assertThat(extractPaths(moduleSplit.getEntries())).containsExactly("lib/x86/libnoname.so");
  assertThat(moduleSplit.isMasterSplit()).isTrue();
  assertThat(getForceUncompressed(moduleSplit, "lib/x86/libnoname.so")).isFalse();
  assertThat(moduleSplit.getApkTargeting()).isEqualToDefaultInstance();
}
 
源代码17 项目: buck   文件: ExecutableFinder.java
public Optional<Path> getOptionalExecutable(
    Path suggestedExecutable,
    ImmutableCollection<Path> path,
    ImmutableCollection<String> fileSuffixes) {

  // Fast path out of here.
  if (isExecutable(suggestedExecutable)) {
    return Optional.of(suggestedExecutable);
  }

  Optional<Path> executable =
      FileFinder.getOptionalFile(
          FileFinder.combine(
              /* prefixes */ null,
              suggestedExecutable.toString(),
              ImmutableSet.copyOf(fileSuffixes)),
          path,
          ExecutableFinder::isExecutable);
  LOG.debug("Executable '%s' mapped to '%s'", suggestedExecutable, executable);

  return executable;
}
 
源代码18 项目: buck   文件: HaskellGhciDescription.java
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractHaskellGhciDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {

  HaskellDescriptionUtils.getParseTimeDeps(
      buildTarget.getTargetConfiguration(),
      ImmutableList.of(getPlatform(buildTarget, constructorArg)),
      targetGraphOnlyDepsBuilder);

  constructorArg
      .getDepsQuery()
      .ifPresent(
          depsQuery ->
              QueryUtils.extractParseTimeTargets(buildTarget, cellRoots, depsQuery)
                  .forEach(targetGraphOnlyDepsBuilder::add));
}
 
源代码19 项目: buck   文件: ScalaTestDescription.java
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractScalaTestDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  extraDepsBuilder.add(config.getScalaLibraryTarget(buildTarget.getTargetConfiguration()));
  Optionals.addIfPresent(
      config.getScalacTarget(buildTarget.getTargetConfiguration()), extraDepsBuilder);
  javaOptionsForTests
      .apply(buildTarget.getTargetConfiguration())
      .addParseTimeDeps(targetGraphOnlyDepsBuilder, buildTarget.getTargetConfiguration());
  javacFactory.addParseTimeDeps(
      targetGraphOnlyDepsBuilder, constructorArg, buildTarget.getTargetConfiguration());
}
 
@Test
public void splittingByCompression_preM_instantModule() throws Exception {
  NativeLibrariesCompressionSplitter nativeLibrariesCompressionSplitter =
      new NativeLibrariesCompressionSplitter(
          ApkGenerationConfiguration.builder().setForInstantAppVariants(true).build());

  ImmutableCollection<ModuleSplit> splits =
      nativeLibrariesCompressionSplitter.split(
          ModuleSplit.forNativeLibraries(
              createSingleLibraryModule("testModule", "x86", "lib/x86/libnoname.so"),
              lPlusVariantTargeting()));

  assertThat(splits).hasSize(1);

  ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);

  assertThat(moduleSplit.getVariantTargeting()).isEqualTo(lPlusVariantTargeting());
  assertThat(extractPaths(moduleSplit.getEntries())).containsExactly("lib/x86/libnoname.so");
  assertThat(moduleSplit.isMasterSplit()).isTrue();
  assertThat(moduleSplit.getApkTargeting()).isEqualToDefaultInstance();
  assertThat(getForceUncompressed(moduleSplit, "lib/x86/libnoname.so")).isTrue();
  assertThat(
          compareManifestMutators(
              moduleSplit.getMasterManifestMutators(), withExtractNativeLibs(false)))
      .isTrue();
}
 
源代码21 项目: joda-collect   文件: DenseImmutableGrid.java
@Override
@SuppressWarnings("unchecked")
public ImmutableCollection<V> values() {
    Object[] array = new Object[size];
    int index = 0;
    for (Object object : values) {
        if (object != null) {
            array[index++] = object;
        }
    }
    return ImmutableList.copyOf((V[]) array);
}
 
@Override
protected ImmutableCollection<T> doDeserialize( JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params ) {
    try {
        currentBuilder = ImmutableList.builder();
        buildCollection( reader, ctx, params );
        return currentBuilder.build();
    } finally {
        currentBuilder = null;
    }
}
 
源代码23 项目: bazel   文件: Expander.java
/**
 * Returns a new instance that also expands locations, passing the given location map, as well as
 * {@code execPaths} to the underlying {@link LocationTemplateContext}.
 */
public Expander withExecLocations(
    ImmutableMap<Label, ImmutableCollection<Artifact>> locations, boolean windowsPath) {
  TemplateContext newTemplateContext =
      new LocationTemplateContext(
          templateContext, ruleContext, locations, true, false, windowsPath);
  return new Expander(ruleContext, newTemplateContext, labelMap, lookedUpVariables);
}
 
@java.lang.SuppressWarnings("all")
protected SingularGuavaCollection(final SingularGuavaCollectionBuilder<T, ?, ?> b) {
  com.google.common.collect.ImmutableCollection<java.lang.Object> rawTypes = b.rawTypes == null ? com.google.common.collect.ImmutableList.<java.lang.Object>of() : b.rawTypes.build();
  this.rawTypes = rawTypes;
  com.google.common.collect.ImmutableCollection<Integer> integers = b.integers == null ? com.google.common.collect.ImmutableList.<Integer>of() : b.integers.build();
  this.integers = integers;
  com.google.common.collect.ImmutableCollection<T> generics = b.generics == null ? com.google.common.collect.ImmutableList.<T>of() : b.generics.build();
  this.generics = generics;
  com.google.common.collect.ImmutableCollection<Number> extendsGenerics = b.extendsGenerics == null ? com.google.common.collect.ImmutableList.<Number>of() : b.extendsGenerics.build();
  this.extendsGenerics = extendsGenerics;
}
 
源代码25 项目: Velocity   文件: QueryResponse.java
@VisibleForTesting
QueryResponse(String hostname, String gameVersion, String map, int currentPlayers,
    int maxPlayers, String proxyHost, int proxyPort, ImmutableCollection<String> players,
    String proxyVersion, ImmutableCollection<PluginInformation> plugins) {
  this.hostname = hostname;
  this.gameVersion = gameVersion;
  this.map = map;
  this.currentPlayers = currentPlayers;
  this.maxPlayers = maxPlayers;
  this.proxyHost = proxyHost;
  this.proxyPort = proxyPort;
  this.players = players;
  this.proxyVersion = proxyVersion;
  this.plugins = plugins;
}
 
@java.lang.SuppressWarnings("all")
public SingularGuavaCollection<T> build() {
  com.google.common.collect.ImmutableCollection<java.lang.Object> rawTypes = this.rawTypes == null ? com.google.common.collect.ImmutableList.<java.lang.Object>of() : this.rawTypes.build();
  com.google.common.collect.ImmutableCollection<Integer> integers = this.integers == null ? com.google.common.collect.ImmutableList.<Integer>of() : this.integers.build();
  com.google.common.collect.ImmutableCollection<T> generics = this.generics == null ? com.google.common.collect.ImmutableList.<T>of() : this.generics.build();
  com.google.common.collect.ImmutableCollection<Number> extendsGenerics = this.extendsGenerics == null ? com.google.common.collect.ImmutableList.<Number>of() : this.extendsGenerics.build();
  return new SingularGuavaCollection<T>(rawTypes, integers, generics, extendsGenerics);
}
 
@Override
protected void setDimensionAlternatives(
    VariantTargeting.Builder targetingBuilder, ImmutableCollection<SdkVersion> alternatives) {
  targetingBuilder
      .getSdkVersionTargetingBuilder()
      .clearAlternatives()
      .addAllAlternatives(alternatives);
}
 
源代码28 项目: buck   文件: UnresolvedInferPlatform.java
/** Helper method to add parse-time deps to target graph for nullsafe flavored targets. */
static void addParseTimeDepsToInferFlavored(
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder,
    BuildTarget buildTarget,
    UnresolvedInferPlatform platform) {
  if (buildTarget.getFlavors().contains(InferNullsafe.INFER_NULLSAFE)) {
    targetGraphOnlyDepsBuilder.addAll(
        platform.getParseTimeDeps(buildTarget.getTargetConfiguration()));
  }
}
 
源代码29 项目: bundletool   文件: EntryCompressionPreprocessor.java
@CheckReturnValue
private static ImmutableList<BundleModule> setEntryCompression(
    ImmutableCollection<BundleModule> modules) {
  return modules.stream()
      .map(EntryCompressionPreprocessor::setEntryCompression)
      .collect(toImmutableList());
}
 
private static ImmutableCollection<ModuleEntry> processEntries(
    ImmutableCollection<ModuleEntry> entries,
    ImmutableCollection<TargetedNativeDirectory> targeted64BitNativeDirectories) {
  return entries.stream()
      .filter(entry -> shouldIncludeEntry(entry, targeted64BitNativeDirectories))
      .collect(toImmutableList());
}
 
 同包方法