Example usage for org.apache.commons.collections CollectionUtils select

List of usage examples for org.apache.commons.collections CollectionUtils select

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils select.

Prototype

public static Collection select(Collection inputCollection, Predicate predicate) 

Source Link

Document

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

Usage

From source file:de.hybris.platform.b2bacceleratorfacades.order.populators.B2BApprovalDataPopulator.java

protected List<B2BOrderHistoryEntryData> filterOrderHistoryEntriesForApprovalStage(
        final List<B2BOrderHistoryEntryData> orderHistoryEntries, final String orderApprovalStage) {

    final Collection<B2BOrderHistoryEntryData> outputList = CollectionUtils.select(orderHistoryEntries,
            applyApprovalStagePredicate(orderApprovalStage));
    if (outputList != null && !outputList.isEmpty()) {
        final List<B2BOrderHistoryEntryData> selectedList = new ArrayList<B2BOrderHistoryEntryData>(
                outputList.size());/*  w w  w. j  a  va 2  s . c om*/
        selectedList.addAll(outputList);

        CollectionUtils.filter(orderHistoryEntries,
                PredicateUtils.notPredicate(applyApprovalStagePredicate(orderApprovalStage)));
        return selectedList;
    }
    return null;
}

From source file:de.hybris.platform.b2bacceleratorfacades.order.impl.DefaultB2BCheckoutFacade.java

@Override
public List<B2BCostCenterData> getActiveVisibleCostCenters() {
    final Collection costCenters = CollectionUtils.select(b2bCostCenterService.getAllCostCenters(),
            new Predicate() {
                @Override//w w w  .j a  v  a 2 s. c o  m
                public boolean evaluate(final Object object) {
                    return ((B2BCostCenterModel) object).getActive().booleanValue();
                }
            });
    return Converters.convertAll(costCenters, getB2bCostCenterConverter());
}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.AliquotReportServiceImpl.java

public List<Aliquot> getFilteredAliquotList(final List<Aliquot> list, final String aliquot,
        final List<String> disease, final List<String> center, final List<String> platform,
        final String bcrBatch, final List<String> levelOne, final List<String> levelTwo,
        final List<String> levelThree) {
    StringBuilder strLog = new StringBuilder();
    strLog.append("Filter used: aliquot:").append(aliquot).append(" disease:").append(disease)
            .append(" center:").append(center).append(" platform:").append(platform).append(" bcrBatch:")
            .append(bcrBatch).append(" levelOne:").append(levelOne).append(" levelTwo:").append(levelTwo)
            .append(" levelThree:").append(levelThree);
    logger.debug(strLog);//  w w  w .j  a v  a2  s  . c o  m
    if (aliquot == null && disease == null && center == null && platform == null && bcrBatch == null
            && levelOne == null && levelTwo == null && levelThree == null) {
        return list; //quick test so we don't have to evaluate the predicates
    }
    //Cool predicates to do my sql behavior WHERE .. AND ... in java collections 
    List<Predicate> aliPredicateList = new LinkedList<Predicate>();
    aliPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            if (aliquot == null || "".equals(aliquot)) {
                return true;
            }
            return (((Aliquot) o).getAliquotId()).startsWith(aliquot);
        }
    });
    aliPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            if (bcrBatch == null || "".equals(bcrBatch)) {
                return true;
            }
            return bcrBatch.equals(((Aliquot) o).getBcrBatch());
        }
    });
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, disease, DISEASE);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, center, CENTER);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, platform, PLATFORM);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, levelOne, LEVEL_ONE);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, levelTwo, LEVEL_TWO);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, levelThree, LEVEL_THREE);

    Predicate aliquotPredicates = PredicateUtils.allPredicate(aliPredicateList);
    List<Aliquot> fList = (List<Aliquot>) CollectionUtils.select(list, aliquotPredicates);
    return fList;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.BamTelemetryReportServiceImpl.java

