com.google.common.collect.ImmutableCollection#isEmpty ( )源码实例Demo

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

源代码1 项目: copybara   文件: RestoreOriginalAuthor.java
@Override
public void transform(TransformWork work)
    throws IOException, ValidationException {
  Author author = null;
  // If multiple commits are included (for example on a squash for skipping a bad change),
  // last author wins.
  for (Change<?> change : work.getChanges().getCurrent()) {
    ImmutableCollection<String> labelValue = change.getLabels().get(label);
    if (!labelValue.isEmpty()) {
      try {
        author = Author.parse(Iterables.getLast(labelValue));
      } catch (EvalException e) {
        // Don't fail the migration because the label is wrong since it is very
        // difficult for a user to recover from this.
        work.getConsole().warn("Cannot restore original author: " + e.getMessage());
      }
    }
    if (!searchAllChanges) {
      break;
    }
  }
  if (author != null) {
    work.setAuthor(author);
    work.removeLabel(label, /*wholeMessage=*/true);
  }
}
 
源代码2 项目: intellij   文件: ProjectTargetManagerImpl.java
@Override
@Nullable
public SyncStatus getSyncStatus(File source) {
  // TODO(brendandouglas): implement 'stale' sync state
  ImmutableCollection<TargetKey> syncedTargets =
      SourceToTargetMap.getInstance(project).getRulesForSourceFile(source);
  if (!syncedTargets.isEmpty()) {
    return syncedTargets.stream().anyMatch(t -> syncInProgress(t.getLabel()))
        ? SyncStatus.RESYNCING
        : SyncStatus.SYNCED;
  }
  Label label = WorkspaceHelper.getBuildLabel(project, source);
  if (label == null) {
    // can't find a parent BUILD package
    return null;
  }

  // we don't know which target covers this source without a blaze query. Instead, just check if
  // any target in the parent package is currently being synced
  if (inProgressBuilds.values().stream()
      .map(s -> s.targets)
      .anyMatch(list -> list.includesAnyTargetInPackage(label.blazePackage()))) {
    return SyncStatus.IN_PROGRESS;
  }
  return SyncStatus.UNSYNCED;
}
 
源代码3 项目: java-n-IDE-for-Android   文件: JavaInput.java
/**
 * Convert from an offset and length flag pair to a token range.
 *
 * @param offset the {@code 0}-based offset in characters
 * @param length the length in characters
 * @return the {@code 0}-based {@link Range} of tokens
 * @throws FormatterException
 */
Range<Integer> characterRangeToTokenRange(int offset, int length) throws FormatterException {
    int requiredLength = offset + length;
    if (requiredLength > text.length()) {
        throw new FormatterException(
                String.format(
                        "error: invalid length %d, offset + length (%d) is outside the file",
                        length, requiredLength));
    }
    if (length < 0) {
        return EMPTY_RANGE;
    }
    if (length == 0) {
        // 0 stands for "format the line under the cursor"
        length = 1;
    }
    ImmutableCollection<Token> enclosed =
            getPositionTokenMap()
                    .subRangeMap(Range.closedOpen(offset, offset + length))
                    .asMapOfRanges()
                    .values();
    if (enclosed.isEmpty()) {
        return EMPTY_RANGE;
    }
    return Range.closedOpen(
            enclosed.iterator().next().getTok().getIndex(), getLast(enclosed).getTok().getIndex() + 1);
}
 
源代码4 项目: javaide   文件: JavaInput.java
/**
 * Convert from an offset and length flag pair to a token range.
 *
 * @param offset the {@code 0}-based offset in characters
 * @param length the length in characters
 * @return the {@code 0}-based {@link Range} of tokens
 * @throws FormatterException
 */
