/** * 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())); }
/** * 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); }
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; }
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; }
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; }
@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); }
@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); } }); }
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); }
@NonNull Set<WiFiDetail> getNewSeries(@NonNull List<WiFiDetail> wiFiDetails, @NonNull Pair<WiFiChannel, WiFiChannel> wiFiChannelPair) { return new TreeSet<>(CollectionUtils.select(wiFiDetails, new InRangePredicate(wiFiChannelPair))); }
@NonNull private List<WiFiDetail> collectOverlapping(@NonNull WiFiChannel wiFiChannel) { return new ArrayList<>(CollectionUtils.select(wiFiDetails, new InRangePredicate(wiFiChannel))); }
@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); }
@NonNull Set<WiFiDetail> active() { return new HashSet<>(CollectionUtils.select(notSeen.keySet(), new SeenPredicate())); }
@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; }
@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)); }
@Override public void setValues(@NonNull Set<String> values) { super.setValues(new HashSet<>(CollectionUtils.select(values, new SSIDPredicate()))); }
@Override public Collection<OccurrenceIF> getOccurrences(String value, final TopicIF occurrenceType) { return CollectionUtils.select(extractExactValues(occurs, value), new TypedPredicate(occurrenceType)); }
@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; }
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())); }
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)); }
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)); }