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:org.squashtest.tm.web.internal.controller.testcase.steps.TestStepViewFromExecBuilder.java

private ExecutionStep findExistingStep(ExecutionStep execStep) {

    Execution exec = execStep.getExecution();
    List<ExecutionStep> execSteps = new ArrayList<>(exec.getSteps());
    int stepIndex = exec.getStepIndex(execStep.getId());
    List<ExecutionStep> after = execSteps.subList(stepIndex, execSteps.size());

    // search for next existing step
    ExecutionStep result = (ExecutionStep) CollectionUtils.find(after, TestStepViewFromExec.NOT_DELETED);

    // if no step exist next, search the nearest previous step that still exist
    if (result == null) {
        List<ExecutionStep> before = execSteps.subList(0, stepIndex);
        // reverse the list so the first element found is the nearest
        Collections.reverse(before);
        result = (ExecutionStep) CollectionUtils.find(before, TestStepViewFromExec.NOT_DELETED);
    }/*from   www. j a va 2s . c om*/

    return result;
}

From source file:org.teama.AppListDA.java

static public App getApp(final int id) {
    if (appList == null)
        load();/* w w  w  . j a v  a 2s .c o  m*/

    if (appList != null) {
        /* Use collectionUtils to find the matching App from the list */
        return (App) CollectionUtils.find(appList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                App a = (App) o;
                return a.getAppId() == id;
            }
        });
    } else {
        return null;
    }
}

From source file:org.teama.IssueListDA.java

static public Issue getIssue(final int id) {
    if (issueList != null) {
        /* Use collectionUtils to find the matching App from the list */
        return (Issue) CollectionUtils.find(issueList, new Predicate() {
            @Override/* ww  w. java  2s. co m*/
            public boolean evaluate(Object o) {
                Issue i = (Issue) o;
                return i.getIssueId() == id;
            }
        });
    } else {
        return null;
    }
}

From source file:org.teama.PriorityListDA.java

static public Priority getPriority(final int id) {
    if (priorityList == null)
        load();/*from   w ww  . j  a v  a2s  .co  m*/

    if (priorityList != null) {
        /* Use collectionUtils to find the matching App from the list */
        return (Priority) CollectionUtils.find(priorityList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                Priority p = (Priority) o;
                return p.getPriorityId() == id;
            }
        });
    } else {
        return null;
    }
}

From source file:org.teama.StatusListDA.java

static public Status getStatus(final int id) {
    if (statusList == null)
        load();/*from  w  ww.j ava 2 s  .c o  m*/

    if (statusList != null) {
        /* Use collectionUtils to find the matching App from the list */
        return (Status) CollectionUtils.find(statusList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                Status s = (Status) o;
                return s.getStatusId() == id;
            }
        });
    } else {
        return null;
    }
}

From source file:org.teama.UserListDA.java

static public User getUser(final int id) {
    if (userList == null)
        load();/*from  w  w w.jav  a  2  s .  c  om*/

    if (userList != null) {
        /* Use collectionUtils to find the matching App from the list */
        return (User) CollectionUtils.find(userList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                User u = (User) o;
                return u.getIdUser() == id;
            }
        });
    } else {
        return null;
    }
}

From source file:org.teama.UserListDA.java

static public User getUser(final String email) {
    if (userList == null)
        load();/*from  w w w .  j a  v  a 2 s. com*/

    if (userList != null) {
        /* Use collectionUtils to find the matching App from the list */
        return (User) CollectionUtils.find(userList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                User u = (User) o;
                return u.getEmailAddress().equals(email);
            }
        });
    } else {
        return null;
    }
}

From source file:org.tonguetied.datatransfer.exporting.LanguageCentricProcessor.java

/**
 * Find an existing {@link KeywordByLanguage} item based on criteria 
 * provided in the <code>translation<code> parameter. If no match is 
 * found <code>null</code> is returned. 
 * //ww  w .j  a  v  a2s  .  c  o m
 * @param results the list of {@link KeywordByLanguage} items to search
 * @param translation the {@link Translation} object used to construct the
 * search criteria
 * @return the first item matching the criteria, or <code>null</code> if no
 * match is found
 * 
 * @see LanguagePredicate
 */
private KeywordByLanguage findItem(List<KeywordByLanguage> results, Translation translation) {
    Predicate predicate = new LanguagePredicate(translation.getKeyword().getKeyword(),
            translation.getKeyword().getContext(), translation.getBundle(), translation.getCountry());

    return (KeywordByLanguage) CollectionUtils.find(results, predicate);
}

From source file:org.tonguetied.datatransfer.importing.AbstractPropertiesImporter.java

/**
 * Find a translation from an existing keyword that matches the business 
 * keys./*from ww w.j  a  v a  2s .  com*/
 * 
 * @param keyword the existing keyword to search
 * @return the matching translation or <code>null</code> if no match is 
 * found
 */
private Translation findTranslation(final Keyword keyword) {
    Translation translation = null;
    if (!keyword.getTranslations().isEmpty()) {
        final Predicate predicate = new TranslationPredicate(getBundle(), getCountry(), getLanguage());
        translation = (Translation) CollectionUtils.find(keyword.getTranslations(), predicate);
    }

    return translation;
}

From source file:org.tonguetied.datatransfer.importing.CsvImporter.java

/**
 * Add or update a translation for a keyword.
 * /*from  w  w  w  . j  av a  2 s  .  c  o  m*/
 * @param keyword the current {@link Keyword}
 * @param language the current {@link Language}
 * @param country the current {@link Country}
 * @param bundle the current {@link Bundle}
 * @param translationState the {@link TranslationState} for the translation
 * @param value the value of the translation
 */
private void updateTranslation(Keyword keyword, final Language language, final Country country,
        final Bundle bundle, final TranslationState translationState, final String value) {
    Predicate predicate = new TranslationPredicate(bundle, country, language);
    Translation translation = (Translation) CollectionUtils.find(keyword.getTranslations(), predicate);

    if (translation == null) {
        keyword.addTranslation(
                new Translation(bundle, country, language, evaluateValue(value), translationState));
    } else {
        translation.setState(translationState);
        translation.setValue(evaluateValue(value));
    }
}