@Override
public List<BamTelemetry> getFilteredBamTelemetryList(final List<BamTelemetry> list, final String aliquotUUID,
        final String aliquotId, final String dateFrom, final String dateTo, final List<String> disease,
        final List<String> center, final List<String> dataType, final List<String> analyteCode,
        final List<String> libraryStrategy) {
    final StringBuilder strLog = new StringBuilder();
    final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_US_STRING);
    strLog.append("Filter used: aliquotUUID:").append(aliquotUUID).append("aliquotID").append(aliquotId)
            .append(" disease:").append(disease).append(" center:").append(center).append(" dataType:")
            .append(dataType).append(" analyteCode:").append(analyteCode).append(" dateFrom:").append(dateFrom)
            .append(" dateTo:").append(dateTo).append(" libraryStrategy:").append(libraryStrategy);
    logger.debug(strLog);/*  w w w .java2  s .c  o m*/
    if (aliquotId == null && aliquotUUID == null && disease == null && center == null && dataType == null
            && analyteCode == null && dateFrom == null && dateTo == null && libraryStrategy == null) {
        return list;
    }

    final List<Predicate> bamPredicateList = new LinkedList<Predicate>();
    bamPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            boolean isValid = true;

            if (StringUtils.isNotEmpty(aliquotUUID)) {
                isValid = (((BamTelemetry) o).getAliquotUUID()).equalsIgnoreCase(aliquotUUID);
            } else if (StringUtils.isNotEmpty(aliquotId)) {
                isValid = (((BamTelemetry) o).getAliquotId()).startsWith(aliquotId);
            } else {
                return isValid;
            }
            return isValid;
        }
    });
    bamPredicateList.add(
            commonService.genDatePredicate(BamTelemetry.class, "dateReceived", false, dateFrom, dateFormat));
    bamPredicateList
            .add(commonService.genDatePredicate(BamTelemetry.class, "dateReceived", true, dateTo, dateFormat));
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, disease, DISEASE);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, center, CENTER);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, dataType, DATA_TYPE);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, analyteCode, ANALYTE_CODE);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, libraryStrategy, LIBRARY_STRATEGY);

    Predicate bamTelemetryPredicates = PredicateUtils.allPredicate(bamPredicateList);
    List<BamTelemetry> fList = (List<BamTelemetry>) CollectionUtils.select(list, bamTelemetryPredicates);
    return fList;
}

From source file:de.hybris.platform.b2bacceleratorfacades.user.populators.B2BCustomerPopulator.java

protected void populatePermissionGroups(final B2BCustomerModel source, final CustomerData target) {
    final Collection<B2BUserGroupModel> permissionGroups = CollectionUtils.select(source.getGroups(),
            PredicateUtils.instanceofPredicate(B2BUserGroupModel.class));
    final List<B2BUserGroupData> permissionGroupData = new ArrayList<B2BUserGroupData>(permissionGroups.size());

    for (final B2BUserGroupModel group : permissionGroups) {
        final B2BUserGroupData b2BUserGroupData = new B2BUserGroupData();
        b2BUserGroupData.setName(group.getName());
        b2BUserGroupData.setUid(group.getUid());
        final B2BUnitData b2BUnitData = new B2BUnitData();
        b2BUnitData.setUid(group.getUnit().getUid());
        b2BUnitData.setName(group.getUnit().getLocName());
        b2BUnitData.setActive(Boolean.TRUE.equals(group.getUnit().getActive()));

        b2BUserGroupData.setUnit(b2BUnitData);
        permissionGroupData.add(b2BUserGroupData);
    }/*from w  w w .  jav  a2 s .co m*/

    target.setPermissionGroups(permissionGroupData);
}

From source file:com.frank.search.solr.core.query.HighlightOptions.java

/**
 * Get Collection of fields that have field specific highlight options.
 * /*from  w  ww . j a v  a 2  s  . c om*/
 * @return
 */
@SuppressWarnings("unchecked")
public Collection<FieldWithHighlightParameters> getFieldsWithHighlightParameters() {
    return (Collection<FieldWithHighlightParameters>) CollectionUtils.select(this.fields,
            new IsFieldWithHighlightParametersInstancePredicate());
}

From source file:RestoreService.java

/**
 * execute restore process/*w  w w. java 2  s  .co m*/
 *
 * @throws Exception
 */
