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

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

Introduction

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

Prototype

public static int countMatches(Collection inputCollection, Predicate predicate) 

Source Link

Document

Counts the number of elements in the input collection that match the predicate.

Usage

From source file:com.collective.celos.SerialSchedulingStrategy.java

@Override
public List<SlotState> getSchedulingCandidates(List<SlotState> states) {

    int slotsRunning = CollectionUtils.countMatches(states, RUNNING_PREDICATE);
    if (slotsRunning >= concurrencyLevel) {
        return Collections.emptyList();
    }/*from w ww .  j  a v a  2s. c  om*/

    @SuppressWarnings("unchecked")
    Collection<SlotState> candidates = CollectionUtils.select(states, CANDIDATE_PREDICATE);

    if (!candidates.isEmpty()) {
        int elemsToGet = Math.min(candidates.size(), concurrencyLevel - slotsRunning);
        return Lists.newArrayList(candidates).subList(0, elemsToGet);
    }

    return Collections.emptyList();
}

From source file:com.googelcode.jpractices.Person.java

/**
     * select's the Person object's from collection of person objects based on arg
     * @param propertyName - Person's attribute (firstName (or) lastName (or) salary )
     * @param value - Value to be compared to propertyName
     *//*from   w  w  w.ja v a 2 s . com*/
    void selectObjectsByName(String propertyName, String value) {
        EqualPredicate nameEqlPredicate = new EqualPredicate(value);
        BeanPredicate beanPredicate = new BeanPredicate(propertyName, nameEqlPredicate);
        Collection<Person> filteredCollection = CollectionUtils.select(personList, beanPredicate);
        System.out.println("Below are person object(s) whose " + propertyName + " is " + value);
        System.out
                .println("Matches for entered criteria " + CollectionUtils.countMatches(personList, beanPredicate));
        for (Person person : filteredCollection) {
            System.out.println(person);
        }
    }

From source file:com.jaspersoft.jasperserver.repository.test.RepositoryServiceDependentResourcesTest.java

@Test
public void shouldFindAllDependantReportsForDataSource() {
    assertNotNull("RepositoryService service is not wired.", getRepositoryService());
    assertNotNull("SearchCriteriaFactory service is not wired.", searchCriteriaFactory);

    String uri = "/datasources/JServerJNDIDS";

    List<ResourceLookup> resources = getRepositoryService().getDependentResources(null, uri,
            searchCriteriaFactory, 0, 20);

    assertEquals("Should find 9 dependant resources.", 9, resources.size());

    assertEquals("All resources should be lookup's.", 9,
            CollectionUtils.countMatches(resources, PredicateUtils.instanceofPredicate(ResourceLookup.class)));

    Collection types = CollectionUtils.collect(resources,
            TransformerUtils.invokerTransformer("getResourceType"));

    assertEquals("All lookup's should have type ReportUnit.", 9,
            CollectionUtils.countMatches(types, PredicateUtils.equalPredicate(
                    "com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportUnit")));

    String sortOrder = ArrayUtils.toString(
            CollectionUtils.collect(resources, TransformerUtils.invokerTransformer("getURIString")).toArray());

    assertEquals("Resources should be sorted in order.", expectedOrder, sortOrder);
}

From source file:BackupRestoreTest.java

private static void checkRestoreTo(final String passwordData, final String passwordMeta,
        final Collection<String> repoPatern, List<String> argList) throws Exception {
    CipherProvider dataCipherProvider = new CipherProvider();
    dataCipherProvider.setPassword(passwordData);
    CipherProvider metaCipherProvider = new CipherProvider();
    metaCipherProvider.setPassword(passwordMeta);

    String repoPathStr = REPO_TST;
    Repository repository = new Repository(repoPathStr, dataCipherProvider, metaCipherProvider);

    VOConfig cfg = new VOConfig(REPO_TST, ID_BCK_TST, getExcl("*.excl"), getExcl("*Excl"), argList);

    BackupService backup = new BackupService(cfg, repository);
    final String bck = backup.run();

    // check repo content
    List<String> contentRepo = getContentDir(REPO_TST + File.separator + "data", false);
    printContent(contentRepo);//from   w  w  w  . jav a  2  s . co  m
    checkCollectionIn(repoPatern, contentRepo);

    RestoreService restore = new RestoreService(bck, repository, argList, RESTORE_TST);
    restore.run();

    // check new dir content
    List<String> contentRestore = getContentDir(RESTORE_TST, false);
    // TODO Lebeda - do check with date - on source tst files must be dat prepared on setup test
    printContent(contentRestore);
    Assert.assertEquals(16, contentRestore.size());
    Assert.assertTrue(0 == CollectionUtils.countMatches(contentRestore, new Predicate() {
        @Override
        public boolean evaluate(final Object object) {
            String s = (String) object;
            return StringUtils.contains(s, "excl");
        }
    }));
    Assert.assertTrue(CollectionUtils.isSubCollection(getContentRestorePatern(), contentRestore));
}

