Java Code Examples for com.google.common.collect.ImmutableSortedSet#size()

The following examples show how to use com.google.common.collect.ImmutableSortedSet#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathListing.java    From buck with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: AsyncTaskEnqueuer.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: GenruleBinary.java    From buck with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 4
Source File: PathReferenceRuleWithMultipleOutputs.java    From buck with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public SourcePath getSourcePathToOutput() {
  ImmutableSortedSet<SourcePath> sourcePaths = getSourcePathToOutput(OutputLabel.defaultLabel());
  if (sourcePaths.size() == 1) {
    return Iterables.getOnlyElement(sourcePaths);
  }
  return null;
}