Range<Integer> characterRangeToTokenRange(int offset, int length) throws FormatterException {
    int requiredLength = offset + length;
    if (requiredLength > text.length()) {
        throw new FormatterException(
                String.format(
                        "error: invalid length %d, offset + length (%d) is outside the file",
                        length, requiredLength));
    }
    if (length < 0) {
        return EMPTY_RANGE;
    }
    if (length == 0) {
        // 0 stands for "format the line under the cursor"
        length = 1;
    }
    ImmutableCollection<Token> enclosed =
            getPositionTokenMap()
                    .subRangeMap(Range.closedOpen(offset, offset + length))
                    .asMapOfRanges()
                    .values();
    if (enclosed.isEmpty()) {
        return EMPTY_RANGE;
    }
    return Range.closedOpen(
            enclosed.iterator().next().getTok().getIndex(), getLast(enclosed).getTok().getIndex() + 1);
}
 
源代码5 项目: codebuff   文件: CollectionFuture.java
CollectionFutureRunningState(
  ImmutableCollection<? extends ListenableFuture<? extends V>> futures,
  boolean allMustSucceed) {
  super(futures, allMustSucceed, true);
  this.values =
    futures.isEmpty()
      ? ImmutableList.<Optional<V>>of()
      : Lists.<Optional<V>>newArrayListWithCapacity(futures.size());

  // Populate the results list with null initially.
  for (int i = 0; i < futures.size(); ++i) {
    values.add(null);
  }
}
 
源代码6 项目: codebuff   文件: CollectionFuture.java
CollectionFutureRunningState(
  ImmutableCollection<? extends ListenableFuture<? extends V>> futures,
  boolean allMustSucceed) {
  super(futures, allMustSucceed, true);
  this.values =
    futures.isEmpty()
      ? ImmutableList.<Optional<V>>of()
      : Lists.<Optional<V>>newArrayListWithCapacity(futures.size());

  // Populate the results list with null initially.
  for (int i = 0; i < futures.size(); ++i) {
    values.add(null);
  }
}
 
源代码7 项目: codebuff   文件: CollectionFuture.java
CollectionFutureRunningState(
  ImmutableCollection<? extends ListenableFuture<? extends V>> futures,
  boolean allMustSucceed) {
  super(futures, allMustSucceed, true);
  this.values = futures.isEmpty()
    ? ImmutableList.<Optional<V>>of()
    : Lists.<Optional<V>>newArrayListWithCapacity(futures.size());

  // Populate the results list with null initially.
  for (int i = 0; i < futures.size(); ++i) {
    values.add(null);
  }
}
 
源代码8 项目: codebuff   文件: CollectionFuture.java
CollectionFutureRunningState(
  ImmutableCollection<? extends ListenableFuture<? extends V>> futures,
  boolean allMustSucceed) {
  super(futures, allMustSucceed, true);
  this.values =
    futures.isEmpty()
      ? ImmutableList.<Optional<V>>of()
      : Lists.<Optional<V>>newArrayListWithCapacity(futures.size());

  // Populate the results list with null initially.
  for (int i = 0; i < futures.size(); ++i) {
    values.add(null);
  }
}
 
源代码9 项目: codebuff   文件: CollectionFuture.java
CollectionFutureRunningState(
    ImmutableCollection<? extends ListenableFuture<? extends V>> futures,
    boolean allMustSucceed) {
  super(futures, allMustSucceed, true);

  this.values =
      futures.isEmpty()
          ? ImmutableList.<Optional<V>>of()
          : Lists.<Optional<V>>newArrayListWithCapacity(futures.size());

  // Populate the results list with null initially.
  for (int i = 0; i < futures.size(); ++i) {
    values.add(null);
  }
}
 
源代码10 项目: google-java-format   文件: JavaInput.java
/**
 * Convert from an offset and length flag pair to a token range.
 *
 * @param offset the {@code 0}-based offset in characters
 * @param length the length in characters
 * @return the {@code 0}-based {@link Range} of tokens
 * @throws FormatterException if offset + length is outside the file
 */
