org.apache.commons.collections4.CollectionUtils.select()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.apache.commons.collections4.CollectionUtils.select()方法的一些代码示例,展示了CollectionUtils.select()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.select()方法的具体详情如下:
包路径:org.apache.commons.collections4.CollectionUtils
类名称:CollectionUtils
方法名:select

CollectionUtils.select介绍

[英]Selects all elements from input collection which match the given predicate into an output collection.

A null predicate matches no elements.
[中]将输入集合中与给定谓词匹配的所有元素选择到输出集合中。
null谓词不匹配任何元素。

代码示例

代码示例来源:origin: org.apache.commons/commons-collections4

/**
 * Selects all elements from input collection which match the given
 * predicate into an output list.
 * <p>
 * A <code>null</code> predicate matches no elements.
 *
 * @param <E> the element type
 * @param inputCollection  the collection to get the input from, may not be null
 * @param predicate  the predicate to use, may be null
 * @return the elements matching the predicate (new list)
 * @throws NullPointerException if the input list is null
 *
 * @since 4.0
 * @see CollectionUtils#select(Iterable, Predicate)
 */
public static <E> List<E> select(final Collection<? extends E> inputCollection,
    final Predicate<? super E> predicate) {
  return CollectionUtils.select(inputCollection, predicate, new ArrayList<E>(inputCollection.size()));
}

代码示例来源:origin: org.apache.commons/commons-collections4

/**
 * Selects all elements from input collection which match the given
 * predicate into an output collection.
 * <p>
 * A <code>null</code> predicate matches no elements.
 *
 * @param <O>  the type of object the {@link Iterable} contains
 * @param inputCollection  the collection to get the input from, may not be null
 * @param predicate  the predicate to use, may be null
 * @return the elements matching the predicate (new list)
 * @throws NullPointerException if the input collection is null
 */
public static <O> Collection<O> select(final Iterable<? extends O> inputCollection,
                    final Predicate<? super O> predicate) {
  final Collection<O> answer = inputCollection instanceof Collection<?> ?
      new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>();
  return select(inputCollection, predicate, answer);
}

代码示例来源:origin: gocd/gocd

private Collection<StageIdFaninScmMaterialPair> findScmRevisionsThatDiffer(List<StageIdFaninScmMaterialPair> pIdScmMaterialList) {
  for (final StageIdFaninScmMaterialPair pIdScmPair : pIdScmMaterialList) {
    final Collection<StageIdFaninScmMaterialPair> matWithSameFingerprint = CollectionUtils.select(pIdScmMaterialList, pIdScmPair::equals);
    boolean diffRevFound = false;
    for (StageIdFaninScmMaterialPair pair : matWithSameFingerprint) {
      if (pair.stageIdentifier == pIdScmPair.stageIdentifier) {
        continue;
      }
      if (pair.faninScmMaterial.revision.equals(pIdScmPair.faninScmMaterial.revision)) {
        continue;
      }
      diffRevFound = true;
      break;
    }
    if (diffRevFound) {
      return matWithSameFingerprint;
    }
  }
  return Collections.EMPTY_LIST;
}

代码示例来源:origin: gocd/gocd

