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

The following examples show how to use org.apache.commons.collections4.CollectionUtils#collect() . 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: DrugsLogicImpl.java    From icure-backend with GNU General Public License v2.0 6 votes vote down vote up
public List<MppPreview> getMedecinePackagesFromIngredients(String searchString, String lang, List<String> types, int first, int count) {
    try {
        drugsDAO.openDataStoreSession();
        Validate.noNullElements(new Object[]{searchString, lang});
        log.debug("Asked language : " + lang);
        lang = getAvailableLanguage(lang);
        log.debug("Final language : " + lang);
        List<Mpp> packages = drugsDAO.getMedecinePackagesFromIngredients(searchString, lang, types, first, count);
        return (List<MppPreview>) CollectionUtils.collect(packages, MPP_TO_MPPPREVIEW);
    } catch (Exception e) {
        log.debug(e);
        return new ArrayList<>();
    }
    finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 2
Source File: DrugsLogicImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<MpPreview> getChildrenMps(DocId docID) {
    try {
        drugsDAO.openDataStoreSession();
        Doc aDoc = drugsDAO.getDoc(docID);
        SortedSet<Mp> childrenMps = aDoc.getMps();
        List<Mp> resultMps = new ArrayList<>();
        resultMps.addAll(childrenMps);
        List<Doc> childrenDocs = aDoc.getChildren();
        if (childrenDocs.size() > 0) {
            if (childrenDocs.get(0).getMpgrp()) {
                for (Doc child : childrenDocs) {
                    resultMps.addAll(child.getMps());
                }
            }
        }
        return (List<MpPreview>) CollectionUtils.collect(resultMps, MP_TO_MPPREVIEW);
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 3
Source File: FanInGraph.java    From gocd with Apache License 2.0 5 votes vote down vote up
private void assertAllDirectDependenciesArePresentInInput(MaterialRevisions actualRevisions, CaseInsensitiveString pipelineName) {
    Collection<String> actualRevFingerprints = CollectionUtils.collect(actualRevisions.iterator(), actualRevision -> actualRevision.getMaterial().getFingerprint());

    for (FanInNode child : root.children) {
        //The dependency material that is not in 'passed' state will not be found in actual revisions
        if (!actualRevFingerprints.contains(child.materialConfig.getFingerprint())) {
            throw NoCompatibleUpstreamRevisionsException.doesNotHaveValidRevisions(pipelineName, child.materialConfig);
        }
    }
}
 
Example 4
Source File: DrugsLogicImpl.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<ParagraphPreview> findParagraphs(String searchString, String lang) {
    try {
        drugsDAO.openDataStoreSession();
        lang = getAvailableLanguage(lang);
        return (List<ParagraphPreview>) CollectionUtils.collect(drugsDAO.findParagraphs(searchString, lang), PARAGRAPH_TO_PARAGRAPHPREVIEW);
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 5
Source File: DrugsLogicImpl.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
public List<MppPreview> getMedecinePackages(String searchString, String lang, List<String> types, int first, int count) {
    try {
        drugsDAO.openDataStoreSession();
        Validate.noNullElements(new Object[]{searchString, lang});
        log.debug("Asked language : " + lang);
        lang = getAvailableLanguage(lang);
        log.debug("Final language : " + lang);
        List<Mpp> packages = drugsDAO.getMedecinePackages(searchString, lang, types, first, count);
        return (List<MppPreview>) CollectionUtils.collect(packages, MPP_TO_MPPPREVIEW);
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 6
Source File: ChannelRating.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: NodeJdbcDAO.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
public Node updateConfiguration(Node configToUpdate, List<ConfigPv> updatedConfigPvList) {

	Node configNode = getNode(configToUpdate.getUniqueId());

	if(configNode == null || !configNode.getNodeType().equals(NodeType.CONFIGURATION)) {
		throw new IllegalArgumentException(String.format("Config node with unique id=%s not found or is wrong type", configToUpdate.getUniqueId()));
	}

	List<ConfigPv> existingConfigPvList = getConfigPvs(configToUpdate.getUniqueId());

	Collection<ConfigPv> pvsToRemove = CollectionUtils.removeAll(existingConfigPvList,
			updatedConfigPvList);
	Collection<Integer> pvIdsToRemove = CollectionUtils.collect(pvsToRemove, ConfigPv::getId);

	// Remove PVs from relation table
	pvIdsToRemove.stream().forEach(id -> jdbcTemplate.update(
			"delete from config_pv_relation where config_id=? and config_pv_id=?",
			configNode.getId(), id));

	// Check if any of the PVs is orphaned
	deleteOrphanedPVs(pvIdsToRemove);

	Collection<ConfigPv> pvsToAdd = CollectionUtils.removeAll(updatedConfigPvList,
			existingConfigPvList);

	// Add new PVs
	pvsToAdd.stream().forEach(configPv -> saveConfigPv(configNode.getId(), configPv));

	updateProperties(configNode.getId(), configToUpdate.getProperties());

	jdbcTemplate.update("update node set username=?, last_modified=? where id=?",
			configToUpdate.getUserName(), Timestamp.from(Instant.now()), configNode.getId());

	return getNode(configNode.getId());
}
 
Example 8
Source File: DrugsLogicImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<ParagraphPreview> findParagraphsWithCnk(Long cnk, String lang) {
    try {
        drugsDAO.openDataStoreSession();
        lang = getAvailableLanguage(lang);
        return (List<ParagraphPreview>) CollectionUtils.collect(drugsDAO.findParagraphsWithCnk(cnk, lang), PARAGRAPH_TO_PARAGRAPHPREVIEW);
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 9
Source File: Scenarios.java    From java-persistence-frameworks-comparison with MIT License 5 votes vote down vote up
private void updateDepartments(Company company, List<Department> newDepartments) {
    // --------------------------------------------------------------------------------------------------------------------------------------
    // The pattern for one-to-many relation update begins here - but BEWARE, it'll work nicely only for few items in the one to many relation
    // --------------------------------------------------------------------------------------------------------------------------------------

    // first get current departments
    List<Department> currentDepartments = repository.findDepartmentsOfCompany(company);
    logger.info("Company {} current departments {}", company.getName(), currentDepartments);

    // now determine which departments were deleted
    Collection<Integer> newPIDs = CollectionUtils.collect(newDepartments, Department::getPid);
    List<Department> deletedDepartments = currentDepartments.stream()
            .filter(department -> !newPIDs.contains(department.getPid()))
            .collect(toList());

    // ... and which were added or updated
    Map<Boolean, List<Department>> addedOrUpdatedDepartments = newDepartments.stream()
            .filter(department -> !currentDepartments.contains(department))  // filtering out not changed items, assumes that equals and hashCode is properly coded in Department class
            .collect(Collectors.partitioningBy(d -> d.getPid() == null));  // split (partition) by new or updated (pid is either null or not)
    List<Department> addedDepartments = addedOrUpdatedDepartments.get(Boolean.TRUE);
    List<Department> updatedDepartments = addedOrUpdatedDepartments.get(Boolean.FALSE);

    // now perform relevant operations on each list:
    repository.deleteDepartments(deletedDepartments);
    repository.insertDepartments(addedDepartments);
    repository.updateDepartments(updatedDepartments);
}
 
Example 10
Source File: DrugsLogicImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<MppPreview> getCheapAlternativesBasedOnInn(String innCluster, String lang) {
    try {
        drugsDAO.openDataStoreSession();
        try {
            lang = getAvailableLanguage(lang);
            return (List<MppPreview>) CollectionUtils.collect(drugsDAO.getCheapMppsWithInn(innCluster, lang), MPP_TO_MPPPREVIEW);
        } catch (Exception ignored) {
        }
        return new ArrayList<>();
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 11
Source File: DrugsLogicImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<MpPreview> getCheapAlternativesBasedOnAtc(MppId medecinePackageID) {
    try {
        drugsDAO.openDataStoreSession();
        try {
            Atc atc = drugsDAO.getAtc(medecinePackageID);

            return (List<MpPreview>) CollectionUtils.collect(drugsDAO.getMpsWithAtc(atc), MP_TO_MPPREVIEW);
        } catch (Exception ignored) {
        }
        return new ArrayList<>();
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 12
Source File: DrugsLogicImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<MppPreview> getMedecinePackagesFromInn(String inn, String lang) {
    try {
        drugsDAO.openDataStoreSession();
        lang = getAvailableLanguage(lang);

        return (List<MppPreview>) CollectionUtils.collect(drugsDAO.getMppsWithInn(inn, lang), MPP_TO_MPPPREVIEW);
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 13
Source File: DrugsLogicImpl.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
public List<MppPreview> getCheapAlternativesBasedOnInn(String innCluster, String lang) {
    try {
        drugsDAO.openDataStoreSession();
        try {
            lang = getAvailableLanguage(lang);
            return (List<MppPreview>) CollectionUtils.collect(drugsDAO.getCheapMppsWithInn(innCluster, lang), MPP_TO_MPPPREVIEW);
        } catch (Exception ignored) {
        }
        return new ArrayList<>();
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 14
Source File: DrugsLogicImpl.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<ParagraphPreview> findParagraphsWithCnk(Long cnk, String lang) {
    try {
        drugsDAO.openDataStoreSession();
        lang = getAvailableLanguage(lang);
        return (List<ParagraphPreview>) CollectionUtils.collect(drugsDAO.findParagraphsWithCnk(cnk, lang), PARAGRAPH_TO_PARAGRAPHPREVIEW);
    } finally {
        drugsDAO.closeDataStoreSession();
    }
}
 
Example 15
Source File: WiFiChannelCountry.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public static List<WiFiChannelCountry> getAll() {
    return new ArrayList<>(CollectionUtils.collect(LocaleUtils.getAllCountries(), new ToCountry()));
}
 
Example 16
Source File: LanguagePreference.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
private static List<Data> getData() {
    List<Data> results = new ArrayList<>(CollectionUtils.collect(LocaleUtils.getSupportedLanguages(), new ToData()));
    Collections.sort(results);
    return results;
}
 
Example 17
Source File: SysAuthorityServiceImpl.java    From cola-cloud with MIT License 4 votes vote down vote up
@Override
public Collection<String> getResourceCodesByAuthorizeTargetAndType(Long target, String type){
    List<SysResource> sysResources = this.getResourcesByAuthorizeTargetAndType(target,type);
    return CollectionUtils.collect(sysResources.iterator(),(input) -> input.getCode());
}
 
Example 18
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 19
Source File: TimeGraphAdapter.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
private static List<GraphViewNotifier> makeGraphViewNotifiers() {
    return new ArrayList<>(CollectionUtils.collect(EnumUtils.values(WiFiBand.class), new ToGraphViewNotifier()));
}
 
Example 20
Source File: CollectionsUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 循环 <code>inputIterable</code>,将每个元素使用 <code>transformer</code> 转换成新的对象,返回<b>新的list</b>.
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * 
 * List{@code <String>} list = new ArrayList{@code <>}();
 * list.add("xinge");
 * list.add("feilong1");
 * list.add("feilong2");
 * list.add("feilong2");
 * 
 * Transformer{@code <String, Object>} nullTransformer = TransformerUtils.nullTransformer();
 * List{@code <Object>} collect = CollectionsUtil.collect(list, nullTransformer);
 * LOGGER.info(JsonUtil.format(collect, 0, 0));
 * 
 * </pre>
 * 
 * <b>返回:</b>
 * 
 * <pre class="code">
 * [null,null,null,null]
 * </pre>
 * 
 * </blockquote>
 * 
 * <h3>更多的,使用这个方法来处理两个不同类型的转换:</h3>
 * 
 * <blockquote>
 * <p>
 * 比如购物车功能,有游客购物车<b>CookieShoppingCartLine</b>以及内存购物车对象
 * <b>ShoppingCartLineCommand</b>,两个数据结构部分元素相同,<br>
 * 用户登陆需要把<b>cookie</b>中的购物车转成内存购物车<b>ShoppingCartLineCommand</b> list,这时我们可以先创建<b>ToShoppingCartLineCommandTransformer</b>
 * </p>
 * 
 * <p>
 * 代码示例:
 * </p>
 * 
 * <pre class="code">
 * 
 * class <b>ToShoppingCartLineCommandTransformer</b> implements <b>Transformer</b>{@code <CookieShoppingCartLine, ShoppingCartLineCommand>}{
 * 
 *     private static final String[] COPY_PROPERTY_NAMES = {"skuId","extentionCode","quantity","createTime","settlementState","lineGroup" };
 * 
 *     public ShoppingCartLineCommand <b>transform</b>(CookieShoppingCartLine cookieShoppingCartLine){
 *         <span style="color:green">// 将cookie中的购物车 转换为 shoppingCartLineCommand</span>
 *         ShoppingCartLineCommand shoppingLineCommand = new ShoppingCartLineCommand();
 *         PropertyUtil.copyProperties(shoppingLineCommand, cookieShoppingCartLine, COPY_PROPERTY_NAMES);
 * 
 *         shoppingLineCommand.setId(cookieShoppingCartLine.getId());
 *         shoppingLineCommand.setGift(null == cookieShoppingCartLine.getIsGift() ? false : cookieShoppingCartLine.getIsGift());
 * 
 *         return shoppingLineCommand;
 *     }
 * }
 * 
 * </pre>
 * 
 * <p>
 * 然后调用:
 * </p>
 * 
 * <pre class="code">
 * 
 * public List{@code <ShoppingCartLineCommand>} load(HttpServletRequest request){
 *     <span style="color:green">// 获取cookie中的购物车行集合</span>
 *     List{@code <CookieShoppingCartLine>} cookieShoppingCartLineList = getCookieShoppingCartLines(request);
 *     if (isNullOrEmpty(cookieShoppingCartLineList)){
 *         return null;
 *     }
 * 
 *     return CollectionsUtil.collect(cookieShoppingCartLineList, new ToShoppingCartLineCommandTransformer());
 * }
 * </pre>
 * 
 * </blockquote>
 *
 * @param <O>
 *            the type of object in the input collection
 * @param <T>
 *            the type of object in the output collection
 * @param inputIterable
 *            the inputIterable to get the input from
 * @param transformer
 *            the transformer to use, may be null
 * @return 如果 <code>inputIterable</code> 是null,返回 null<br>
 *         如果 <code>transformer</code> 是null,返回 empty list
 * @see org.apache.commons.collections4.CollectionUtils#collect(Iterable, Transformer)
 * @see org.apache.commons.collections4.CollectionUtils#transform(Collection, Transformer)
 * @since 1.5.5
 */
public static <O, T> List<T> collect(final Iterable<O> inputIterable,final Transformer<? super O, ? extends T> transformer){
    return null == inputIterable ? null : (List<T>) CollectionUtils.collect(inputIterable, transformer);
}