Java Code Examples for com.google.common.base.Predicates#compose()

The following examples show how to use com.google.common.base.Predicates#compose() . 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: RuleClass.java    From bazel with Apache License 2.0 5 votes vote down vote up
@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.");
  }
}
 
Example 2
Source File: ReadOnlySchedulerImpl.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private Map<IJobKey, IJobConfiguration> getJobs(
    Optional<String> ownerRole,
    Multimap<IJobKey, IScheduledTask> tasks) {

  // We need to synthesize the JobConfiguration from the the current tasks because the
  // ImmediateJobManager doesn't store jobs directly and ImmediateJobManager#getJobs always
  // returns an empty Collection.
  Map<IJobKey, IJobConfiguration> jobs = Maps.newHashMap();

  jobs.putAll(Maps.transformEntries(tasks.asMap(),
      (jobKey, tasks1) -> {

        // Pick the latest transitioned task for each immediate job since the job can be in the
        // middle of an update or some shards have been selectively created.
        TaskConfig mostRecentTaskConfig =
            Tasks.getLatestActiveTask(tasks1).getAssignedTask().getTask().newBuilder();

        return IJobConfiguration.build(new JobConfiguration()
            .setKey(jobKey.newBuilder())
            .setOwner(mostRecentTaskConfig.getOwner())
            .setTaskConfig(mostRecentTaskConfig)
            .setInstanceCount(tasks1.size()));
      }));

  // Get cron jobs directly from the manager. Do this after querying the task store so the real
  // template JobConfiguration for a cron job will overwrite the synthesized one that could have
  // been created above.
  Predicate<IJobConfiguration> configFilter = ownerRole.isPresent()
      ? Predicates.compose(Predicates.equalTo(ownerRole.get()), JobKeys::getRole)
      : Predicates.alwaysTrue();
  jobs.putAll(Maps.uniqueIndex(
      FluentIterable.from(Storage.Util.fetchCronJobs(storage)).filter(configFilter),
      IJobConfiguration::getKey));

  return jobs;
}
 
Example 3
Source File: TargetingDimensionMatcher.java    From bundletool with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a convenient predicate on {@link ApkTargeting} message.
 */
public Predicate<ApkTargeting> getApkTargetingPredicate() {
  return Predicates.compose(this::matchesTargeting, this::getTargetingValue);
}
 
Example 4
Source File: CollectionFunctionals.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static Predicate<Iterable<?>> sizeEquals(int targetSize) {
    return Predicates.compose(Predicates.equalTo(targetSize), CollectionFunctionals.sizeFunction());
}
 
Example 5
Source File: CollectionFunctionals.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static <K> Predicate<Map<K,?>> mapSizeEquals(int targetSize) {
    return Predicates.compose(Predicates.equalTo(targetSize), CollectionFunctionals.<K>mapSize());
}
 
Example 6
Source File: ZipEntryPredicates.java    From bazel with Apache License 2.0 4 votes vote down vote up
public static Predicate<ZipEntry> classFileFilter(final ImmutableSet<String> classFileNames) {
  return Predicates.compose(classFileNameFilter(classFileNames), zipEntry -> zipEntry.getName());
}
 
Example 7
Source File: StateMachine.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private static <T> Predicate<Transition<T>> oneSideFilter(
    Function<Transition<T>, T> extractor, final T... states) {
  checkArgument(Iterables.all(Arrays.asList(states), Predicates.notNull()));

  return Predicates.compose(Predicates.in(ImmutableSet.copyOf(states)), extractor);
}
 
Example 8
Source File: TargetingDimensionMatcher.java    From bundletool with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a convenient predicate on {@link ModuleTargeting}.
 *
 * <p>As this is used to determine if a conditional module should be installed, the device
 * incompatibility safety checks are not performed. Should this happen, the module will simply
 * fail the matching.
 */
public Predicate<ModuleTargeting> getModuleTargetingPredicate() {
  return Predicates.compose(this::matchesTargeting, this::getTargetingValue);
}