com.google.common.base.Predicates#in ( )源码实例Demo

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

源代码1 项目: bazel   文件: GenQuery.java
@Nullable
private GenQueryResult executeQuery(
    RuleContext ruleContext, QueryOptions queryOptions, Collection<Label> scope, String query)
    throws InterruptedException {
  SkyFunction.Environment env = ruleContext.getAnalysisEnvironment().getSkyframeEnv();
  Pair<ImmutableMap<PackageIdentifier, Package>, ImmutableMap<Label, Target>> closureInfo;
  try {
    closureInfo = constructPackageMap(env, scope);
    if (closureInfo == null) {
      return null;
    }
  } catch (BrokenQueryScopeException e) {
    ruleContext.ruleError(e.getMessage());
    return null;
  }

  ImmutableMap<PackageIdentifier, Package> packageMap = closureInfo.first;
  ImmutableMap<Label, Target> validTargetsMap = closureInfo.second;
  PreloadedMapPackageProvider packageProvider =
      new PreloadedMapPackageProvider(packageMap, validTargetsMap);
  TargetPatternPreloader preloader = new SkyframeEnvTargetPatternEvaluator(env);
  Predicate<Label> labelFilter = Predicates.in(validTargetsMap.keySet());

  return doQuery(queryOptions, packageProvider, labelFilter, preloader, query, ruleContext);
}
 
源代码2 项目: presto   文件: TestEqualityInference.java
private static Predicate<Symbol> matchesSymbols(Collection<String> symbols)
{
    final Set<Symbol> symbolSet = symbols.stream()
            .map(Symbol::new)
            .collect(toImmutableSet());

    return Predicates.in(symbolSet);
}
 
源代码3 项目: codebuff   文件: Sets.java
/**
 * Returns an unmodifiable <b>view</b> of the intersection of two sets. The
 * returned set contains all elements that are contained by both backing sets.
 * The iteration order of the returned set matches that of {@code set1}.
 *
 * <p>Results are undefined if {@code set1} and {@code set2} are sets based
 * on different equivalence relations (as {@code HashSet}, {@code TreeSet},
 * and the keySet of an {@code IdentityHashMap} all are).
 *
 * <p><b>Note:</b> The returned view performs slightly better when {@code
 * set1} is the smaller of the two sets. If you have reason to believe one of
 * your sets will generally be smaller than the other, pass it first.
 * Unfortunately, since this method sets the generic type of the returned set
 * based on the type of the first set passed, this could in rare cases force
 * you to make a cast, for example: <pre>   {@code
 *
 *   Set<Object> aFewBadObjects = ...
 *   Set<String> manyBadStrings = ...
 *
 *   // impossible for a non-String to be in the intersection
 *   SuppressWarnings("unchecked")
 *   Set<String> badStrings = (Set) Sets.intersection(
 *       aFewBadObjects, manyBadStrings);}</pre>
 *
 * <p>This is unfortunate, but should come up only very rarely.
 */


public static <E> SetView<E> intersection(
  final Set<E> set1, final Set<?> set2) {
  checkNotNull(set1, "set1");
  checkNotNull(set2, "set2");
  final Predicate<Object> inSet2 = Predicates.in(set2);
  return new SetView<E>() {
    @Override
    public Iterator<E> iterator() {
      return Iterators.filter(set1.iterator(), inSet2);
    }

    @Override
    public int size() {
      return Iterators.size(iterator());
    }

    @Override
    public boolean isEmpty() {
      return !iterator().hasNext();
    }

    @Override
    public boolean contains(Object object) {
      return set1.contains(object) && set2.contains(object);
    }

    @Override
    public boolean containsAll(Collection<?> collection) {
      return set1.containsAll(collection) && set2.containsAll(collection);
    }
  };
}
 
