类com.google.common.base.Equivalence.Wrapper源码实例Demo

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

源代码1 项目: auto   文件: MemoizeExtension.java
/**
 * Returns the contents of the {@code AutoValue.CopyAnnotations.exclude} element, as a set of
 * {@code TypeMirror} where each type is an annotation type.
 */
// TODO(b/122509249): Move code copied from com.google.auto.value.processor to auto-common.
private ImmutableSet<TypeMirror> getExcludedAnnotationTypes(Element element) {
  Optional<AnnotationMirror> maybeAnnotation =
      getAnnotationMirror(element, COPY_ANNOTATIONS_NAME);
  if (!maybeAnnotation.isPresent()) {
    return ImmutableSet.of();
  }

  @SuppressWarnings("unchecked")
  List<AnnotationValue> excludedClasses =
      (List<AnnotationValue>) getAnnotationValue(maybeAnnotation.get(), "exclude").getValue();
  return excludedClasses.stream()
      .map(
          annotationValue ->
              MoreTypes.equivalence().wrap((TypeMirror) annotationValue.getValue()))
      // TODO(b/122509249): Move TypeMirrorSet to common package instead of doing this.
      .distinct()
      .map(Wrapper::get)
      .collect(toImmutableSet());
}
 
private List<BrowseNode<Integer>> fetchPermittedNodes(final Repository repository,
                                             final long maxNodes,
                                             Function<ContentRepository, Iterable<DatastoreBrowseNode>> findChildren,
                                             Predicate<DatastoreBrowseNode> filterNodePredicate) {
  Stream<DatastoreBrowseNode> nodeStream;
  if (repository.getType() instanceof GroupType) {
    Equivalence<BrowseNode<Integer>> browseNodeIdentity = getIdentity(repository);

    // overlay member results, first-one-wins if there are any nodes with the same name
    nodeStream = members(repository)
        .map(this::getContentRepository)
        .map(findChildren)
        .flatMap(iter -> stream(iter.spliterator(), false))
        .map(browseNodeIdentity::wrap)
        .distinct()
        .map(Wrapper::get);
  }
  else {
    nodeStream = of(repository)
        .map(this::getContentRepository)
        .map(findChildren)
        .flatMap(iter -> stream(iter.spliterator(), false));
  }

  return nodeStream
      .filter(filterNodePredicate)
      .limit(maxNodes)
      .collect(toList());
}
 
源代码3 项目: dagger2-sample   文件: Util.java
/**
 * Wraps an {@link Optional} of a type in an {@code Optional} of a {@link Wrapper} for that type.
 */
static <T> Optional<Equivalence.Wrapper<T>> wrapOptionalInEquivalence(
    Equivalence<T> equivalence, Optional<T> optional) {
  return optional.isPresent()
      ? Optional.of(equivalence.wrap(optional.get()))
      : Optional.<Equivalence.Wrapper<T>>absent();
}
 
源代码4 项目: dagger2-sample   文件: Util.java
/**
 * Unwraps an {@link Optional} of a {@link Wrapper} into an {@code Optional} of the underlying
 * type.
 */
static <T> Optional<T> unwrapOptionalEquivalence(
    Optional<Equivalence.Wrapper<T>> wrappedOptional) {
  return wrappedOptional.isPresent()
      ? Optional.of(wrappedOptional.get().get())
      : Optional.<T>absent();
}
 
源代码5 项目: nexus-public   文件: OrientBrowseNodeStoreImpl.java
@Override
@Guarded(by = STARTED)
public Iterable<BrowseNode<EntityId>> getByPath(
    final String repositoryName,
    final List<String> path,
    final int maxNodes)
{
  Repository repository = repositoryManager.get(repositoryName);
  String format = repository.getFormat().getValue();

  List<SelectorConfiguration> selectors = emptyList();
  if (!hasBrowsePermission(repositoryName, format)) {
    // user doesn't have repository-wide access so need to apply content selection
    selectors = selectorManager.browseActive(asList(repositoryName), asList(format));
    if (selectors.isEmpty()) {
      return emptyList(); // no browse permission and no selectors -> no results
    }
  }

  Map<String, Object> filterParameters = new HashMap<>();
  String assetFilter = buildAssetFilter(repository, selectors, filterParameters);

  BrowseNodeFilter filter = browseNodeFilters.getOrDefault(repository.getFormat().getValue(), (node, name) -> true);

  List<BrowseNode<EntityId>> results;
  if (repository.getType() instanceof GroupType) {
    Equivalence<OrientBrowseNode> browseNodeIdentity;
    Optional<BrowseNodeFacet> browseNodeFacet = repository.optionalFacet(BrowseNodeFacet.class);
    if (browseNodeFacet.isPresent()) {
      browseNodeIdentity = Equivalence.equals()
          .onResultOf(input -> browseNodeFacet.get().browseNodeIdentity().apply(input));
    }
    else {
      browseNodeIdentity = Equivalence.equals().onResultOf(BrowseNode::getName);
    }

    // overlay member results, first-one-wins if there are any nodes with the same name
    results = members(repository)
        .map(m -> getByPath(m.getName(), path, maxNodes, assetFilter, filterParameters))
        .flatMap(List::stream)
        .map(browseNodeIdentity::wrap)
        .distinct()
        .map(Wrapper::get)
        .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName())))
        .limit(maxNodes)
        .collect(toList());
  }
  else {
    results = getByPath(repository.getName(), path, maxNodes, assetFilter, filterParameters).stream()
        .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName())))
        .collect(toList());
  }

  results.sort(getBrowseNodeComparator(format));

  return results;
}