Java Code Examples for org.apache.commons.collections4.CollectionUtils#select()

The following examples show how to use org.apache.commons.collections4.CollectionUtils#select() . 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: JmxConnectionHelper.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected static Collection<ObjectName> getSuitableObjectNames(final MBeanServerConnection connection,
                                                               final Class objectClass) throws IOException {
    Set<ObjectName> names = connection.queryNames(null, null);

    // find all suitable beans
    Collection<ObjectName> suitableNames = CollectionUtils.select(names, o -> {
        MBeanInfo info;
        try {
            info = connection.getMBeanInfo(o);
        } catch (Exception e) {
            throw new JmxControlException(e);
        }
        return Objects.equals(objectClass.getName(), info.getClassName());
    });

    return suitableNames;
}
 
Example 2
Source File: FanInGraph.java    From gocd with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: MaterialRepository.java    From gocd with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: PurposeStrategy.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
protected Collection<VendorPermissionWithGvl> excludedVendors(Collection<VendorPermissionWithGvl> vendorPermissions,
                                                              Purpose purpose) {
    final List<String> bidderNameExceptions = purpose.getVendorExceptions();
    return CollectionUtils.isEmpty(bidderNameExceptions)
            ? Collections.emptyList()
            : CollectionUtils.select(vendorPermissions, vendorPermission ->
            bidderNameExceptions.contains(vendorPermission.getVendorPermission().getBidderName()));
}
 
Example 5
Source File: SpecialFeaturesStrategy.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
protected Collection<VendorPermission> excludedVendors(Collection<VendorPermission> vendorPermissions,
                                                       SpecialFeature specialFeature) {
    final List<String> bidderNameExceptions = specialFeature.getVendorExceptions();
    return CollectionUtils.isEmpty(bidderNameExceptions)
            ? Collections.emptyList()
            : CollectionUtils.select(vendorPermissions, vendorPermission ->
                    bidderNameExceptions.contains(vendorPermission.getBidderName()));
}
 
Example 6
Source File: CollectionSearchTests.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void testSelect() {
    Collection<String> collection = Lists.newArrayList("2", "14", "3", "13", "43");
    MutableCollection<String> mutableCollection = FastList.newListWith("2", "14", "3", "13", "43");
    Iterable<String> iterable = collection;

    // выбрать все элементы по шаблону
    List<String> jdk = collection.stream().filter((s) -> s.contains("1")).collect(Collectors.toList()); // c помощью JDK
    Iterable<String>  guava = Iterables.filter(iterable, (s) -> s.contains("1")); // с помощью guava
    Collection<String> apache = CollectionUtils.select(iterable, (s) -> s.contains("1")); // c помощью Apache
    MutableCollection<String> gs = mutableCollection.select((s) -> s.contains("1")); // c помощью GS

    System.out.println("select = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает select = [14, 13]:[14, 13]:[14, 13]:[14, 13]
}
 
Example 7
Source File: VendorDB.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public List<String> findVendors(@NonNull String filter) {
    if (StringUtils.isBlank(filter)) {
        return new ArrayList<>(getVendors().keySet());
    }
    Locale locale = Locale.getDefault();
    String filterToUpperCase = filter.toUpperCase(locale);
    List<Predicate<String>> predicates = Arrays.asList(new StringContains(filterToUpperCase), new MacContains(filterToUpperCase));
    return new ArrayList<>(CollectionUtils.select(getVendors().keySet(), PredicateUtils.anyPredicate(predicates)));
}
 
Example 8
Source File: NameIndex.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@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);
    }
  });
}
 
Example 9
Source File: ClassInstanceIndex.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<AssociationRoleIF> getAssociationRoles(TopicIF association_role_type, final TopicIF association_type) {
  if (roles.containsKey(association_role_type)) {
    return CollectionUtils.select(roles.get(association_role_type), new Predicate<AssociationRoleIF>() {
      @Override
      public boolean evaluate(AssociationRoleIF role) {
        return role.getAssociation().getType().equals(association_type);
      }
    });
  } else {
    return Collections.<AssociationRoleIF>emptyList();
  }
}
 
Example 10
Source File: WiFiData.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example 11
Source File: ChannelRating.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
private List<WiFiDetail> collectOverlapping(@NonNull WiFiChannel wiFiChannel) {
    return new ArrayList<>(CollectionUtils.select(wiFiDetails, new InRangePredicate(wiFiChannel)));
}
 
Example 12
Source File: TimeGraphCache.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
Set<WiFiDetail> active() {
    return new HashSet<>(CollectionUtils.select(notSeen.keySet(), new SeenPredicate()));
}
 