源代码4 项目: codebuff   文件: Sets.java
/**
 * Returns an unmodifiable <b>view</b> of the intersection of two sets. The
 * returned set contains all elements that are contained by both backing sets.
 * The iteration order of the returned set matches that of {@code set1}.
 *
 * <p>Results are undefined if {@code set1} and {@code set2} are sets based
 * on different equivalence relations (as {@code HashSet}, {@code TreeSet},
 * and the keySet of an {@code IdentityHashMap} all are).
 *
 * <p><b>Note:</b> The returned view performs slightly better when {@code
 * set1} is the smaller of the two sets. If you have reason to believe one of
 * your sets will generally be smaller than the other, pass it first.
 * Unfortunately, since this method sets the generic type of the returned set
 * based on the type of the first set passed, this could in rare cases force
 * you to make a cast, for example: <pre>   {@code
 *
 *   Set<Object> aFewBadObjects = ...
 *   Set<String> manyBadStrings = ...
 *
 *   // impossible for a non-String to be in the intersection
 *   SuppressWarnings("unchecked")
 *   Set<String> badStrings = (Set) Sets.intersection(
 *       aFewBadObjects, manyBadStrings);}</pre>
 *
 * <p>This is unfortunate, but should come up only very rarely.
 */


public static <E> SetView<E> intersection(
  final Set<E> set1, final Set<?> set2) {
  checkNotNull(set1, "set1");
  checkNotNull(set2, "set2");
  final Predicate<Object> inSet2 = Predicates.in(set2);
  return new SetView<E>() {
    @Override
    public Iterator<E> iterator() {
      return Iterators.filter(set1.iterator(), inSet2);
    }

    @Override
    public int size() {
      return Iterators.size(iterator());
    }

    @Override
    public boolean isEmpty() {
      return !iterator().hasNext();
    }

    @Override
    public boolean contains(Object object) {
      return set1.contains(object) && set2.contains(object);
    }

    @Override
    public boolean containsAll(Collection<?> collection) {
      return set1.containsAll(collection) && set2.containsAll(collection);
    }
  };
}
 
源代码5 项目: codebuff   文件: Sets.java
/**
 * Returns an unmodifiable <b>view</b> of the intersection of two sets. The
 * returned set contains all elements that are contained by both backing sets.
 * The iteration order of the returned set matches that of {@code set1}.
 *
 * <p>Results are undefined if {@code set1} and {@code set2} are sets based
 * on different equivalence relations (as {@code HashSet}, {@code TreeSet},
 * and the keySet of an {@code IdentityHashMap} all are).
 *
 * <p><b>Note:</b> The returned view performs slightly better when {@code
 * set1} is the smaller of the two sets. If you have reason to believe one of
 * your sets will generally be smaller than the other, pass it first.
 * Unfortunately, since this method sets the generic type of the returned set
 * based on the type of the first set passed, this could in rare cases force
 * you to make a cast, for example: <pre>   {@code
 *
 *   Set<Object> aFewBadObjects = ...
 *   Set<String> manyBadStrings = ...
 *
 *   // impossible for a non-String to be in the intersection
 *   SuppressWarnings("unchecked")
 *   Set<String> badStrings = (Set) Sets.intersection(
 *       aFewBadObjects, manyBadStrings);}</pre>
 *
 * <p>This is unfortunate, but should come up only very rarely.
 */


public static <E> SetView<E> intersection(
  final Set<E> set1, final Set<?> set2) {
  checkNotNull(set1, "set1");
  checkNotNull(set2, "set2");
  final Predicate<Object> inSet2 = Predicates.in(set2);
  return new SetView<E>() {
    @Override
    public Iterator<E> iterator() {
      return Iterators.filter(set1.iterator(), inSet2);
    }

    @Override
    public int size() {
      return Iterators.size(iterator());
    }

    @Override
    public boolean isEmpty() {
      return !iterator().hasNext();
    }

    @Override
    public boolean contains(Object object) {
      return set1.contains(object) && set2.contains(object);
    }

    @Override
    public boolean containsAll(Collection<?> collection) {
      return set1.containsAll(collection) && set2.containsAll(collection);
    }
  };
}
 
源代码6 项目: codebuff   文件: Sets.java
/**
 * Returns an unmodifiable <b>view</b> of the intersection of two sets. The
 * returned set contains all elements that are contained by both backing sets.
 * The iteration order of the returned set matches that of {@code set1}.
 *
 * <p>Results are undefined if {@code set1} and {@code set2} are sets based
 * on different equivalence relations (as {@code HashSet}, {@code TreeSet},
 * and the keySet of an {@code IdentityHashMap} all are).
 *
 * <p><b>Note:</b> The returned view performs slightly better when {@code
 * set1} is the smaller of the two sets. If you have reason to believe one of
 * your sets will generally be smaller than the other, pass it first.
 * Unfortunately, since this method sets the generic type of the returned set
 * based on the type of the first set passed, this could in rare cases force
 * you to make a cast, for example: <pre>   {@code
 *
 *   Set<Object> aFewBadObjects = ...
 *   Set<String> manyBadStrings = ...
 *
 *   // impossible for a non-String to be in the intersection
 *   SuppressWarnings("unchecked")
 *   Set<String> badStrings = (Set) Sets.intersection(
 *       aFewBadObjects, manyBadStrings);}</pre>
 *
 * <p>This is unfortunate, but should come up only very rarely.
 */