Range<Integer> characterRangeToTokenRange(int offset, int length) throws FormatterException {
  int requiredLength = offset + length;
  if (requiredLength > text.length()) {
    throw new FormatterException(
        String.format(
            "error: invalid length %d, offset + length (%d) is outside the file",
            length, requiredLength));
  }
  if (length < 0) {
    return EMPTY_RANGE;
  }
  if (length == 0) {
    // 0 stands for "format the line under the cursor"
    length = 1;
  }
  ImmutableCollection<Token> enclosed =
      getPositionTokenMap()
          .subRangeMap(Range.closedOpen(offset, offset + length))
          .asMapOfRanges()
          .values();
  if (enclosed.isEmpty()) {
    return EMPTY_RANGE;
  }
  return Range.closedOpen(
      enclosed.iterator().next().getTok().getIndex(), getLast(enclosed).getTok().getIndex() + 1);
}
 
源代码11 项目: bazel   文件: TaggedEvents.java
@VisibleForTesting
public TaggedEvents(final @Nullable String tag, ImmutableCollection<Event> events) {
  this.events =
      events.isEmpty()
          ? ImmutableList.of()
          : ImmutableList.copyOf(
              Collections2.transform(
                  events,
                  (Event e) -> e.withTag(tag)));
  this.hashCode = events.hashCode();
}
 
源代码12 项目: tac-kbp-eal   文件: StandardScoringAligner.java
@Override
public EventArgScoringAlignment<EquivClassType> align(final AnswerKey answerKey,
    final ArgumentOutput argumentOutput) {
  checkArgument(answerKey.docId() == argumentOutput.docId());
  final ImmutableMultimap<EquivClassType, Response> equivClassToSystemResponses = Multimaps.index(
      argumentOutput.responses(), equivClassFunction);
  final ImmutableMultimap<EquivClassType, AssessedResponse> equivClassToAnswerKeyResponses =
      Multimaps.index(
          answerKey.annotatedResponses(),
          Functions.compose(equivClassFunction, AssessedResponseFunctions.response()));

  final ImmutableSet<EquivClassType> allEquivClasses =
      Sets.union(equivClassToSystemResponses.keySet(),
          equivClassToAnswerKeyResponses.keySet()).immutableCopy();

  final ImmutableSet.Builder<EquivClassType> truePositives = ImmutableSet.builder();
  final ImmutableSet.Builder<EquivClassType> falsePositives = ImmutableSet.builder();
  final ImmutableSet.Builder<EquivClassType> falseNegatives = ImmutableSet.builder();
  final ImmutableSet.Builder<EquivClassType> unassessed = ImmutableSet.builder();

  for (final EquivClassType eqivClass : allEquivClasses) {
    // a key equivalence class is correct if anyone found a correct response in that class
    final ImmutableCollection<AssessedResponse> answerKeyResponsesForEC =
        equivClassToAnswerKeyResponses.get(eqivClass);
    final boolean isCorrectEquivClass = !FluentIterable.
        from(answerKeyResponsesForEC)
        .filter(AssessedResponse.IsCorrectUpToInexactJustifications)
        .isEmpty();

    final ImmutableCollection<Response> systemResponsesForEC = equivClassToSystemResponses.get(
        eqivClass);

    if (isCorrectEquivClass) {
      // only the top-scoring system response for an equivalence class counts
      final Optional<Response> selectedSystemResponse =
          argumentOutput.selectFromMultipleSystemResponses(
              equivClassToSystemResponses.get(eqivClass));

      if (selectedSystemResponse.isPresent()) {
        final Optional<AssessedResponse> assessmentOfSelectedResponse =
            AssessedResponse.findAnnotationForArgument(
                selectedSystemResponse.get(), answerKeyResponsesForEC);
        if (assessmentOfSelectedResponse.isPresent()) {
          if (assessmentOfSelectedResponse.get().isCorrectUpToInexactJustifications()) {
            truePositives.add(eqivClass);
          } else {
            // it was a correct equivalence class, but we the system response for that
            // equivalence class was incorrect (e.g. due to bad justifications).
            // This counts as both a false positive and a false negative. Note that there
            // could be a correct system response for the equivalence class which has a lower
            // confidence, but it won't count.
            falseNegatives.add(eqivClass);
            falsePositives.add(eqivClass);
          }
        } else {
          // the best system response for this equivalence class is unassessed
          unassessed.add(eqivClass);
        }
      } else {
        // it was a correct equivalence class, but we didn't find any responses
        falseNegatives.add(eqivClass);
      }
    } else {
      // if the equivalence class is incorrect, the system is wrong if it returned *any* response
      if (!systemResponsesForEC.isEmpty()) {
        falsePositives.add(eqivClass);
      } else {
        // do nothing - it was a true negative
      }
    }
  }

  return EventArgScoringAlignment
      .create(argumentOutput.docId(), argumentOutput, answerKey, truePositives.build(),
          falsePositives.build(),
          falseNegatives.build(), unassessed.build(), equivClassToAnswerKeyResponses,
          equivClassToSystemResponses);
}
 