From source file:com.jaspersoft.jasperserver.repository.test.RepositoryServiceDependentResourcesTest.java

@Test
public void shouldFindFirstFiveDependantReportsForDataSource() {
    assertNotNull("RepositoryService service is not wired.", getRepositoryService());
    assertNotNull("SearchCriteriaFactory service is not wired.", searchCriteriaFactory);

    String uri = "/datasources/JServerJNDIDS";

    List<ResourceLookup> resources = getRepositoryService().getDependentResources(null, uri,
            searchCriteriaFactory, 0, 5);

    assertEquals("Should find 5 dependant resources.", 5, resources.size());

    assertEquals("All resources should be lookup's.", 5,
            CollectionUtils.countMatches(resources, PredicateUtils.instanceofPredicate(ResourceLookup.class)));

    String sortOrder = ArrayUtils.toString(
            CollectionUtils.collect(resources, TransformerUtils.invokerTransformer("getURIString")).toArray());

    assertEquals("Resources should be sorted in order.", expectedOrderForTopFive, sortOrder);

}

From source file:org.opencastproject.serviceregistry.impl.jmx.HostsStatistics.java

/**
 * @see org.opencastproject.serviceregistry.impl.jmx.HostsStatisticsMXBean#getOnlineCount()
 *//* ww w. j a v  a2s.  c  o  m*/
@Override
public int getOnlineCount() {
    return CollectionUtils.countMatches(hosts.values(), PredicateUtils.equalPredicate(ONLINE));
}

From source file:org.opencastproject.serviceregistry.impl.jmx.HostsStatistics.java

/**
 * @see org.opencastproject.serviceregistry.impl.jmx.HostsStatisticsMXBean#getOfflineCount()
 *//*from   ww  w  . ja va 2s  .c  om*/
@Override
public int getOfflineCount() {
    return CollectionUtils.countMatches(hosts.values(), PredicateUtils.equalPredicate(OFFLINE));
}

From source file:org.opencastproject.serviceregistry.impl.jmx.HostsStatistics.java

/**
 * @see org.opencastproject.serviceregistry.impl.jmx.HostsStatisticsMXBean#getInMaintenanceCount()
 */// w  ww .ja v  a2 s . c  om
@Override
public int getInMaintenanceCount() {
    return CollectionUtils.countMatches(hosts.values(), PredicateUtils.equalPredicate(MAINTENANCE));
}

From source file:org.opencastproject.serviceregistry.impl.jmx.ServicesStatistics.java

/**
 * @see org.opencastproject.serviceregistry.impl.jmx.ServicesStatisticsMXBean#getNormalServiceCount()
 *//*from   w w w  . j ava2 s  .  c  o m*/
@Override
public int getNormalServiceCount() {
    return CollectionUtils.countMatches(services.values(), PredicateUtils.equalPredicate(ServiceState.NORMAL));
}

From source file:org.opencastproject.serviceregistry.impl.jmx.ServicesStatistics.java

/**
 * @see org.opencastproject.serviceregistry.impl.jmx.ServicesStatisticsMXBean#getWarningServiceCount()
 *//*from w  w  w  . j  ava2  s . c  o  m*/
@Override
public int getWarningServiceCount() {
    return CollectionUtils.countMatches(services.values(), PredicateUtils.equalPredicate(ServiceState.WARNING));
}