public static <E> SetView<E> intersection(
  final Set<E> set1, final Set<?> set2) {
  checkNotNull(set1, "set1");
  checkNotNull(set2, "set2");
  final Predicate<Object> inSet2 = Predicates.in(set2);
  return new SetView<E>() {
    @Override
    public Iterator<E> iterator() {
      return Iterators.filter(set1.iterator(), inSet2);
    }

    @Override
    public int size() {
      return Iterators.size(iterator());
    }

    @Override
    public boolean isEmpty() {
      return !iterator().hasNext();
    }

    @Override
    public boolean contains(Object object) {
      return set1.contains(object) && set2.contains(object);
    }

    @Override
    public boolean containsAll(Collection<?> collection) {
      return set1.containsAll(collection) && set2.containsAll(collection);
    }
  };
}
 
源代码7 项目: codebuff   文件: Sets.java
/**
 * Returns an unmodifiable <b>view</b> of the intersection of two sets. The
 * returned set contains all elements that are contained by both backing sets.
 * The iteration order of the returned set matches that of {@code set1}.
 *
 * <p>Results are undefined if {@code set1} and {@code set2} are sets based
 * on different equivalence relations (as {@code HashSet}, {@code TreeSet},
 * and the keySet of an {@code IdentityHashMap} all are).
 *
 * <p><b>Note:</b> The returned view performs slightly better when {@code
 * set1} is the smaller of the two sets. If you have reason to believe one of
 * your sets will generally be smaller than the other, pass it first.
 * Unfortunately, since this method sets the generic type of the returned set
 * based on the type of the first set passed, this could in rare cases force
 * you to make a cast, for example: <pre>   {@code
 *
 *   Set<Object> aFewBadObjects = ...
 *   Set<String> manyBadStrings = ...
 *
 *   // impossible for a non-String to be in the intersection
 *   SuppressWarnings("unchecked")
 *   Set<String> badStrings = (Set) Sets.intersection(
 *       aFewBadObjects, manyBadStrings);}</pre>
 *
 * <p>This is unfortunate, but should come up only very rarely.
 */
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2) {
  checkNotNull(set1, "set1");
  checkNotNull(set2, "set2");

  final Predicate<Object> inSet2 = Predicates.in(set2);
  return new SetView<E>() {
    @Override
    public Iterator<E> iterator() {
      return Iterators.filter(set1.iterator(), inSet2);
    }

    @Override
    public int size() {
      return Iterators.size(iterator());
    }

    @Override
    public boolean isEmpty() {
      return !iterator().hasNext();
    }

    @Override
    public boolean contains(Object object) {
      return set1.contains(object) && set2.contains(object);
    }

    @Override
    public boolean containsAll(Collection<?> collection) {
      return set1.containsAll(collection) && set2.containsAll(collection);
    }
  };
}
 
源代码8 项目: tac-kbp-eal   文件: ArgumentOutput.java
public ArgumentOutput copyWithFilteredResponses(Predicate<Scored<Response>> predicate) {
  final Iterable<Scored<Response>> scoredResponses =
      Iterables.filter(scoredResponses(), predicate);
  final ImmutableSet<Response> responses = ImmutableSet.copyOf(
      transform(scoredResponses, Scoreds.<Response>itemsOnly()));
  final Predicate<Response> retainedResponse = Predicates.in(responses);
  // retain only the responses and metadata that this predicate filters
  return ArgumentOutput
      .from(docId(), scoredResponses, Maps.filterKeys(metadata, retainedResponse));
}
 