public void run() throws Exception {
    // load index
    Collection<File> bckIdxCollection = FileUtils.listFiles(repository.getMetaPath(),
            new WildcardFileFilter(bckIdxName + "*"), TrueFileFilter.INSTANCE);

    // TODO Lebeda - check only one index file

    // find files ro restore
    Set<VOBackupFile> oldFileSet = repository.collectBackupedFilesFromIndex(bckIdxCollection);
    Set<VOBackupFile> restoreFileSet = new HashSet<>();
    for (final String path : pathToRestoreList) {
        //noinspection unchecked
        restoreFileSet.addAll((Collection<VOBackupFile>) CollectionUtils.select(oldFileSet, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                VOBackupFile voBackupFile = (VOBackupFile) object;
                return StringUtils.startsWithIgnoreCase(voBackupFile.getPath(), path + File.separator);
            }
        }));
    }

    // create directory if not exists
    for (String pathForRestore : pathToRestoreList) {
        pathForRestore = changedPathToRestore(pathForRestore, targetPath);
        File baseFile = new File(pathForRestore);
        if (!baseFile.exists()) {
            //noinspection ResultOfMethodCallIgnored
            baseFile.mkdirs(); // TODO Lebeda - oetit hodnotu
        }
    }

    // find files in directory
    List<VOBackupFile> newFileList = new ArrayList<>();
    for (String pathForRestore : pathToRestoreList) {
        pathForRestore = changedPathToRestore(pathForRestore, targetPath);
        //noinspection unchecked
        final Collection<File> fileColection = FileUtils.listFiles(new File(pathForRestore),
                TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);

        for (File file : fileColection) {
            newFileList.add(new VOBackupFile(file));
        }
    }

    // delete files not in index (new or changed)
    //noinspection unchecked
    final Collection<VOBackupFile> toDelete = (Collection<VOBackupFile>) CollectionUtils.subtract(newFileList,
            restoreFileSet);
    for (VOBackupFile voBackupFile : toDelete) {
        FileUtils.forceDelete(new File(voBackupFile.getPath()));
        logger.debug("deleted file: {}", voBackupFile.getPath());
    }

    // restore files not in direcroty
    //noinspection unchecked
    final Collection<VOBackupFile> toRestore = (Collection<VOBackupFile>) CollectionUtils
            .subtract(restoreFileSet, newFileList);

    final Collection<VOBackupFile> toTime = new ArrayList<>();
    for (VOBackupFile voBackupFile : toRestore) {
        String path = changedPathToRestore(voBackupFile.getPath(), targetPath);
        if (!voBackupFile.isSymLink()) {
            if (voBackupFile.isDirectory()) {
                File dir = new File(path);
                dir.mkdirs(); // TODO Lebeda - zajistit oeten
                toTime.add(voBackupFile);
                setAdvancedAttributes(voBackupFile, dir);
            } else if (voBackupFile.getSize() == 0) {
                File file = new File(path);
                file.createNewFile(); // TODO Lebeda - oetit
                file.setLastModified(voBackupFile.getModify().getTime());
                setAdvancedAttributes(voBackupFile, file);
            } else if (StringUtils.isNotBlank(voBackupFile.getFileHash())) {
                repository.restoreFile(voBackupFile, path);
            } else {
                // TODO Lebeda - chyba
                //                LoggerTools.log("unable to restore ${it}")
            }
        }
    }

    // symlinks restore at end
    for (VOBackupFile voBackupFile : toRestore) {
        String path = changedPathToRestore(voBackupFile.getPath(), targetPath);
        if (voBackupFile.isSymLink()) {
            Files.createSymbolicLink(Paths.get(path), Paths.get(voBackupFile.getSymlinkTarget()));
        }
    }

    for (VOBackupFile voBackupFile : toTime) {
        String path = changedPathToRestore(voBackupFile.getPath(), targetPath);
        File dir = new File(path);
        dir.setLastModified(voBackupFile.getModify().getTime());
    }

}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.DatareportsServiceFastTest.java

@Test
public void genListPredicates() {
    List<String> strList = new LinkedList<String>() {
        {//from  www.  j  av  a  2 s  . com
            add("GBM");
        }
    };
    List<Predicate> pList = commonService.genListPredicates(Aliquot.class, strList, "disease");
    List<Aliquot> fList = (List<Aliquot>) CollectionUtils.select(makeMockAliquotRows(),
            PredicateUtils.allPredicate(pList));
    assertEquals(1, pList.size());
    assertEquals(2, fList.size());
}

