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.admin.impl.CompanyServiceImpl.java

/**
 * ?????????????./*  w w  w  . j a v  a2 s  . c  o  m*/
 * @param id ID
 * @param users 
 * @throws ServiceAbortException ??????
 */
private void validateProjectUserExists(Long id, List<User> users) throws ServiceAbortException {
    SearchUserCondition condition = new SearchUserCondition();
    condition.setProjectId(getCurrentProjectId());

    UserDao dao = getDao(UserDao.class);
    List<ProjectUser> projectUsers = dao.findProjectUser(condition);

    for (final User u : users) {
        //  ????????
        Object ret = CollectionUtils.find(projectUsers, new Predicate() {
            public boolean evaluate(Object object) {
                ProjectUser pu = (ProjectUser) object;
                return u.getEmpNo().equals(pu.getUser().getEmpNo());
            }
        });

        if (ret == null) {
            throw new ServiceAbortException("invalid user",
                    ApplicationMessageCode.CANNOT_PERFORM_BECAUSE_USER_ALREADY_DELETED, u.getLabel());
        }
    }
}

From source file:com.dell.asm.asmcore.asmmanager.util.deployment.ServerFilteringUtil.java

private LogicalNetworkInterface findFirstNIC(LogicalNetworkInterface nic, List<LogicalNetworkInterface> nics) {
    NicFQDD fqdd = new NicFQDD(nic.getFqdd());
    final String nicFqdd1stPort;
    if (fqdd.getPartition() == null) {
        nicFqdd1stPort = fqdd.getCardKey() + "-1";
    } else {/*from   w w  w.j a  v a 2  s. c om*/
        nicFqdd1stPort = fqdd.getCardKey() + "-1-1";
    }
    return (LogicalNetworkInterface) CollectionUtils.find(nics, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return ((LogicalNetworkInterface) object).getFqdd().equals(nicFqdd1stPort);
        }
    });
}

From source file:ml.shifu.shifu.util.CommonUtils.java

/**
 * Get target ColumnConfig.//  w  w  w . ja v a  2s. com
 *
 * @param columnConfigList
 *            column config list
 * @return target ColumnConfig
 * @throws IllegalArgumentException
 *             if columnConfigList is null or empty.
 *
 * @throws IllegalStateException
 *             if no target column can be found.
 */
public static ColumnConfig getTargetColumnConfig(List<ColumnConfig> columnConfigList) {
    if (CollectionUtils.isEmpty(columnConfigList)) {
        throw new IllegalArgumentException("columnConfigList should not be null or empty.");
    }
    // I need cast operation because of common-collections doesn't support generic.
    ColumnConfig cc = (ColumnConfig) CollectionUtils.find(columnConfigList, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return ((ColumnConfig) object).isTarget();
        }
    });
    if (cc == null) {
        throw new IllegalStateException(
                "No target column can be found, please check your column configurations");
    }
    return cc;
}

From source file:edu.kit.dama.rest.staging.types.TransferTaskContainer.java

/**
 * Add a data file/directory to the provided tree. If pDataFile is a file,
 * the file is added to the 'data' node of the provided file tree. If
 * pDataFile is a folder, all contained files and directories are added to
 * the 'data' node of the provided file tree. The tree must be compatible to
 * the required tree structure. Therefore, it should be created by
 * createCompatibleTree() before./*ww w .j  a  v a  2  s .co  m*/
 *
 * @param pTree The tree to which the file/directory is added.
 * @param pTransferInfo The transfer information associated with the tree.
 * @param pDataFile The file/directory to add.
 *
 * @throws edu.kit.lsdf.adalapi.exception.AdalapiException If pDataFile
 * cannot be accessed.
 * @throws java.net.MalformedURLException If extracting the URL information
 * from pDataFile fails. This should never happen.
 */
