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.service.impl.SpecificationItemServiceImpl.java

public void filter(List<SpecificationItem> specificationItems) {
    CollectionUtils.filter(specificationItems, new Predicate() {
        public boolean evaluate(Object object) {
            SpecificationItem specificationItem = (SpecificationItem) object;
            if (specificationItem == null || StringUtils.isEmpty(specificationItem.getName())) {
                return false;
            }/*w ww.j av a 2 s .  com*/
            CollectionUtils.filter(specificationItem.getEntries(), new Predicate() {
                private Set<Integer> idSet = new HashSet<Integer>();
                private Set<String> valueSet = new HashSet<String>();

                public boolean evaluate(Object object) {
                    SpecificationItem.Entry entry = (SpecificationItem.Entry) object;
                    return entry != null && entry.getId() != null && StringUtils.isNotEmpty(entry.getValue())
                            && entry.getIsSelected() != null && idSet.add(entry.getId())
                            && valueSet.add(entry.getValue());
                }
            });
            return CollectionUtils.isNotEmpty(specificationItem.getEntries()) && specificationItem.isSelected();
        }
    });
}

From source file:com.newlandframework.avatarmq.consumer.ConsumerContext.java

public static int getClustersStat(String clusters) {

    Predicate predicate = new Predicate() {
        public boolean evaluate(Object object) {
            String clustersId = ((ClustersState) object).getClusters();
            return clustersId.compareTo(clusters) == 0;
        }//from  w w w  .  jav  a2  s. c  o m
    };

    Iterator iterator = new FilterIterator(stateArray.iterator(), predicate);

    ClustersState state = null;
    while (iterator.hasNext()) {
        state = (ClustersState) iterator.next();
        break;

    }
    return (state != null) ? state.getState() : 0;
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.resourceAllocationManager.RemoverTurno.java

@Atomic
public static Object run(final InfoShift infoShift, final InfoClass infoClass) {
    check(RolePredicates.RESOURCE_ALLOCATION_MANAGER_PREDICATE);
    final Shift shift = FenixFramework.getDomainObject(infoShift.getExternalId());
    if (shift == null) {
        return Boolean.FALSE;
    }//from ww w . j a va  2s.  co  m
    final SchoolClass schoolClass = (SchoolClass) CollectionUtils.find(shift.getAssociatedClassesSet(),
            new Predicate() {
                @Override
                public boolean evaluate(Object arg0) {
                    final SchoolClass schoolClass = (SchoolClass) arg0;
                    return schoolClass.getExternalId().equals(infoClass.getExternalId());
                }
            });
    if (schoolClass == null) {
        return Boolean.FALSE;
    }
    shift.getAssociatedClassesSet().remove(schoolClass);
    return Boolean.TRUE;
}

From source file:controllers.BranchApp.java

@IsAllowed(Operation.READ)
public static Result branches(String loginId, String projectName) throws IOException, GitAPIException {
    Project project = Project.findByOwnerAndProjectName(loginId, projectName);
    GitRepository gitRepository = new GitRepository(project);
    List<GitBranch> allBranches = gitRepository.getBranches();
    final GitBranch headBranch = gitRepository.getHeadBranch();

    // filter the head branch from all branch list.
    CollectionUtils.filter(allBranches, new Predicate() {
        @Override//from   www .  ja  va 2s . c  om
        public boolean evaluate(Object o) {
            GitBranch gitBranch = (GitBranch) o;
            return !gitBranch.getName().equals(headBranch.getName());
        }
    });

    return ok(branches.render(project, allBranches, headBranch));
}

From source file:com.codenjoy.dojo.tetris.model.TestUtils.java

public static void assertContainsPlot(final int x, final int y, List<Plot> plots) {
    Object foundPlot = CollectionUtils.find(plots, new Predicate() {
        @Override//from  ww  w .  jav a2 s  . co m
        public boolean evaluate(Object object) {
            Plot plot = (Plot) object;
            return plot.getX() == x && plot.getY() == y;
        }
    });
    assertNotNull("Plot with coordinates (" + x + "," + y + ") not found", foundPlot);
}

From source file:com.cognifide.cq.cqsm.core.scripts.ScriptFilters.java

public static Predicate filterByExecutionMode(final List<ExecutionMode> modes) {
    return new Predicate() {
        @Override/*from www .ja v  a 2s  . c om*/
        public boolean evaluate(Object o) {
            return modes.contains(((Script) o).getExecutionMode());
        }
    };
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.RemoveProfessorshipWithPerson.java

@Atomic
public static Boolean run(Person person, ExecutionCourse executionCourse) throws NotAuthorizedException {
    AbstractModifyProfessorshipWithPerson.run(person);

    Professorship professorshipToDelete = person.getProfessorshipByExecutionCourse(executionCourse);

    Collection shiftProfessorshipList = professorshipToDelete.getAssociatedShiftProfessorshipSet();

    boolean hasCredits = false;

    if (!shiftProfessorshipList.isEmpty()) {
        hasCredits = CollectionUtils.exists(shiftProfessorshipList, new Predicate() {

            @Override// w  w w .j  a  va  2 s . co  m
            public boolean evaluate(Object arg0) {
                ShiftProfessorship shiftProfessorship = (ShiftProfessorship) arg0;
                return shiftProfessorship.getPercentage() != null && shiftProfessorship.getPercentage() != 0;
            }
        });
    }

    if (!hasCredits) {
        professorshipToDelete.delete();
    } else {
        if (hasCredits) {
            throw new DomainException("error.remove.professorship");
        }
    }
    return Boolean.TRUE;
}

From source file:com.redhat.rhn.frontend.security.BaseAuthenticationService.java

protected boolean requestURIRequiresAuthentication(final HttpServletRequest request) {
    return !CollectionUtils.exists(getUnprotectedURIs(), new Predicate() {
        public boolean evaluate(Object uri) {
            return request.getRequestURI().startsWith(uri.toString());
        }//from w w w. j  a v a  2s  .  c om
    });
}

From source file:gov.nih.nci.caarray.domain.permissions.SampleSecurityLevel.java

/**
 * @return the list of SecurityLevels that are available to the public access profile
 *///from www. j a v  a2 s . c om
public static List<SampleSecurityLevel> publicLevels() {
    List<SampleSecurityLevel> levels = new ArrayList<SampleSecurityLevel>(
            Arrays.asList(SampleSecurityLevel.values()));
    CollectionUtils.filter(levels, new Predicate() {
        public boolean evaluate(Object o) {
            return ((SampleSecurityLevel) o).isAvailableToPublic();
        }
    });
    return levels;
}

From source file:io.wcm.wcm.ui.extjs.provider.impl.servlets.DummyPredicateProvider.java

@Override
public Predicate getPredicate(String name) {
    if (StringUtils.equals(name, PREDICATE_PAGENAME_PAGE1)) {
        return new Predicate() {

            @Override//from   ww  w .  ja  va  2s . c o m
            public boolean evaluate(Object object) {
                Page page = (Page) object;
                return StringUtils.equals(page.getName(), "page1");
            }
        };
    }
    return null;
}