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

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

Introduction

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

Prototype

public boolean evaluate(T object);

Source Link

Document

Use the specified parameter to perform a test that returns true or false.

Usage

From source file:org.examproject.tweet.service.SimpleTagcrowdService.java

/**
 * update the entity./*from www.  j  a va2 s  .c o m*/
 */
@Override
public List<TagcrowdDto> update(TweetDto tweetDto) {
    LOG.debug("called.");
    try {
        Long statusId = Long.parseLong(tweetDto.getStatusId());
        String content = tweetDto.getText();
        String userName = tweetDto.getUserName();

        // get the korean word only.
        Predicate predicate = new IsContainKrHangulCodePredicate();
        boolean isNeed = predicate.evaluate(content);
        if (isNeed) {

            // split words from the sentence.
            Transformer transformer = new SentenceToWordsTransformer();
            String[] words = (String[]) transformer.transform(content);

            // process all words.
            for (int i = 0; i < words.length; i++) {
                String oneWord = words[i];
                boolean isKr = predicate.evaluate(oneWord);
                if (isKr) {

                    // get the vocab entity.
                    Vocab vocab = context.getBean(Vocab.class);

                    // get the word id.
                    List<Word> wordList = wordRepository.findByText(oneWord);

                    // if the new word.
                    if (wordList.isEmpty()) {

                        // create this word.
                        Word wordEntity = context.getBean(Word.class);
                        wordEntity.setText(oneWord);
                        Word newWordEntity = (Word) wordRepository.save(wordEntity);
                        vocab.setWord(newWordEntity);
                    }
                    // already exist.
                    else {
                        Word wordEntity = wordList.get(0);
                        vocab.setWord(wordEntity);
                    }

                    // set vocabulary this tweet!
                    Tweet tweet = tweetRepository.findById(statusId);
                    vocab.setStatus(tweet);
                    vocab.setName(userName);
                    vocabRepository.save(vocab);
                }
            }
        }

        // TODO: return tagcrowd dto list..
        List<TagcrowdDto> tagcrowdDtoList = null;
        return tagcrowdDtoList;
    } catch (Exception e) {
        LOG.error("an error occurred: " + e.getMessage());
        throw new RuntimeException(e);
    }
}

From source file:org.jasig.cas.CentralAuthenticationServiceImpl.java

/**
 * {@inheritDoc}/*from  ww  w . j  a  v  a2 s  .c om*/
 */
@Transactional(readOnly = true)
@Override
public Collection<Ticket> getTickets(final Predicate predicate) {
    final Collection<Ticket> c = new HashSet<>(this.ticketRegistry.getTickets());
    final Iterator<Ticket> it = c.iterator();
    while (it.hasNext()) {
        if (!predicate.evaluate(it.next())) {
            it.remove();
        }
    }
    return c;
}

From source file:org.jumpmind.db.platform.AbstractDdlBuilder.java

/**
 * Calls the given closure for all changes that are of one of the given
 * types, and then removes them from the changes collection.
 *
 * @param changes//from w w w.j a  va  2  s.  com
 *            The changes
 * @param changeTypes
 *            The types to search for
 * @param closure
 *            The closure to invoke
 */
protected void applyForSelectedChanges(Collection<IModelChange> changes, Class<?>[] changeTypes,
        final Closure closure) {
    final Predicate predicate = new MultiInstanceofPredicate(changeTypes);

    // basically we filter the changes for all objects where the above
    // predicate returns true, and for these filtered objects we invoke the
    // given closure
    CollectionUtils.filter(changes, new Predicate() {
        public boolean evaluate(Object obj) {
            if (predicate.evaluate(obj)) {
                closure.execute(obj);
                return false;
            } else {
                return true;
            }
        }
    });
}

From source file:org.lockss.config.ConfigManager.java

List getConfigGenerations(Collection urls, boolean required, boolean reload, String msg, KeyPredicate keyPred)
        throws IOException {

    if (urls == null)
        return Collections.EMPTY_LIST;
    List res = new ArrayList(urls.size());
    for (Object o : urls) {
        ConfigFile.Generation gen;/* w  ww. j  a v  a  2s.c o m*/
        if (o instanceof ConfigFile) {
            gen = getConfigGeneration((ConfigFile) o, required, reload, msg, keyPred);
        } else if (o instanceof LocalFileDescr) {
            LocalFileDescr lfd = (LocalFileDescr) o;
            String filename = lfd.getFile().toString();
            Predicate includePred = lfd.getIncludePredicate();
            if (includePred != null && !includePred.evaluate(filename)) {
                continue;
            }
            KeyPredicate pred = keyPred;
            if (lfd.getKeyPredicate() != null) {
                pred = lfd.getKeyPredicate();
            }
            gen = getConfigGeneration(filename, required, reload, msg, pred);
        } else {
            String url = o.toString();
            gen = getConfigGeneration(url, required, reload, msg, keyPred);
        }
        if (gen != null) {
            res.add(gen);
        }
    }
    return res;
}