private boolean validateAllScmRevisionsAreSameWithinAFingerprint(Pair<StageIdentifier, List<ReportingFaninScmMaterial>> pIdScmPair) {
  if (pIdScmPair == null) {
    return false;
  }
  List<ReportingFaninScmMaterial> scmMaterialList = pIdScmPair.last();
  for (final ReportingFaninScmMaterial scmMaterial : scmMaterialList) {
    Collection<ReportingFaninScmMaterial> scmMaterialOfSameFingerprint = CollectionUtils.select(scmMaterialList, scmMaterial::equals);
    for (ReportingFaninScmMaterial faninScmMaterial : scmMaterialOfSameFingerprint) {
      if (!faninScmMaterial.revision.equals(scmMaterial.revision)) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: gocd/gocd

private List<String> pmrModificationsKey(Modification modification, List<PipelineMaterialRevision> pmrs) {
  final long id = modification.getId();
  final MaterialInstance materialInstance = modification.getMaterialInstance();
  Collection<PipelineMaterialRevision> matchedPmrs = CollectionUtils.select(pmrs, pmr -> {
    long from = pmr.getFromModification().getId();
    long to = pmr.getToModification().getId();
    MaterialInstance pmi = findMaterialInstance(pmr.getMaterial());
    return from <= id && id <= to && materialInstance.equals(pmi);
  });
  List<String> keys = new ArrayList<>(matchedPmrs.size());
  for (PipelineMaterialRevision matchedPmr : matchedPmrs) {
    keys.add(pmrModificationsKey(matchedPmr));
  }
  return keys;
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
public static <T extends Enum> T find(@NonNull Class<T> enumType, @NonNull Predicate<T> predicate, @NonNull T defaultValue) {
  List<T> results = new ArrayList<>(CollectionUtils.select(values(enumType), predicate));
  return results.isEmpty() ? defaultValue : results.get(0);
}

代码示例来源:origin: ontopia/ontopia

@Override
public Collection<VariantNameIF> getVariants(String value, final LocatorIF datatype) {
 return CollectionUtils.select(extractExactValues(variants, value), new Predicate<VariantNameIF>() {
  @Override
  public boolean evaluate(VariantNameIF vn) {
   return Objects.equals(vn.getDataType(), datatype);
  }
 });
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

void update(@NonNull WiFiData wiFiData) {
  Collection<Pair<WiFiChannel, WiFiChannel>> visible = CollectionUtils.select(ids.keySet(), new PairPredicate());
  updateButtons(wiFiData, visible);
  view.setVisibility(visible.size() > 1 ? View.VISIBLE : View.GONE);
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
Set<WiFiDetail> getNewSeries(@NonNull List<WiFiDetail> wiFiDetails, @NonNull Pair<WiFiChannel, WiFiChannel> wiFiChannelPair) {
  return new TreeSet<>(CollectionUtils.select(wiFiDetails, new InRangePredicate(wiFiChannelPair)));
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
private List<WiFiDetail> collectOverlapping(@NonNull WiFiChannel wiFiChannel) {
  return new ArrayList<>(CollectionUtils.select(wiFiDetails, new InRangePredicate(wiFiChannel)));
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
private List<WiFiDetail> getWiFiDetails(@NonNull Predicate<WiFiDetail> predicate) {
  Collection<WiFiDetail> selected = CollectionUtils.select(wiFiDetails, predicate);
  Collection<WiFiDetail> collected = CollectionUtils.collect(selected, new Transform());
  return new ArrayList<>(collected);
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
Set<WiFiDetail> active() {
  return new HashSet<>(CollectionUtils.select(notSeen.keySet(), new SeenPredicate()));
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
List<BaseSeries<DataPoint>> remove(@NonNull List<WiFiDetail> series) {
  List<BaseSeries<DataPoint>> removeSeries = new ArrayList<>();
  IterableUtils.forEach(CollectionUtils.select(series, new RemovePredicate()), new RemoveClosure(removeSeries));
  return removeSeries;
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
@Override
public List<String> findVendors(@NonNull String filter) {
  Predicate<String> predicate =
    PredicateUtils.anyPredicate(new StringContains(filter), new MacContains(filter));
  return new ArrayList<>(CollectionUtils.select(getVendors().keySet(), predicate));
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@Override
public void setValues(@NonNull Set<String> values) {
  super.setValues(new HashSet<>(CollectionUtils.select(values, new SSIDPredicate())));
}

代码示例来源:origin: ontopia/ontopia

@Override
public Collection<OccurrenceIF> getOccurrences(String value, final TopicIF occurrenceType) {
 return CollectionUtils.select(extractExactValues(occurs, value), new TypedPredicate(occurrenceType));
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@NonNull
public List<ChannelAPCount> getBestChannels(@NonNull final List<WiFiChannel> wiFiChannels) {
  List<ChannelAPCount> results = new ArrayList<>(
    CollectionUtils.collect(
      CollectionUtils.select(wiFiChannels, new BestChannelPredicate())
      , new ToChannelAPCount()));
  Collections.sort(results, new ChannelAPCountSort());
  return results;
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

private FilterPredicate(@NonNull Settings settings, @NonNull Set<WiFiBand> wiFiBands) {
  Predicate<WiFiDetail> ssidPredicate = makeSSIDPredicate(settings.getSSIDs());
  Predicate<WiFiDetail> wiFiBandPredicate = EnumUtils.predicate(WiFiBand.class, wiFiBands, new WiFiBandTransformer());
  Predicate<WiFiDetail> strengthPredicate = EnumUtils.predicate(Strength.class, settings.getStrengths(), new StrengthTransformer());
  Predicate<WiFiDetail> securityPredicate = EnumUtils.predicate(Security.class, settings.getSecurities(), new SecurityTransformer());
  List<Predicate<WiFiDetail>> predicates = Arrays.asList(ssidPredicate, wiFiBandPredicate, strengthPredicate, securityPredicate);
  this.predicate = PredicateUtils.allPredicate(CollectionUtils.select(predicates, new NoTruePredicate()));
}

代码示例来源:origin: com.github.rvesse/airline

private <T> Collection<OptionMetadata> getTaggedOptions(ParseState<T> state) {
  List<OptionMetadata> options = state.getCommand() != null ? state.getCommand().getAllOptions() : null;
  if (options == null)
    options = state.getGroup() != null ? state.getGroup().getOptions() : null;
  if (options == null)
    options = state.getGlobal() != null ? state.getGlobal().getOptions()
        : Collections.<OptionMetadata> emptyList();
  return CollectionUtils.select(options, new RequiredTagOptionFinder(this.tag));
}

代码示例来源:origin: com.github.rvesse/airline

private <T> Collection<OptionMetadata> getTaggedOptions(ParseState<T> state) {
  List<OptionMetadata> options = state.getCommand() != null ? state.getCommand().getAllOptions() : null;
  if (options == null)
    options = state.getGroup() != null ? state.getGroup().getOptions() : null;
  if (options == null)
    options = state.getGlobal() != null ? state.getGlobal().getOptions()
        : Collections.<OptionMetadata> emptyList();
  return CollectionUtils.select(options, new MutuallyExclusiveWithOptionFinder(this.tag));
}

相关文章