源代码9 项目: bazel   文件: RuleClass.java
@VisibleForSerialization
RuleClassNamePredicate(
    ImmutableSet<String> ruleClassNames, PredicateType predicateType, Set<?> overlappable) {
  this.ruleClassNames = ruleClassNames;
  this.predicateType = predicateType;
  this.overlappable = overlappable;

  switch (predicateType) {
    case All_EXCEPT:
      Predicate<String> containing = only(ruleClassNames).asPredicateOfRuleClassName();
      ruleClassNamePredicate =
          new DescribedPredicate<>(
              Predicates.not(containing), "all but " + containing.toString());
      ruleClassPredicate =
          new DescribedPredicate<>(
              Predicates.compose(ruleClassNamePredicate, RuleClass::getName),
              ruleClassNamePredicate.toString());
      break;
    case ONLY:
      ruleClassNamePredicate =
          new DescribedPredicate<>(
              Predicates.in(ruleClassNames), StringUtil.joinEnglishList(ruleClassNames));
      ruleClassPredicate =
          new DescribedPredicate<>(
              Predicates.compose(ruleClassNamePredicate, RuleClass::getName),
              ruleClassNamePredicate.toString());
      break;
    case UNSPECIFIED:
      ruleClassNamePredicate = Predicates.alwaysTrue();
      ruleClassPredicate = Predicates.alwaysTrue();
      break;
    default:
      // This shouldn't happen normally since the constructor is private and within this file.
      throw new IllegalArgumentException(
          "Predicate type was not specified when constructing a RuleClassNamePredicate.");
  }
}
 
源代码10 项目: bazel   文件: ProtoOutputFormatter.java
private static Predicate<String> newAttributePredicate(List<String> outputAttributes) {
  if (outputAttributes.equals(ImmutableList.of("all"))) {
    return Predicates.alwaysTrue();
  } else if (outputAttributes.isEmpty()) {
    return Predicates.alwaysFalse();
  } else {
    return Predicates.in(ImmutableSet.copyOf(outputAttributes));
  }
}
 
源代码11 项目: bazel   文件: SplitZipFilters.java
/**
 * Returns a predicate that returns true for filenames contained in the given zip file.
 */
public static Predicate<String> entriesIn(String filterZip) throws IOException {
  // Aggregate filenames into a set so Predicates.in is efficient
  ImmutableSet.Builder<String> filenames = ImmutableSet.builder();
  @SuppressWarnings("resource") // ZipIn takes ownership but isn't Closable
  ZipIn zip = new ZipIn(new FileInputStream(filterZip).getChannel(), filterZip);
  for (DirectoryEntry entry : zip.centralDirectory().list()) {
    filenames.add(entry.getFilename());
  }
  return Predicates.in(filenames.build());
}
 
源代码12 项目: emodb   文件: EmoTableAllTablesReportDAO.java
/**
 * Returns the matching table report entries for a report ID and query parameters.
 */
@Override
public Iterable<TableReportEntry> getReportEntries(String reportId, final AllTablesReportQuery query) {
    checkNotNull(reportId, "reportId");

    final String reportTable = getTableName(reportId);

    // Set up several filters based on the query attributes

    final Predicate<String> placementFilter = query.getPlacements().isEmpty()
            ? Predicates.<String>alwaysTrue()
            : Predicates.in(query.getPlacements());

    final Predicate<Boolean> droppedFilter = query.isIncludeDropped()
            ? Predicates.<Boolean>alwaysTrue()
            : Predicates.equalTo(false);

    final Predicate<Boolean> facadeFilter = query.isIncludeFacades()
            ? Predicates.<Boolean>alwaysTrue()
            : Predicates.equalTo(false);

    return new Iterable<TableReportEntry>() {
        @Override
        public Iterator<TableReportEntry> iterator() {
            return Iterators.limit(
                    Iterators.filter(
                            Iterators.transform(
                                    queryDataStoreForTableReportResults(reportTable, query),
                                    new Function<Map<String, Object>, TableReportEntry>() {
                                        @Nullable
                                        @Override
                                        public TableReportEntry apply(Map<String, Object> map) {
                                            if (Intrinsic.getId(map).startsWith("~")) {
                                                // Skip this row, it's the metadata
                                                return null;
                                            }
                                            return convertToTableReportEntry(
                                                    map, placementFilter, droppedFilter, facadeFilter);
                                        }
                                    }),
                            Predicates.notNull()
                    ),
                    query.getLimit()
            );
        }
    };
}