From source file:ke.co.tawi.babblesms.server.servlet.sms.send.SendSMS.java

/**
 * Method to handle form processing//  www  . j a v  a 2s.co  m
 * 
 * @param request
 * @param response
 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 * 
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // Respond as soon as possible to the client request
    HttpSession session = request.getSession(true);
    session.setAttribute(SessionConstants.SENT_SUCCESS, "success");
    response.sendRedirect("sendsms.jsp");

    // Get the relevant account      
    Account account = new Account();

    String username = request.getParameter("username");

    Element element;
    if ((element = accountsCache.get(username)) != null) {
        account = (Account) element.getObjectValue();
    }

    TawiGateway smsGateway = gatewayDAO.get(account);

    // Retrieve the web parameters
    String[] groupselected = request.getParameterValues("groupselected");
    String[] phones = request.getParameterValues("phones");
    String source = request.getParameter("source");
    String message = request.getParameter("message");

    // Deal with the case where one or more Groups has been selected
    // Get phones of all the Contacts in the Group(s)
    SetUniqueList phoneList = SetUniqueList.decorate(new LinkedList<Phone>()); // Does not allow duplicates 

    Group group;
    List<Contact> contactList;
    List<OutgoingGrouplog> outgoingGroupList = new LinkedList<>();

    if (groupselected != null) {
        OutgoingGrouplog groupLog;

        for (String groupUuid : groupselected) {
            group = new Group();
            group.setUuid(groupUuid);
            contactList = ctgrpDAO.getContacts(group);

            for (Contact contact : contactList) {
                phoneList.addAll(phoneDAO.getPhones(contact));
            }

            // Save an outgoing log for the group 
            groupLog = new OutgoingGrouplog();
            groupLog.setMessagestatusUuid(MsgStatus.SENT);
            groupLog.setSender(account.getUuid());
            groupLog.setDestination(group.getUuid());
            groupLog.setMessage(message);
            outgoingGroupList.add(groupLog);

        } // end 'for(String groupUuid : groupselected)'
    } // end 'if(groupselected != null)'

    // This is the case where individual Contacts may have been selected      
    if (phones == null) {
        phones = new String[0];
    }
    phones = StringUtil.removeDuplicates(phones);

    for (String phone : phones) {
        phoneList.add(phoneDAO.getPhone(phone));
    }

    // Determine whether a shortcode or mask is the source
    SMSSource smsSource;
    Shortcode shortcode = shortcodeDAO.get(source);
    Mask mask = null;
    if (shortcode == null) {
        mask = maskDAO.get(source);
        smsSource = mask;

    } else {
        smsSource = shortcode;
    }

    // Set the network in the groups (if any) and save the log
    for (OutgoingGrouplog log : outgoingGroupList) {
        log.setNetworkUuid(smsSource.getNetworkuuid());
        log.setOrigin(smsSource.getUuid());
        groupLogDAO.put(log);
    }

    // Filter the phones to the Network of the source (mask or short code)
    List<Phone> validPhoneList = new LinkedList<>();
    validPhoneList.addAll(
            CollectionUtils.select(phoneList, new PhonesByNetworkPredicate(smsSource.getNetworkuuid())));

    // Break down the phone list to go out to manageable sizes, each sublist
    // being sent to the SMS Gateway in one URL POST
    List<List<Phone>> phonePartition = ListPartitioner.partition(validPhoneList, 10);

    // Send the lists one by one
    PostSMS postThread;

    for (List<Phone> list : phonePartition) {
        postThread = new PostSMS(smsGateway, list, smsSource, message, account, true);

        postThread.start();
    }

    // Deduct credit
    smsBalanceDAO.deductBalance(account, smsSource, validPhoneList.size());
}

From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java

public List<DegreeTeachingService> getDegreeTeachingServices() {
    return (List<DegreeTeachingService>) CollectionUtils.select(getServiceItemsSet(), new Predicate() {
        @Override/*from   w  w w  .ja v  a 2  s  .co  m*/
        public boolean evaluate(Object arg0) {
            return arg0 instanceof DegreeTeachingService;
        }
    });
}