public final static void addDataFile(IFileTree pTree, ITransferInformation pTransferInfo, File pDataFile)
        throws AdalapiException, MalformedURLException {
    ICollectionNode dataNode = (ICollectionNode) CollectionUtils.find(pTree.getRootNode().getChildren(),
            new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    return Constants.STAGING_DATA_FOLDER_NAME.equals(((IDataOrganizationNode) o).getName());
                }
            });

    //DataOrganizationUtils.printTree(pTree.getRootNode(), true);
    if (dataNode == null) {
        throw new IllegalArgumentException("Provided tree has an invalid structure. No '"
                + Constants.STAGING_DATA_FOLDER_NAME + "' node found.");
    }

    AbstractFile dataFile = new AbstractFile(pDataFile);
    IFileTree newTree = DataOrganizationUtils.createTreeFromFile(pTransferInfo.getDigitalObjectId(), dataFile,
            dataFile.getUrl(), false);
    DataOrganizationUtils.merge(dataNode, new LinkedList<ICollectionNode>(), newTree.getRootNode().getChildren()
            .toArray(new IDataOrganizationNode[newTree.getRootNode().getChildren().size()]));
}

From source file:com.topsec.tsm.sim.event.web.EventQueryController.java

@SuppressWarnings("unchecked")
private void addDeviceGroupLogs(String dvcType, List<Map<String, Object>> clogs, Map<String, Object> log) {
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
    Map<String, Object> clog0 = (Map<String, Object>) CollectionUtils.find(clogs,
            new BeanPropertyValueEqualsPredicate("deviceType", dvcType));
    clog0 = (clog0 == null) ? new HashMap<String, Object>() : clog0;
    if (!clog0.containsKey("deviceType")) {
        IndexTemplateUtil indexTemplateUtil = IndexTemplateUtil.getInstance();
        List<IndexField> indexFields = indexTemplateUtil.getIndexFields(dvcType);//
        List<Map<String, String>> headcolums = new ArrayList<Map<String, String>>();
        for (IndexField indexField : indexFields) {
            Map<String, String> fieldMap = new HashMap<String, String>();
            fieldMap.put("field", indexField.getKey());
            fieldMap.put("title", indexTemplateUtil.getFieldAlias(dvcType, indexField.getKey()));
            headcolums.add(fieldMap);//  ww  w .j av a  2  s  .  c  o  m
        }

        clog0.put("dvcTypeName", DeviceTypeNameUtil.getDeviceTypeName(dvcType));
        clog0.put("deviceType", dvcType);
        clog0.put("headcolums", headcolums);
        clogs.add(clog0);
    }
    if (!clog0.containsKey("columsdata")) {
        clog0.put("columsdata", new ArrayList<Map<String, Object>>());
    }
    List<Map<String, Object>> columsdata = (List<Map<String, Object>>) clog0.get("columsdata");
    if (log.containsKey("PRIORITY")) {
        log.put("PRIORITY", CommonUtils.getLevel(log.get("PRIORITY")));
    }
    if (log.containsKey("START_TIME")) {
        try {
            Date date = sdf.parse(log.get("START_TIME").toString());
            log.put("START_TIME", StringUtil.dateToString(date, "yyyy-MM-dd HH:mm:ss"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    columsdata.add(log);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.student.finalDegreeWork.FinalDegreeWorkCandidacyDA.java

private void setDefaultExecutionDegree(ActionForm form, HttpServletRequest request, List infoExecutionDegrees)
        throws Exception {
    DynaActionForm dynaActionForm = (DynaActionForm) form;
    String executionDegreeOID = (String) dynaActionForm.get("executionDegreeOID");

    if ((executionDegreeOID == null || executionDegreeOID.length() == 0 || executionDegreeOID.equals(""))
            && infoExecutionDegrees != null && !infoExecutionDegrees.isEmpty()) {
        User userView = Authenticate.getUser();

        InfoStudentCurricularPlan infoStudentCurricularPlan = getDefaultStudentCurricularPlan(userView);
        if (infoStudentCurricularPlan == null) {
            throw new NoDegreeStudentCurricularPlanFoundException();
        }//from   ww w .  j a  v  a 2 s  .  c o  m

        InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) CollectionUtils
                .find(infoExecutionDegrees, new PREDICATE_FIND_EXECUTION_DEGREE_BY_DEGREE_CURRICULAR_PLAB(
                        infoStudentCurricularPlan.getInfoDegreeCurricularPlan().getExternalId()));

        if (infoExecutionDegree != null && infoExecutionDegree.getExternalId() != null) {
            executionDegreeOID = infoExecutionDegree.getExternalId().toString();
            dynaActionForm.set("executionDegreeOID", executionDegreeOID);
            request.setAttribute("finalDegreeWorkCandidacyForm", dynaActionForm);
        }
    }
}

From source file:edu.kit.dama.rest.staging.types.TransferTaskContainer.java

/**
 * Add a generated file/directory to the provided tree. If pGeneratedFile is
 * a file, the file is added to the 'generated' node of the provided file
 * tree. If pGeneratedFile is a folder, all contained files and directories
 * are added to the 'generated' node of the provided file tree. The tree
 * must be compatible to the required tree structure. Therefore, it should
 * be created by createCompatibleTree() before.
 *
 * @param pTree The tree to which the file/directory is added.
 * @param pTransferInfo The transfer information associated with the tree.
 * @param pGeneratedFile The file/directory to add.
 *
 * @throws edu.kit.lsdf.adalapi.exception.AdalapiException If pGeneratedFile
 * cannot be accessed./*from   w  w  w.j a v  a2 s  . c  om*/
 * @throws java.net.MalformedURLException If extracting the URL information
 * from pGeneratedFile fails. This should never happen.
 */
public final static void addGeneratedFile(IFileTree pTree, ITransferInformation pTransferInfo,
        File pGeneratedFile) throws AdalapiException, MalformedURLException {
    ICollectionNode generatedNode = (ICollectionNode) CollectionUtils.find(pTree.getRootNode().getChildren(),
            new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    return Constants.STAGING_GENERATED_FOLDER_NAME
                            .equals(((IDataOrganizationNode) o).getName());
                }
            });

    if (generatedNode == null) {
        throw new IllegalArgumentException("Provided tree has an invalid structure. No '"
                + Constants.STAGING_GENERATED_FOLDER_NAME + "' node found.");
    }

    IFileTree newTree = DataOrganizationUtils.createTreeFromFile(pTransferInfo.getDigitalObjectId(),
            new AbstractFile(pGeneratedFile), pTransferInfo.getGeneratedFolderUrl(), false);
    DataOrganizationUtils.merge(generatedNode, new LinkedList<ICollectionNode>(), newTree.getRootNode()
            .getChildren().toArray(new IDataOrganizationNode[newTree.getRootNode().getChildren().size()]));
}

From source file:edu.kit.dama.rest.staging.types.TransferTaskContainer.java

/**
 * Add a settings file/directory to the provided tree. If pSettingsFile is a
 * file, the file is added to the 'settings' node of the provided file tree.
 * If pSettingsFile is a folder, all contained files and directories are
 * added to the 'settings' node of the provided file tree. The tree must be
 * compatible to the required tree structure. Therefore, it should be
 * created by createCompatibleTree() before.
 *
 * @param pTree The tree to which the file/directory is added.
 * @param pTransferInfo The transfer information associated with the tree.
 * @param pSettingsFile The file/directory to add.
 *
 * @throws edu.kit.lsdf.adalapi.exception.AdalapiException If pSettingsFile
 * cannot be accessed.// www.ja v a2  s.c  o m
 * @throws java.net.MalformedURLException If extracting the URL information
 * from pSettingsFile fails. This should never happen.
 */
public final static void addSettingsFile(IFileTree pTree, ITransferInformation pTransferInfo,
        File pSettingsFile) throws AdalapiException, MalformedURLException {
    ICollectionNode settingsNode = (ICollectionNode) CollectionUtils.find(pTree.getRootNode().getChildren(),
            new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    return Constants.STAGING_SETTINGS_FOLDER_NAME.equals(((IDataOrganizationNode) o).getName());
                }
            });

    if (settingsNode == null) {
        throw new IllegalArgumentException("Provided tree has an invalid structure. No '"
                + Constants.STAGING_SETTINGS_FOLDER_NAME + "' node found.");
    }

    IFileTree newTree = DataOrganizationUtils.createTreeFromFile(pTransferInfo.getDigitalObjectId(),
            new AbstractFile(pSettingsFile), pTransferInfo.getSettingsFolderUrl(), false);
    DataOrganizationUtils.merge(settingsNode, new LinkedList<ICollectionNode>(), newTree.getRootNode()
            .getChildren().toArray(new IDataOrganizationNode[newTree.getRootNode().getChildren().size()]));
}

