List of usage examples for org.apache.commons.collections CollectionUtils find
public static Object find(Collection collection, Predicate predicate)
From source file:jp.co.opentone.bsol.linkbinder.service.admin.impl.CorresponGroupServiceImpl.java
/** * ??????????.//from w ww . j av a 2s. c o m * @param users * @throws ServiceAbortException ??????? */ private void validateUserProjectDiff(List<User> users) throws ServiceAbortException { String projectId = getCurrentProjectId(); SearchUserCondition condition = new SearchUserCondition(); condition.setProjectId(projectId); List<ProjectUser> projectUsers = 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.app.util.browser.BrowserSniffer.java
private void sniffBrowser() throws Exception { // eg: Camino/0.7 // [0] = Camino/0.7 // [1] = Camino // [2] = 0//from ww w. j a v a2s. co m // [3] = .7 ArrayList matches = getMatches(BrowserTypePat, ua, 4); if (matches.isEmpty()) return; // first find out whether it's msie hiding behind many different doors... String[] browserParticulars = (String[]) CollectionUtils.find(matches, new Predicate() { public boolean evaluate(Object arg0) { final String[] pieces = (String[]) arg0; for (int i = 0; i < pieces.length; i++) { final String piece = pieces[i]; if (StringUtils.contains(piece, MSIE_ID)) { return true; } } return false; } }); // if it's not msie but test for Opera because it can identify itself as msie... if (browserParticulars == null) { // get the position of the last browser key found int count = matches.size() - 1; browserParticulars = (String[]) matches.get(count); } longName = browserParticulars[0]; browserName = browserParticulars[1]; // get browserName from string Matcher nameMatcher = NameOnlyPat.matcher(browserName); if (nameMatcher.matches()) { browserName = nameMatcher.group(nameMatcher.groupCount()); } majorVersion = browserParticulars[2]; // parse the minor version string and look for alpha chars if (browserParticulars[3] != null) { // eg: .7b // [0] = .7b // [1] = .7 // [2] = b matches = getMatches(MinorVersionPat, browserParticulars[3], 3); if (matches.isEmpty()) return; int count = matches.size() - 1; browserParticulars = (String[]) matches.get(count); if (browserParticulars[1] != null) minorVersion = browserParticulars[1]; else minorVersion = ".0"; if (PunctuationOnlyPat.matcher(minorVersion).matches()) minorVersion = StringUtils.EMPTY; if (browserParticulars[2] != null && !PunctuationOnlyPat.matcher(browserParticulars[2]).matches()) revisionVersion = browserParticulars[2]; } }
From source file:net.sourceforge.fenixedu.domain.Teacher.java
public TeacherService getTeacherServiceByExecutionPeriod(final ExecutionSemester executionSemester) { return (TeacherService) CollectionUtils.find(getTeacherServicesSet(), new Predicate() { @Override/*from w w w.j av a 2 s.co m*/ public boolean evaluate(Object arg0) { TeacherService teacherService = (TeacherService) arg0; return teacherService.getExecutionPeriod() == executionSemester; } }); }
From source file:net.shopxx.entity.Goods.java
@Transient public Product getDefaultProduct() { return (Product) CollectionUtils.find(getProducts(), new Predicate() { public boolean evaluate(Object object) { Product product = (Product) object; return product != null && product.getIsDefault(); }/* w w w . j a v a2s . co m*/ }); }
From source file:net.sourceforge.fenixedu.domain.Teacher.java
public Professorship getProfessorshipByExecutionCourse(final ExecutionCourse executionCourse) { return (Professorship) CollectionUtils.find(getProfessorships(), new Predicate() { @Override//from www.jav a 2s. c o m public boolean evaluate(Object arg0) { Professorship professorship = (Professorship) arg0; return professorship.getExecutionCourse() == executionCourse; } }); }
From source file:net.sourceforge.fenixedu.domain.Enrolment.java
private void createAttendForImprovement(final ExecutionSemester executionSemester) { final Registration registration = getRegistration(); // FIXME this is completly wrong, there may be more than one execution // course for this curricular course ExecutionCourse currentExecutionCourse = (ExecutionCourse) CollectionUtils .find(getCurricularCourse().getAssociatedExecutionCoursesSet(), new Predicate() { @Override//www . j av a 2 s . c o m final public boolean evaluate(Object arg0) { ExecutionCourse executionCourse = (ExecutionCourse) arg0; if (executionCourse.getExecutionPeriod().equals(executionSemester) && executionCourse.getEntryPhase().equals(EntryPhase.FIRST_PHASE)) { return true; } return false; } }); if (currentExecutionCourse != null) { Collection attends = currentExecutionCourse.getAttendsSet(); Attends attend = (Attends) CollectionUtils.find(attends, new Predicate() { @Override public boolean evaluate(Object arg0) { Attends attend = (Attends) arg0; if (attend.getRegistration().equals(registration)) { return true; } return false; } }); if (attend == null) { attend = getStudent().getAttends(currentExecutionCourse); if (attend != null) { attend.setRegistration(registration); } else { attend = new Attends(registration, currentExecutionCourse); } } attend.setEnrolment(this); } }
From source file:edu.kit.dama.staging.util.DataOrganizationUtils.java
/** * Check if the EXISTS flag is set as attribute of the provided node. * * @param pNode The node to check./*from www. j av a2s . co m*/ * * @return TRUE = EXISTS is set TRUE. */ public static boolean directoryExists(ICollectionNode pNode) { IAttribute attribute = (IAttribute) CollectionUtils.find(pNode.getAttributes(), new Predicate() { @Override public boolean evaluate(Object o) { return ((IAttribute) o).getKey().equals(EXISTS); } }); return (attribute != null && Boolean.parseBoolean(attribute.getValue())); }
From source file:com.lp.server.artikel.ejbfac.WebshopItemServiceEjb.java
private ShopgroupsResult getShopGroupsFindIdChangedImpl(WebshopAuthHeader header, Integer shopgruppeIId, Timestamp changedStamp, String searchKey) { if (!existsShopgroupIIdForWebshopIId(shopgruppeIId)) return new ShopgroupsResult(BaseRequestResult.ERROR_NOT_FOUND, searchKey); try {// ww w . j av a 2s . com ShopgroupsResult sgResult = new ShopgroupsResult(); List<Shopgruppe> changedShopgruppen = new ArrayList<Shopgruppe>(); Collection<Shopgruppe> childs = queryChildShopgruppen(shopgruppeIId); for (Shopgruppe shopgruppe : childs) { if (haveChangedWithChildShopgruppen(shopgruppe, changedStamp)) { changedShopgruppen.add(shopgruppe); } } if (childs.size() == 0) { Shopgruppe me = em.find(Shopgruppe.class, shopgruppeIId); if (me != null) { changedShopgruppen.add(me); } } for (Shopgruppe shopgruppe : changedShopgruppen) { Object o = CollectionUtils.find(sgResult.getShopgroups(), new ShopgruppeIdPredicate(shopgruppeIId)); if (o == null) { ShopgruppeDto rootShopDto = getArtikelFac().shopgruppeFindByPrimaryKey(shopgruppe.getIId(), webClientDto); WebshopShopgroup node = buildWebshopgroup(rootShopDto, changedStamp); sgResult.getShopgroups().add(node); } } sgResult.setOkay(); return sgResult; } catch (RemoteException ex) { return new ShopgroupsResult(BaseRequestResult.ERROR_RMI_EXCEPTION, ex.getMessage()); } catch (EJBExceptionLP ex) { return new ShopgroupsResult(BaseRequestResult.ERROR_EJB_EXCEPTION + ex.getCode(), searchKey); } }
From source file:edu.kit.dama.staging.util.DataOrganizationUtils.java
/** * Check if the TRANSFERRED flag is set as attribute of the provided node. * * @param pNode The node to check./*from ww w .j a v a 2 s . c om*/ * * @return TRUE = TRANSFERRED is set TRUE. */ public static boolean isFileTransferred(IFileNode pNode) { IAttribute attribute = (IAttribute) CollectionUtils.find(pNode.getAttributes(), new Predicate() { @Override public boolean evaluate(Object o) { return ((IAttribute) o).getKey().equals(TRANSFERRED); } }); return (attribute != null && Boolean.parseBoolean(attribute.getValue())); }
From source file:edu.kit.dama.staging.util.DataOrganizationUtils.java
/** * Mark the provided IFileNode as TRANSFERRED. Basically, an attribute * TRANSFERRED with the value 'TRUE' is added. This feature is needed for * the KIT Data Manager data transfer./* www . j ava 2 s .c om*/ * * @param pNode The tree node which should be marked as TRANSFERRED. */ public static void markFileTransferred(IFileNode pNode) { IAttribute attribute = (IAttribute) CollectionUtils.find(pNode.getAttributes(), new Predicate() { @Override public boolean evaluate(Object o) { return ((IAttribute) o).getKey().equals(TRANSFERRED); } }); if (attribute == null) { pNode.addAttribute(new AttributeImpl(TRANSFERRED, Boolean.TRUE.toString())); } else { attribute.setValue(Boolean.TRUE.toString()); } }