Example usage for java.util List subList

List of usage examples for java.util List subList

Introduction

In this page you can find the example usage for java.util List subList.

Prototype

List<E> subList(int fromIndex, int toIndex);

Source Link

Document

Returns a view of the portion of this list between the specified fromIndex , inclusive, and toIndex , exclusive.

Usage

From source file:org.wallerlab.yoink.regionizer.service.NumberRegionizer.java

private void checkCriteria(Region qmAdaptiveRegion, Region bufferRegion,
        Map<Molecule, Double> distanceAndMoleculeSequence, int qmNumber, int bufferNumber) {
    // only use the molecules.
    List<Molecule> moleculeSequence = new ArrayList<Molecule>(distanceAndMoleculeSequence.keySet());
    // take the first n number of molecules as adaptive qm
    List<Molecule> adaptiveQMMolecules = moleculeSequence.subList(0, qmNumber);
    for (Molecule molecule : adaptiveQMMolecules) {
        qmAdaptiveRegion.addMolecule(molecule, molecule.getIndex());
    }/* ww w. ja v a 2 s  .  c o  m*/
    List<Molecule> bufferMolecules = moleculeSequence.subList(qmNumber, bufferNumber);
    for (Molecule molecule : bufferMolecules) {
        bufferRegion.addMolecule(molecule, molecule.getIndex());
    }
}

From source file:org.lightadmin.core.web.RepositoryScopedSearchController.java

private Page<?> selectPage(List<Object> items, Pageable pageable) {
    final List<Object> itemsOnPage = items.subList(pageable.getOffset(),
            Math.min(items.size(), pageable.getOffset() + pageable.getPageSize()));

    return new PageImpl(itemsOnPage, pageable, items.size());
}

From source file:de.tudarmstadt.ukp.dkpro.core.ngrams.util.NGramStringIterable.java

private List<String> getNGrams(List<String> tokenList, int k) {
    List<String> nGrams = new ArrayList<String>();

    int size = tokenList.size();
    for (int i = 0; i < (size + 1 - k); i++) {
        nGrams.add(StringUtils.join(tokenList.subList(i, i + k), ' '));
    }//from  w  ww  . ja v a  2s.  com

    return nGrams;
}

From source file:com.music.scheduled.PieceDigestSendingJob.java

@Scheduled(cron = "0 0 9 ? * 1,4")
@Transactional(readOnly = true)//from w w  w . ja  va  2  s . c o m
public void sendPieceDigestEmails() {
    logger.info("Sending email digests started");
    DateTime now = new DateTime();
    DateTime minusTwoDays = now.minusDays(2);
    List<Piece> pieces = pieceDao.getPiecesInRange(minusTwoDays, now);
    Collections.shuffle(pieces);
    final List<Piece> includedPieces = new ArrayList<>(pieces.subList(0, Math.min(pieces.size(), 3)));
    if (includedPieces.isEmpty()) {
        return;
    }
    // for now - using the same data for all users. TODO send personalized selection
    final EmailDetails baseDetails = new EmailDetails();
    baseDetails.setMessageTemplate("digest.vm");
    baseDetails.setSubject("Computoser-generated tracks digest for you");
    Map<String, Object> model = Maps.newHashMap();
    baseDetails.setMessageTemplateModel(model);
    baseDetails.setFrom(from);
    baseDetails.setHtml(true);
    userDao.performBatched(User.class, 100, new PageableOperation<User>() {
        @Override
        public void execute() {
            for (User user : getData()) {
                if (user.isReceiveDailyDigest() && StringUtils.isNotBlank(user.getEmail())) {
                    EmailDetails email = SerializationUtils.clone(baseDetails);
                    email.setTo(user.getEmail());
                    email.setCurrentUser(user);
                    String hmac = SecurityUtils.hmac(user.getEmail(), hmacKey);
                    email.getMessageTemplateModel().put("pieces", includedPieces);
                    email.getMessageTemplateModel().put("hmac", hmac);
                    // needed due to SES restrictions
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        throw new IllegalStateException(e);
                    }
                    emailService.send(email);
                }
            }
        }
    });
}

From source file:es.udc.gii.common.eaf.plugin.multiobjective.remainingfront.NSGA2RemainingFrontSelection.java

@Override
public List<NSGA2Individual> selection(EvolutionaryAlgorithm alg, List<NSGA2Individual> newPop,
        List<NSGA2Individual> front, int size) {

    NSGA2Algorithm nsga2 = (NSGA2Algorithm) alg;

    nsga2.getParametersPlugin().calculateParameters(front);

    Collections.sort(front, new CrowdingDistanceComparator<NSGA2Individual>());
    newPop.addAll(front.subList(0, size));

    return newPop;
}

From source file:cloudlens.engine.CLBuilder.java

