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

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

Introduction

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

Prototype

public static Object find(Collection collection, Predicate predicate) 

Source Link

Document

Finds the first element in the given collection which matches the given predicate.

Usage

From source file:jp.co.opentone.bsol.linkbinder.service.correspon.impl.LearningLabelServiceImpl.java

@Override
public void saveLearningLabels(Correspon correspon) throws ServiceAbortException {
    List<LearningLabel> labels = correspon.getLearningLabel();
    Set<LearningLabel> deleteCandidateLabels = new HashSet<>();

    LearningLabelDao dao = getDao(LearningLabelDao.class);
    CorresponLearningLabelDao clDao = getDao(CorresponLearningLabelDao.class);
    try {//from w  w w . j  a  v  a2 s  .  c o  m
        List<CorresponLearningLabel> exists = clDao.findByCorresponId(correspon.getId());
        // ??????????
        for (CorresponLearningLabel cl : exists) {
            LearningLabel found = (LearningLabel) CollectionUtils.find(labels,
                    o -> ((LearningLabel) o).getId().equals(cl.getLabelId()));
            if (found == null) {
                clDao.delete(cl);

                LearningLabel l = new LearningLabel();
                l.setId(cl.getLabelId());
                deleteCandidateLabels.add(l);
            }
        }

        // ??
        for (LearningLabel l : correspon.getLearningLabel()) {
            if (l.getId() < 0) {
                l.setCreatedBy(getCurrentUser());
                l.setUpdatedBy(getCurrentUser());
                Long id = dao.create(l);
                l.setId(id);
            }
            // ?
            CorresponLearningLabel found = (CorresponLearningLabel) CollectionUtils.find(exists,
                    o -> ((CorresponLearningLabel) o).getLabelId().equals(l.getId()));
            if (found == null) {
                CorresponLearningLabel cl = new CorresponLearningLabel();
                cl.setCorresponId(correspon.getId());
                cl.setLabelId(l.getId());
                cl.setCreatedBy(getCurrentUser());
                cl.setUpdatedBy(getCurrentUser());

                clDao.create(cl);
            }
        }

        // ?????????
        deleteCandidateLabels.forEach(dao::deleteIfUnused);
    } catch (StaleRecordException e) {
        throw new ServiceAbortException(
                ApplicationMessageCode.CANNOT_PERFORM_BECAUSE_CORRESPON_ALREADY_UPDATED);
    } catch (KeyDuplicateException e) {
        throw new ServiceAbortException(e);
    }
}

From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java

public EmployeeBO getEmployeeByEmployeeUID(String employeeUID) throws ExceptionWrapper {
    try {// ww  w  .  j  ava 2  s  . c o  m
        ArrayList<EmployeeBO> employeeBOArrayList = new ArrayList<EmployeeBO>(getAllEmployees().values());
        final String UID = employeeUID;
        return (EmployeeBO) CollectionUtils.find(employeeBOArrayList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                return ((EmployeeBO) o).getEmployeeUid().trim().equalsIgnoreCase(UID.trim()); //To change body of implemented methods use File | Settings | File Templates.
            }
        });
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:hr.fer.zemris.vhdllab.platform.manager.workspace.DefaultWorkspaceManager.java

@Override
public File getFile(String projectName, final String fileName) {
    Validate.notNull(projectName, "Project name can't be null");
    Validate.notNull(fileName, "File name can't be null");
    String key = makeKey(projectName, fileName);
    if (getFileIdentifiers().containsKey(key)) {
        return getFileIdentifiers().get(key);
    }//www.j  a va  2  s .  c  om
    Set<File> predefinedFiles = getWorkspace().getPredefinedFiles();
    File found = (File) CollectionUtils.find(predefinedFiles, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            File predefined = (File) object;
            return predefined.getName().equalsIgnoreCase(fileName);
        }
    });
    return new File(found, getProject(projectName));
}

From source file:net.sourceforge.fenixedu.dataTransferObject.CurricularCourseScopesForPrintDTO.java

private BranchForPrintDTO getSelectedBranch(final InfoCurricularCourseScope scope,
        CurricularYearForPrintDTO selectedCurricularYear) {
    BranchForPrintDTO selectedBranch = (BranchForPrintDTO) CollectionUtils
            .find(selectedCurricularYear.getBranches(), new Predicate() {

                @Override/*from   w ww .ja v a 2s .  c  om*/
                public boolean evaluate(Object arg0) {
                    BranchForPrintDTO branchForPrintDTO = (BranchForPrintDTO) arg0;
                    if (branchForPrintDTO.getName().equals(scope.getInfoBranch().getName())) {
                        return true;
                    }

                    return false;
                }

            });

    if (selectedBranch == null) {
        selectedBranch = new BranchForPrintDTO(scope.getInfoBranch().getName());
        selectedCurricularYear.getBranches().add(selectedBranch);

    }

    return selectedBranch;
}

From source file:edu.kit.dama.mdm.admin.UserPropertyCollection.java

