com.google.common.base.Equivalence.Wrapper Java Examples

The following examples show how to use com.google.common.base.Equivalence.Wrapper. 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: MemoizeExtension.java    From auto with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #2
Source File: DatastoreBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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());
}
 
Example #3
Source File: Util.java    From dagger2-sample with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: Util.java    From dagger2-sample with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #5
Source File: OrientBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@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;
}