From source file:edu.kit.dama.staging.util.DataOrganizationUtils.java

/**
 * Add pNodeToAdd to pNode. Before the node is added it is checked if there
 * is already a child of pNode with the name of pNodeToAdd. If there is a
 * IFileNode with the same name, pNodeToAdd is not added. If there is a
 * ICollectionNode with the same name, all children of pNodeToAdd are added
 * recursively using this method. The mentioned checks are then performed
 * for each node./* w w w  .  j  a  v a  2 s .  c om*/
 *
 * @param pNode To node to which a node is added.
 * @param pNodeToAdd The node to add.
 */
public static void addNode(ICollectionNode pNode, final IDataOrganizationNode pNodeToAdd) {
    IDataOrganizationNode result = (IDataOrganizationNode) CollectionUtils.find(pNode.getChildren(),
            new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    IDataOrganizationNode node = (IDataOrganizationNode) o;
                    if (o instanceof ICollectionNode && pNodeToAdd instanceof IFileNode) {
                        return false;
                    } else if (o instanceof IFileNode && pNodeToAdd instanceof ICollectionNode) {
                        return false;
                    } else {//node types are equal...check them
                        if (node.getName() != null) {
                            return node.getName().equals(pNodeToAdd.getName());
                        } else if (pNodeToAdd.getName() != null) {
                            return pNodeToAdd.getName().equals(node.getName());
                        }
                        //both are null
                        return true;
                    }
                }
            });

    if (result == null) {
        //no child with same name, just add the node
        pNode.addChild(pNodeToAdd);
    } else if (result instanceof ICollectionNode && pNodeToAdd instanceof ICollectionNode) {
        //child with same name found
        for (IDataOrganizationNode child : ((ICollectionNode) pNodeToAdd).getChildren()) {
            addNode((ICollectionNode) result, child);
        }
    }
}

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

