com.google.common.collect.ImmutableSortedSet#size ( )源码实例Demo

下面列出了com.google.common.collect.ImmutableSortedSet#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: buck   文件: PathListing.java
private static ImmutableSortedSet<Path> subSet(
    ImmutableSortedSet<Path> paths, FilterMode filterMode, int limitIndex) {
  // This doesn't copy the contents of the ImmutableSortedSet. We use it
  // as a simple way to get O(1) access to the set's contents, as otherwise
  // we would have to iterate to find the Nth element.
  ImmutableList<Path> pathsList = paths.asList();
  boolean fullSet = limitIndex == paths.size();
  switch (filterMode) {
    case INCLUDE:
      // Make sure we don't call pathsList.get(pathsList.size()).
      if (!fullSet) {
        paths = paths.headSet(pathsList.get(limitIndex));
      }
      break;
    case EXCLUDE:
      if (fullSet) {
        // Make sure we don't call pathsList.get(pathsList.size()).
        paths = ImmutableSortedSet.of();
      } else {
        paths = paths.tailSet(pathsList.get(limitIndex));
      }
      break;
  }
  return paths;
}
 
源代码2 项目: nomulus   文件: AsyncTaskEnqueuer.java
/**
 * Enqueues a task to asynchronously re-save an entity at some point(s) in the future.
 *
 * <p>Multiple re-save times are chained one after the other, i.e. any given run will re-enqueue
 * itself to run at the next time if there are remaining re-saves scheduled.
 */
public void enqueueAsyncResave(
    ImmutableObject entityToResave, DateTime now, ImmutableSortedSet<DateTime> whenToResave) {
  DateTime firstResave = whenToResave.first();
  checkArgument(isBeforeOrAt(now, firstResave), "Can't enqueue a resave to run in the past");
  Key<ImmutableObject> entityKey = Key.create(entityToResave);
  Duration etaDuration = new Duration(now, firstResave);
  if (etaDuration.isLongerThan(MAX_ASYNC_ETA)) {
    logger.atInfo().log(
        "Ignoring async re-save of %s; %s is past the ETA threshold of %s.",
        entityKey, firstResave, MAX_ASYNC_ETA);
    return;
  }
  logger.atInfo().log("Enqueuing async re-save of %s to run at %s.", entityKey, whenToResave);
  String backendHostname = appEngineServiceUtils.getServiceHostname("backend");
  TaskOptions task =
      TaskOptions.Builder.withUrl(PATH_RESAVE_ENTITY)
          .method(Method.POST)
          .header("Host", backendHostname)
          .countdownMillis(etaDuration.getMillis())
          .param(PARAM_RESOURCE_KEY, entityKey.getString())
          .param(PARAM_REQUESTED_TIME, now.toString());
  if (whenToResave.size() > 1) {
    task.param(PARAM_RESAVE_TIMES, Joiner.on(',').join(whenToResave.tailSet(firstResave, false)));
  }
  addTaskToQueueWithRetry(asyncActionsPushQueue, task);
}
 
源代码3 项目: buck   文件: GenruleBinary.java
@Override
public Tool getExecutableCommand(OutputLabel outputLabel) {
  ImmutableSortedSet<SourcePath> outputs = getSourcePathToOutput(outputLabel);
  if (outputs.size() != 1) {
    throw new HumanReadableException(
        "Unexpectedly found %d outputs for %s[%s]",
        outputs.size(), getBuildTarget().getFullyQualifiedName(), outputLabel);
  }
  return new CommandTool.Builder()
      .addArg(SourcePathArg.of(Iterables.getOnlyElement(outputs)))
      .build();
}
 
@Nullable
@Override
public SourcePath getSourcePathToOutput() {
  ImmutableSortedSet<SourcePath> sourcePaths = getSourcePathToOutput(OutputLabel.defaultLabel());
  if (sourcePaths.size() == 1) {
    return Iterables.getOnlyElement(sourcePaths);
  }
  return null;
}