@Override
public <T extends BuildRuleArg> BuildRule transform(
    ToolchainProvider toolchainProvider,
    TargetGraph targetGraph,
    ConfigurationRuleRegistry configurationRuleRegistry,
    ActionGraphBuilder graphBuilder,
    TargetNode<T> targetNode,
    ProviderInfoCollection providerInfoCollection,
    CellPathResolver cellPathResolver) {
  Preconditions.checkArgument(
      targetNode.getBuildTarget().getCell() == cellPathResolver.getCurrentCellName());

  BaseDescription<T> description = targetNode.getDescription();
  if (description instanceof RuleDescription) {
    RuleAnalysisResult result =
        ruleAnalysisComputation.get(RuleAnalysisKey.of(targetNode.getBuildTarget()));

    // TODO(bobyf): add support for multiple actions from a rule
    ImmutableCollection<ActionAnalysisData> actions = result.getRegisteredActions().values();

    Optional<Action> correspondingAction;
    if (actions.isEmpty()) {
      correspondingAction = Optional.empty();
    } else {
      correspondingAction =
          Optional.of(((ActionWrapperData) Iterables.getOnlyElement(actions)).getAction());
    }

    ProviderInfoCollection providerInfos = result.getProviderInfos();
    String ruleName = getRuleName(description, targetNode.getConstructorArg());
    return providerInfos
        .get(TestInfo.PROVIDER)
        .<BuildRule>map(
            testInfo ->
                new RuleAnalysisLegacyTestBuildRuleView(
                    ruleName,
                    result.getBuildTarget(),
                    correspondingAction,
                    graphBuilder,
                    targetNode.getFilesystem(),
                    providerInfos))
        .orElseGet(
            () ->
                providerInfos
                    .get(RunInfo.PROVIDER)
                    .<BuildRule>map(
                        runInfo ->
                            new RuleAnalysisLegacyBinaryBuildRuleView(
                                ruleName,
                                result.getBuildTarget(),
                                correspondingAction,
                                graphBuilder,
                                targetNode.getFilesystem(),
                                providerInfos))
                    .orElseGet(
                        () ->
                            new RuleAnalysisLegacyBuildRuleView(
                                ruleName,
                                result.getBuildTarget(),
                                correspondingAction,
                                graphBuilder,
                                targetNode.getFilesystem(),
                                providerInfos)));
  }

  return delegate.transform(
      toolchainProvider,
      targetGraph,
      configurationRuleRegistry,
      graphBuilder,
      targetNode,
      providerInfoCollection,
      cellPathResolver);
}
 
源代码14 项目: docker-client   文件: DockerConfigReader.java
/**
 * Return a single RegistryAuth from the config file.
 * If there are multiple RegistryAuth entries, which entry is returned from this method
 * depends on hashing and should not be considered reliable.
 * If there is only one entry, however, that will be the one returned. This is the
 * primary use of this method, as a useful way to extract a RegistryAuth during testing.
 * In that environment, the contents of the config file are known and controlled. In a
 * production environment, the contents of the config file are less predictable.
 *
 * @param configPath Path to the docker config file.
 * @return Some registry auth value.
 */
@VisibleForTesting
RegistryAuth anyRegistryAuth(final Path configPath) throws IOException {
  final ImmutableCollection<RegistryAuth> registryAuths =
      authForAllRegistries(configPath).configs().values();
  return registryAuths.isEmpty()
      ? RegistryAuth.builder().build()
      : registryAuths.iterator().next();
}