Example 13
Source File: DataManager.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
Set<WiFiDetail> getNewSeries(@NonNull List<WiFiDetail> wiFiDetails, @NonNull Pair<WiFiChannel, WiFiChannel> wiFiChannelPair) {
    return new TreeSet<>(CollectionUtils.select(wiFiDetails, new InRangePredicate(wiFiChannelPair)));
}
 
Example 14
Source File: ChannelGraphNavigation.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
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);
}
 
Example 15
Source File: NameIndex.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<TopicNameIF> getTopicNames(String value, final TopicIF topicNameType) {
  return CollectionUtils.select(extractExactValues(basenames, value), new TypedPredicate(topicNameType));
}
 
Example 16
Source File: OccurrenceIndex.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<OccurrenceIF> getOccurrencesByPrefix(String prefix, final LocatorIF datatype) {
  return CollectionUtils.select(extractPrefixValues(occurs, prefix), new DataTypePredicate(datatype));
}
 
Example 17
Source File: OccurrenceIndex.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<OccurrenceIF> getOccurrences(String value, final LocatorIF datatype, final TopicIF occurrenceType) {
  return CollectionUtils.select(extractExactValues(occurs, value), 
          new AndPredicate<>(new DataTypePredicate(datatype), new TypedPredicate(occurrenceType)));
}
 
Example 18
Source File: OccurrenceIndex.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<OccurrenceIF> getOccurrences(String value, final LocatorIF datatype) {
  return CollectionUtils.select(extractExactValues(occurs, value), new DataTypePredicate(datatype));
}
 
Example 19
Source File: SSIDAdapter.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setValues(@NonNull Set<String> values) {
    super.setValues(new HashSet<>(CollectionUtils.select(values, new SSIDPredicate())));
}
 
Example 20
Source File: CollectionsUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 按照指定的 {@link Predicate},返回查询出来的集合.
 * 
 * <h3>说明:</h3>
 * <blockquote>
 * <ol>
 * <li>和该方法正好相反的是 {@link #selectRejected(Iterable, Predicate)}</li>
 * </ol>
 * </blockquote>
 * 
 * <h3>示例1:</h3>
 * <blockquote>
 * 
 * <p>
 * <b>场景:</b> 查找等于 1的元素
 * </p>
 * 
 * <pre class="code">
 * List{@code <Long>} list = new ArrayList{@code <>}();
 * list.add(1L);
 * list.add(1L);
 * list.add(2L);
 * list.add(3L);
 * LOGGER.info(JsonUtil.format(CollectionsUtil.select(list, new EqualPredicate{@code <Long>}(1L))));
 * </pre>
 * 
 * <b>返回:</b>
 * 
 * <pre class="code">
 * [1,1]
 * </pre>
 * 
 * </blockquote>
 * 
 * <h3>示例2:</h3>
 * <blockquote>
 * 
 * <p>
 * <b>场景:</b> 查找大于 10的元素
 * </p>
 * 
 * <pre class="code">
 * Comparator{@code <Integer>} comparator = ComparatorUtils.naturalComparator();
 * Predicate{@code <Integer>} predicate = new ComparatorPredicate{@code <Integer>}(10, comparator, Criterion.LESS);
 * 
 * List{@code <Integer>} select = CollectionsUtil.select(toList(1, 5, 10, 30, 55, 88, 1, 12, 3), predicate);
 * LOGGER.debug(JsonUtil.format(select, 0, 0));
 * </pre>
 * 
 * <b>返回:</b>
 * 
 * <pre class="code">
 * [30,55,88,12]
 * </pre>
 * 
 * </blockquote>
 *
 * @param <O>
 *            the generic type
 * @param beanIterable
 *            bean Iterable,诸如List{@code <User>},Set{@code <User>}等
 * @param predicate
 *            接口封装了对输入对象的判断,返回true或者false,可用的实现类有
 *            <ul>
 *            <li>{@link org.apache.commons.collections4.functors.EqualPredicate EqualPredicate}</li>
 *            <li>{@link org.apache.commons.collections4.functors.IdentityPredicate IdentityPredicate}</li>
 *            <li>{@link org.apache.commons.collections4.functors.FalsePredicate FalsePredicate}</li>
 *            <li>{@link org.apache.commons.collections4.functors.TruePredicate TruePredicate}</li>
 *            <li>....</li>
 *            </ul>
 * @return 如果 <code>beanIterable</code> 是null或者empty,返回 {@link Collections#emptyList()}<br>
 *         否则返回 {@link CollectionUtils#select(Iterable, Predicate)}
 * @see org.apache.commons.collections4.CollectionUtils#select(Iterable, Predicate)
 */
public static <O> List<O> select(Iterable<O> beanIterable,Predicate<O> predicate){
    return isNullOrEmpty(beanIterable) ? Collections.<O> emptyList() : (List<O>) CollectionUtils.select(beanIterable, predicate);
}