From source file:org.lockss.protocol.IdentityManagerImpl.java

/**
 * Return a filtered collection of V3-style PeerIdentities.
 *///from  w w  w  .ja v  a2s .c o  m
public Collection getTcpPeerIdentities(Predicate peerPredicate) {
    Collection retVal = new ArrayList();
    for (PeerIdentity id : pidSet) {
        if (id.getPeerAddress() instanceof PeerAddress.Tcp && !id.isLocalIdentity()
                && peerPredicate.evaluate(id)) {
            retVal.add(id);
        }
    }
    return retVal;
}

From source file:org.lockss.servlet.ServeContent.java

boolean areAnyExcluded(Collection<ArchivalUnit> auList, Predicate pred) {
    for (ArchivalUnit au : auList) {
        if (!pred.evaluate(au)) {
            return true;
        }// www . j a va  2  s.  c o  m
    }
    return false;
}

From source file:org.lockss.servlet.ServeContent.java

boolean areAllExcluded(Collection<ArchivalUnit> auList, Predicate pred) {
    for (ArchivalUnit au : auList) {
        if (pred.evaluate(au)) {
            return false;
        }//w  ww .ja v  a2s  . c o  m
    }
    return true;
}

From source file:org.lockss.servlet.ServletUtil.java

public static Element manifestIndex(PluginManager pluginMgr, Collection<ArchivalUnit> aus, Predicate pred,
        String header, ManifestUrlTransform xform, boolean checkCollected) {
    Table tbl = new Table(AUSUMMARY_TABLE_BORDER, "cellspacing=\"4\" cellpadding=\"0\"");
    if (header != null) {
        tbl.newRow();/*w w  w  .  ja va2 s  .  co  m*/
        tbl.newCell("align=\"center\" colspan=\"3\"");
        tbl.add(header);
    }
    if (!pluginMgr.areAusStarted()) {
        tbl.newRow();
        tbl.newCell("align=\"center\" colspan=\"3\"");
        tbl.add(ServletUtil.notStartedWarning());
    }
    tbl.newRow();
    tbl.addHeading("Archival Unit", "align=left");
    tbl.newCell("width=8");
    tbl.add("&nbsp;");
    tbl.addHeading("Manifest", "align=left");
    for (ArchivalUnit au : aus) {
        if (pred != null && !pred.evaluate(au)) {
            continue;
        }
        tbl.newRow();
        tbl.newCell(ALIGN_LEFT);
        tbl.add(encodeText(au.getName()));
        tbl.newCell("width=8");
        tbl.add("&nbsp;");
        tbl.newCell(ALIGN_LEFT);
        Collection<String> urls = au.getStartUrls();
        for (Iterator uiter = urls.iterator(); uiter.hasNext();) {
            String url = (String) uiter.next();
            tbl.add(xform.transformUrl(url, au));
            if (checkCollected && !AuUtil.hasCrawled(au)) {
                tbl.add(" (not fully collected)");
            }
            if (uiter.hasNext()) {
                tbl.add("<br>");
            }
        }
    }
    return tbl;
}

From source file:org.mifos.reports.branchreport.persistence.BranchReportPersistenceIntegrationTest.java

private void assertListSizeAndTrueCondition(int resultCount, List retrievedReports, Predicate mustBeTrue) {
    Assert.assertEquals(resultCount, retrievedReports.size());
    Assert.assertTrue(mustBeTrue.evaluate(CollectionUtils.first(retrievedReports)));
}

From source file:org.objectstyle.cayenne.conf.Configuration.java

/**
 * @since 1.1//from w ww .  j a  v  a 2s . co  m
 */
public boolean loadDataView(DataView dataView, Predicate dataViewNameFilter) throws IOException {

    Validate.notNull(dataView, "DataView cannot be null.");

    if (dataViewLocations.size() == 0 || dataViewLocations.size() > 512) {
        return false;
    }

    if (dataViewNameFilter == null)
        dataViewNameFilter = Configuration.ACCEPT_ALL_DATAVIEWS;

    List viewXMLSources = new ArrayList(dataViewLocations.size());
    int index = 0;
    for (Iterator i = dataViewLocations.entrySet().iterator(); i.hasNext(); index++) {
        Map.Entry entry = (Map.Entry) i.next();
        String name = (String) entry.getKey();
        if (!dataViewNameFilter.evaluate(name))
            continue;
        String location = (String) entry.getValue();
        InputStream in = getViewConfiguration(location);
        if (in != null)
            viewXMLSources.add(in);
    }

    if (viewXMLSources.isEmpty())
        return false;

    dataView.load((InputStream[]) viewXMLSources.toArray(new InputStream[viewXMLSources.size()]));
    return true;
}