private static List<CLElement> getElements(List<CLElement> elements) {
    final List<CLElement> res = new ArrayList<>();
    int i = 0;/*w ww.j  av a  2  s.  c  o  m*/
    while (i < elements.size() && !blockGuard) {
        final CLElement child = elements.get(i++);
        switch (child.ast.type) {
        case Block:
            res.add(child);
            blockGuard = true;
            break;
        case Process:
        case After:
        case Match:
        case Source:
            res.add(child);
            break;
        case Run:
            final CLElement run = child;
            final List<CLElement> runElements = getElements(run.children);
            res.addAll(runElements);
            break;
        case Declaration:
        case Lens:
            final CLElement dl = child;
            final List<CLElement> lensElements = getElements(dl.children);
            res.addAll(lensElements);
            break;
        }
    }
    nextList.addAll(elements.subList(i, elements.size()));
    return res;
}

From source file:edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup.java

private RevisionInfoBean parseRevisionInformation(List<String> lines) throws ParseException {
    checkValidNumberOfLines(lines);//from ww  w  . j a v  a 2 s.c o m
    String dateLine = lines.get(0);
    List<String> levelLines = lines.subList(1, lines.size());

    Date buildDate = parseDateLine(dateLine);
    List<LevelRevisionInfo> levelInfos = parseLevelLines(levelLines);
    return new RevisionInfoBean(buildDate, levelInfos);
}

From source file:mtsar.processors.task.InverseCountAllocator.java

@Override
@Nonnull//w w w.  j  a va  2s. c  o m
public Optional<TaskAllocation> allocate(@Nonnull Worker worker, @Nonnegative int n) {
    requireNonNull(stage, "the stage provider should not provide null");
    final Set<Integer> answered = answerDAO.listForWorker(worker.getId(), stage.getId()).stream()
            .map(Answer::getTaskId).collect(Collectors.toSet());

    final Map<Integer, Integer> counts = countDAO.getCountsSQL(stage.getId()).stream()
            .filter(pair -> !answered.contains(pair.getKey()))
            .collect(Collectors.toMap(Pair::getKey, Pair::getValue));

    final List<Integer> ids = filterTasks(counts);
    final int taskRemaining = ids.size();

    if (ids.isEmpty())
        return Optional.empty();
    if (taskRemaining > n)
        ids.subList(n, ids.size()).clear();
    final List<Task> tasks = taskDAO.select(ids, stage.getId());

    final int taskCount = taskDAO.count(stage.getId());
    final TaskAllocation allocation = new TaskAllocation.Builder().setWorker(worker).addAllTasks(tasks)
            .setTaskRemaining(taskRemaining).setTaskCount(taskCount).build();
    return Optional.of(allocation);
}

From source file:fr.aliasource.webmail.ldap.BookSource.java

@Override
public List<MinigContact> find(String userId, String userPassword, String query, int limit) {
    DirContext ctx = null;/*from  www.j a  va2s.  c  o  m*/
    List<MinigContact> ret = new LinkedList<MinigContact>();
    String domain = "";
    int idx = userId.indexOf("@");
    if (idx > 0) {
        domain = userId.substring(idx + 1);
    }
    try {
        ctx = conf.getConnection();

        LdapUtils u = new LdapUtils(ctx, conf.getBaseDn().replace("%d", domain));
        List<Map<String, List<String>>> l = u.getAttributes(conf.getFilter(), query,
                new String[] { "cn", "sn", "givenName", "mail" });
        l = l.subList(0, Math.min(limit, l.size()));
        for (Map<String, List<String>> m : l) {
            String sn = uniqueAttribute("sn", m);
            String givenName = uniqueAttribute("givenName", m);
            String cn = uniqueAttribute("cn", m);
            if (sn.length() == 0 || givenName.length() == 0) {
                sn = cn;
                givenName = "";
            }
            MinigContact c = new MinigContact(sn, givenName, "", "", "", "", "", "", "");
            List<String> mails = m.get("mail");
            String lblRoot = "INTERNET;X-OBM-Ref";
            int i = 1;
            for (String mail : mails) {
                c.addEmail(lblRoot + (i++), new MinigEmail(mail));
            }

            ret.add(c);
        }
    } catch (NamingException e) {
        logger.error("findAll error", e);
    } finally {
        conf.cleanup(ctx);
    }
    return ret;
}

From source file:com.snapdeal.archive.service.impl.ArchivalServiceSystemCacheStrategy.java

private List<Map<String, Object>> getResultSet(List<Map<String, Object>> masterResult, long start,
        Long batchSize) {//  w ww  .  j a va 2  s.  c  om
    int startPt = ((Long) start).intValue();
    int endPt = ((Long) batchSize).intValue();
    return masterResult.subList(startPt, endPt);
}