/**
 * Returns the value of the property with the provided key as string. If the
 * property is not found, the provided default value is returned.
 *
 * @param pKey The property key.//from   w w  w.j  a  va  2 s. c o  m
 * @param pDefaultValue The default value.
 *
 * @return The value of the property or the provided default value.
 */
public String getStringProperty(final String pKey, String pDefaultValue) {
    if (pKey == null) {
        throw new IllegalArgumentException("Argument pKey must not be null");
    }
    UserProperty existingProp = (UserProperty) CollectionUtils.find(properties, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((UserProperty) o).getPropertyKey().equals(pKey);
        }
    });

    if (existingProp != null) {
        return existingProp.getPropertyValue();
    }
    return pDefaultValue;
}

From source file:com.ebay.cloud.cms.metadata.mongo.MongoRepositoryServiceImplTest.java

@Test
public void testRepsitory() {
    MetadataContext context = new MetadataContext();
    context.setRefreshRepsitory(false);//from  w  ww  .  j av a 2  s . c o m
    List<Repository> oldRepos = repositoryService.getRepositories(context);
    Assert.assertTrue(oldRepos.size() > 0);

    List<Repository> cachedRepos = repositoryService.getRepositories(context);
    for (final Repository repo : oldRepos) {
        Assert.assertNotNull(CollectionUtils.find(cachedRepos, new Predicate() {

            @Override
            public boolean evaluate(Object object) {
                if (object == repo) {
                    return true;
                }
                return false;
            }
        }));
    }

    context.setRefreshRepsitory(true);
    List<Repository> newRepos = repositoryService.getRepositories(context);
    for (final Repository repo : newRepos) {
        Assert.assertNull(CollectionUtils.find(cachedRepos, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                if (object == repo) {
                    return true;
                }
                return false;
            }
        }));
    }
}

From source file:hr.fer.zemris.vhdllab.service.workspace.ProjectMetadataTest.java

@Test
public void addFile2() {
    File file = new File("file_name", null, "data");
    file.setProject(hierarchy.getProject());
    metadata.addFile(file);/*ww w. j  a  v a  2s.com*/
    assertEquals(3, metadata.getFiles().size());
    assertTrue(metadata.getFiles().contains(file));

    File another = new File(file);
    another.setData("new_data");
    metadata.addFile(another);
    assertEquals(3, metadata.getFiles().size());
    File found = (File) CollectionUtils.find(metadata.getFiles(), new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            File f = (File) object;
            return f.getName().equals("file_name");
        }
    });
    assertEquals("new_data", found.getData());
}

From source file:com.epam.cme.facades.product.impl.DefaultTelcoProductFacade.java

/**
 * Check if the productData is present in list.
 * /*from  w ww .ja v  a  2  s.  c  o  m*/
 * @param productData
 *            list of existing product data items
 * @param newProduct
 *            product data item to be added
 * @return true if newProduct exists in productData
 */
protected boolean contains(final List<ProductData> productData, final ProductData newProduct) {
    final Object exists = CollectionUtils.find(productData, new Predicate() {

        @Override
        public boolean evaluate(final Object productDataObj) {
            final ProductData existingProductData = (ProductData) productDataObj;
            return existingProductData.getCode().equals(newProduct.getCode());
        }
    });
    if (exists != null) {
        return true;
    }
    return false;
}

From source file:de.hybris.platform.b2bacceleratorfacades.company.impl.DefaultB2BCommerceUnitFacade.java

@Override
public SearchPageData<UserData> getPagedManagersForUnit(final PageableData pageableData, final String unitUid) {
    final SearchPageData<UserData> searchPageData = this.getPagedUserDataForUnit(pageableData, unitUid);
    // update the results with users that already have been selected.
    final B2BUnitData unit = this.getUnitForUid(unitUid);
    validateParameterNotNull(unit, String.format("No unit found for uid %s", unitUid));
    for (final UserData userData : searchPageData.getResults()) {
        userData.setSelected(CollectionUtils.find(unit.getManagers(),
                new BeanPropertyValueEqualsPredicate(B2BCustomerModel.UID, userData.getUid())) != null);
    }//from  w  w w  . j a  v a2s.  c  om

    return searchPageData;
}

From source file:com.linkedin.thirdeye.hadoop.util.ThirdeyeAvroUtils.java

/**
 * Helper removed from AvroRecordReader in b19a0965044d3e3f4f1541cc4cd9ea60b96a4b99
 *
 * @param fieldSchema//  w  ww.  ja  v  a2  s. co  m
 * @return
 */
private static org.apache.avro.Schema extractSchemaFromUnionIfNeeded(org.apache.avro.Schema fieldSchema) {
    if ((fieldSchema).getType() == Schema.Type.UNION) {
        fieldSchema = ((org.apache.avro.Schema) CollectionUtils.find(fieldSchema.getTypes(), new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                return ((org.apache.avro.Schema) object).getType() != Schema.Type.NULL;
            }
        }));
    }
    return fieldSchema;
}