@Test
public void testGetMetaClass_refresh() {
    MetadataContext metaContext = new MetadataContext();
    IMetadataService ms = repositoryService.getRepository("raptor-paas").getMetadataService();
    List<MetaClass> metas = ms.getMetaClasses(metaContext);
    Assert.assertEquals(34, metas.size());
    // force refresh
    metaContext.setRefreshMetadata(true);
    List<MetaClass> newMetas = ms.getMetaClasses(metaContext);
    Assert.assertEquals(34, newMetas.size());
    for (final MetaClass oldMeta : metas) {
        Object obj = CollectionUtils.find(newMetas, new Predicate() {
            @Override//  w  w  w  . j a  va  2  s  .co  m
            public boolean evaluate(Object object) {
                if (object == oldMeta) {
                    return true;
                }
                return false;
            }
        });
        Assert.assertNull(obj);
    }
    // cached get
    metaContext.setRefreshMetadata(false);
    List<MetaClass> new2metas = ms.getMetaClasses(metaContext);
    Assert.assertEquals(34, new2metas.size());
    for (final MetaClass newMeta : newMetas) {
        Object obj = CollectionUtils.find(new2metas, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                if (object == newMeta) {
                    return true;
                }
                return false;
            }
        });
        Assert.assertNotNull(obj);
    }
}