Example usage for org.apache.commons.collections Predicate Predicate

List of usage examples for org.apache.commons.collections Predicate Predicate

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:net.shopxx.entity.Goods.java

@Transient
public boolean getIsOutOfStock() {
    return CollectionUtils.exists(getProducts(), new Predicate() {
        public boolean evaluate(Object object) {
            Product product = (Product) object;
            return product != null && product.getIsOutOfStock();
        }//from w ww .j  a  v  a 2  s .  c o m
    });
}

From source file:jp.co.opentone.bsol.linkbinder.service.admin.impl.CorresponGroupServiceImpl.java

/**
 * ??????????./*w ww  .  j a v 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   www .j a v  a 2s. 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:ar.com.fdvs.dj.core.layout.AbstractLayoutManager.java

/**
 * Sets the columns width by reading some report options like the
 * printableArea and useFullPageWidth./*from   ww w . j  a  va  2  s .  c  om*/
 * columns with fixedWidth property set in TRUE will not be modified
 */
protected void setColumnsFinalWidth() {
    log.debug("Setting columns final width.");
    float factor = 1;
    int printableArea = report.getOptions().getColumnWidth();

    //Create a list with only the visible columns.
    List visibleColums = getVisibleColumns();

    if (report.getOptions().isUseFullPageWidth()) {
        int columnsWidth = 0;
        int notRezisableWidth = 0;

        //Store in a variable the total with of all visible columns
        for (Iterator iterator = visibleColums.iterator(); iterator.hasNext();) {
            AbstractColumn col = (AbstractColumn) iterator.next();
            columnsWidth += col.getWidth().intValue();
            if (col.getFixedWidth().booleanValue())
                notRezisableWidth += col.getWidth().intValue();
        }

        factor = (float) (printableArea - notRezisableWidth) / (float) (columnsWidth - notRezisableWidth);

        log.debug("printableArea = " + printableArea + ", columnsWidth = " + columnsWidth + ", columnsWidth = "
                + columnsWidth + ", notRezisableWidth = " + notRezisableWidth + ", factor = " + factor);

        int acumulated = 0;
        int colFinalWidth = 0;

        //Select the non-resizable columns
        Collection resizableColumns = CollectionUtils.select(visibleColums, new Predicate() {
            public boolean evaluate(Object arg0) {
                return !((AbstractColumn) arg0).getFixedWidth().booleanValue();
            }

        });

        //Finally, set the new width to the resizable columns
        for (Iterator iter = resizableColumns.iterator(); iter.hasNext();) {
            AbstractColumn col = (AbstractColumn) iter.next();

            if (!iter.hasNext()) {
                col.setWidth(new Integer(printableArea - notRezisableWidth - acumulated));
            } else {
                colFinalWidth = (new Float(col.getWidth().intValue() * factor)).intValue();
                acumulated += colFinalWidth;
                col.setWidth(new Integer(colFinalWidth));
            }
        }
    }

    // If the columns width changed, the X position must be setted again.
    int posx = 0;
    for (Iterator iterator = visibleColums.iterator(); iterator.hasNext();) {
        AbstractColumn col = (AbstractColumn) iterator.next();
        col.setPosX(new Integer(posx));
        posx += col.getWidth().intValue();
    }
}

From source file:net.sourceforge.fenixedu.domain.Teacher.java

public TeacherService getTeacherServiceByExecutionPeriod(final ExecutionSemester executionSemester) {
    return (TeacherService) CollectionUtils.find(getTeacherServicesSet(), new Predicate() {
        @Override//from www .  j a v a 2  s  .  c o 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();
        }//from w ww  .j  a v  a  2 s  . c o m
    });
}

From source file:net.sourceforge.fenixedu.domain.CurricularCourse.java

@SuppressWarnings("unchecked")
public boolean hasActiveScopeInGivenSemesterForCommonAndGivenBranch(final Integer semester,
        final Branch branch) {

    Collection<CurricularCourseScope> scopes = getScopesSet();

    List<CurricularCourseScope> result = (List<CurricularCourseScope>) CollectionUtils.select(scopes,
            new Predicate() {
                @Override//from  w ww  . j  ava2 s  .  c o  m
                public boolean evaluate(Object obj) {
                    CurricularCourseScope curricularCourseScope = (CurricularCourseScope) obj;
                    return ((curricularCourseScope.getBranch().getBranchType().equals(BranchType.COMNBR)
                            || curricularCourseScope.getBranch().equals(branch))
                            && curricularCourseScope.getCurricularSemester().getSemester().equals(semester)
                            && curricularCourseScope.isActive().booleanValue());
                }
            });

    return !result.isEmpty();
}

From source file:net.sourceforge.fenixedu.domain.Teacher.java

public Professorship getProfessorshipByExecutionCourse(final ExecutionCourse executionCourse) {
    return (Professorship) CollectionUtils.find(getProfessorships(), new Predicate() {
        @Override//from  w  ww .  ja  va  2  s  .c om
        public boolean evaluate(Object arg0) {
            Professorship professorship = (Professorship) arg0;
            return professorship.getExecutionCourse() == executionCourse;
        }
    });
}

From source file:net.shopxx.entity.Goods.java

@SuppressWarnings("unchecked")
@Transient//w w  w. ja va2  s  .c o  m
public Set<Promotion> getValidPromotions() {
    if (!Goods.Type.general.equals(getType()) || CollectionUtils.isEmpty(getPromotions())) {
        return Collections.emptySet();
    }

    return new HashSet<Promotion>(CollectionUtils.select(getPromotions(), new Predicate() {
        public boolean evaluate(Object object) {
            Promotion promotion = (Promotion) object;
            return promotion != null && promotion.hasBegun() && !promotion.hasEnded()
                    && CollectionUtils.isNotEmpty(promotion.getMemberRanks());
        }
    }));
}

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/* w  ww  .  j ava  2s.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);
    }
}