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:com.dianping.lion.dao.ibatis.ConfigReleaseIbatisDao.java

@Override
public void createConfigSnapshots(List<ConfigSnapshot> configSnapshots) {
    int batchSize = 50;
    int snapshotSize = configSnapshots.size();
    for (int fromIndex = 0; fromIndex < snapshotSize;) {
        int toIndex = fromIndex + batchSize <= snapshotSize ? fromIndex + batchSize : snapshotSize;
        List<ConfigSnapshot> batchList = configSnapshots.subList(fromIndex, toIndex);
        getSqlMapClientTemplate().insert("ConfigRelease.insertConfigSnapshots", batchList);
        fromIndex = toIndex;/*  ww  w. j  a va 2s  . c om*/
    }
}

From source file:com.swordlord.jalapeno.datatable.DataTableBase.java

public List<DataRowBase> subList(int fromIndex, int toIndex) {
    List<DataRowBase> rows = getDataRows();
    return rows.subList(fromIndex, toIndex);
}

From source file:com.teradata.tempto.internal.convention.AnnotatedFileParser.java

private List<List<String>> splitSections(List<String> lines) {
    List<List<String>> sections = newArrayList();
    int nextSectionIndex;
    while ((nextSectionIndex = findNextSectionIndex(lines)) != -1) {
        sections.add(lines.subList(0, nextSectionIndex));
        lines = lines.subList(nextSectionIndex, lines.size());
    }/*from  www . ja  v a2  s. c om*/

    if (!lines.isEmpty() || sections.isEmpty()) {
        sections.add(lines);
    }

    return sections;
}

From source file:ml.shifu.shifu.core.dvarsel.wrapper.WrapperWorkerConductorTest.java

@Test
public void testWrapperConductor() throws IOException {
    ModelConfig modelConfig = CommonUtils.loadModelConfig(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json",
            RawSourceData.SourceType.LOCAL);
    List<ColumnConfig> columnConfigList = CommonUtils.loadColumnConfigList(
            "src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ColumnConfig.json",
            RawSourceData.SourceType.LOCAL);

    WrapperWorkerConductor wrapper = new WrapperWorkerConductor(modelConfig, columnConfigList);
    TrainingDataSet trainingDataSet = genTrainingDataSet(modelConfig, columnConfigList);
    wrapper.retainData(trainingDataSet);

    List<Integer> columnIdList = new ArrayList<Integer>();
    for (int i = 2; i < 30; i++) {
        columnIdList.add(i);/*from   w  w w.  j a v a 2s  .  c  om*/
    }

    List<CandidateSeed> seedList = new ArrayList<CandidateSeed>();
    for (int i = 0; i < 10; i++) {
        seedList.add(new CandidateSeed(0, columnIdList.subList(i + 1, i + 7)));
    }
    wrapper.consumeMasterResult(new VarSelMasterResult(seedList));
    VarSelWorkerResult workerResult = wrapper.generateVarSelResult();

    Assert.assertNotNull(workerResult);
    Assert.assertTrue(workerResult.getSeedPerfList().size() > 0);
}

From source file:org.springframework.cloud.consul.binder.EventService.java

/**
 * from https://github.com/hashicorp/consul/blob/master/watch/funcs.go#L169-L194
 *///from   w ww  .  j  a v  a  2 s. c  om
protected List<Event> filterEvents(List<Event> toFilter, Long lastIndex) {
    List<Event> events = toFilter;
    if (lastIndex != null) {
        for (int i = 0; i < events.size(); i++) {
            Event event = events.get(i);
            Long eventIndex = event.getWaitIndex();
            if (lastIndex.equals(eventIndex)) {
                events = events.subList(i + 1, events.size());
                break;
            }
        }
    }
    return events;
}

From source file:com.mgmtp.perfload.perfalyzer.reporting.email.EmailReporter.java

public void createAndSendReportMail() throws IOException {
    log.info("Creating e-mail report...");

    List<? extends List<String>> data = loadData(new File(soureDir, "global/[measuring][executions].csv"));
    Map<String, List<? extends List<String>>> comparisonData = newTreeMap();

    if (maxHistoryItems > 0) {
        File[] files = new File(soureDir, "comparison").listFiles();
        for (File file : files) {
            String groupKey = removeExtension(file.getPath());
            boolean excluded = false;
            for (Pattern pattern : reportContentsConfigMap.get("exclusions")) {
                Matcher matcher = pattern.matcher(groupKey);
                if (matcher.matches()) {
                    excluded = true;/*from  w  w w .java2 s. c om*/
                    log.debug("Excluded from report: {}", groupKey);
                    break;
                }
            }
            if (!excluded) {
                String operation = PerfAlyzerFile.create(file).getFileNameParts().get(1);
                List<? extends List<String>> comparisonDataList = loadData(file);

                // apply max restriction, add 1 for header
                comparisonDataList = comparisonDataList.subList(0,
                        min(maxHistoryItems + 1, comparisonDataList.size()));
                comparisonData.put(operation, comparisonDataList);
            }
        }
    }

    String link;
    if (reportsBaseUrl != null) {
        link = reportsBaseUrl + normalize(new File(destDir, "05_report/report.html").getPath(), true);
    } else {
        link = null;
        log.warn("'reportsBaseUrl' not configured. E-mail will have no link to report.");
    }

    EmailSkeleton skeleton = new EmailSkeleton(testMetadata, resourceBundle, locale, data, comparisonData,
            link);
    StringWriter sw = new StringWriter(1000);
    skeleton.write(sw);

    String content = sw.toString();

    String subject;
    String testName = removeExtension(testMetadata.getTestPlanFile());
    String subjectTemplate = subjectProps.getProperty(testName);
    if (isNotBlank(subjectTemplate)) {
        Map<String, String> replacements = PerfAlyzerUtils
                .readAggregatedMap(new File(soureDir, "global/[measuring][executions].csv"), Charsets.UTF_8);
        replacements.put("test.name", testName);

        subject = PlaceholderUtils.resolvePlaceholders(subjectTemplate, replacements);
    } else {
        subject = "perfLoad E-mail Report";
    }

    sendMessage(subject, content);
}

From source file:com.mashape.galileo.agent.network.AnalyticsBatchRequest.java

private void batch(List<ALF> alfs, int batchSize)
        throws IllegalStateException, IOException, InterruptedException, ExecutionException, TimeoutException {
    if (alfs == null || alfs.size() < 1)
        return;//from  w  w w .  j  a  va  2s  . c om

    int alfsCount = alfs.size();
    for (int i = 0; i < alfsCount; i += batchSize) {
        send(new ArrayList<ALF>(alfs.subList(i, Math.min(alfsCount, i + batchSize))));
    }
}

From source file:com.galenframework.ide.jobs.TaskResultsStorageCleanupJob.java

private void clearFinishedResults() {
    List<TaskResult> filteredResults = testResultsStorage.stream().filter((tr) -> tr.getFinishedDate() != null)
            .sorted(Comparator.comparingLong((tr) -> tr.getFinishedDate().getTime())).collect(toList());

    if (filteredResults.size() > keepLastResults) {
        List<TaskResult> elementsToBeDeleted = filteredResults.subList(0,
                filteredResults.size() - keepLastResults);
        testResultsStorage.clear(elementsToBeDeleted::contains);
        removeExternalReports(elementsToBeDeleted);
    }//from   ww  w.j  a  v a2s  . c o  m
}

From source file:io.anserini.index.IndexClueWeb09b.java

public int indexWithThreads(int numThreads) throws IOException, InterruptedException {

    System.out.println(//  w ww  .j  av  a  2 s. c  o  m
            "Indexing with " + numThreads + " threads to directory '" + indexPath.toAbsolutePath() + "'...");

    final Directory dir = FSDirectory.open(indexPath);

    final IndexWriterConfig iwc = new IndexWriterConfig(analyzer());

    iwc.setSimilarity(new BM25Similarity());
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    iwc.setRAMBufferSizeMB(256.0);
    iwc.setUseCompoundFile(false);
    iwc.setMergeScheduler(new ConcurrentMergeScheduler());

    final IndexWriter writer = new IndexWriter(dir, iwc);

    final ExecutorService executor = Executors.newFixedThreadPool(numThreads);

    List<Path> warcFiles = discoverWarcFiles(docDir);
    if (doclimit > 0 && warcFiles.size() < doclimit)
        warcFiles = warcFiles.subList(0, doclimit);

    for (Path f : warcFiles)
        executor.execute(new IndexerThread(writer, f));

    //add some delay to let some threads spawn by scheduler
    Thread.sleep(30000);
    executor.shutdown(); // Disable new tasks from being submitted

    try {
        // Wait for existing tasks to terminate
        while (!executor.awaitTermination(5, TimeUnit.MINUTES)) {
            Thread.sleep(1000);
        }
    } catch (InterruptedException ie) {
        // (Re-)Cancel if current thread also interrupted
        executor.shutdownNow();
        // Preserve interrupt status
        Thread.currentThread().interrupt();
    }

    int numIndexed = writer.maxDoc();

    try {
        writer.commit();
        if (optimize)
            writer.forceMerge(1);
    } finally {
        writer.close();
    }

    return numIndexed;
}

From source file:com.ichi2.libanki.sync.MediaSyncer.java

private void _downloadFiles(List<String> fnames) {
    mCol.log(fnames.size() + " files to fetch");
    while (fnames.size() > 0) {
        try {// ww w .  j av  a2 s.co m
            List<String> top = fnames.subList(0, Math.min(fnames.size(), Consts.SYNC_ZIP_COUNT));
            mCol.log("fetch " + top);
            ZipFile zipData = mServer.downloadFiles(top);
            int cnt = mCol.getMedia().addFilesFromZip(zipData);
            mDownloadCount += cnt;
            mCol.log("received " + cnt + " files");
            // NOTE: The python version uses slices which return an empty list when indexed beyond what
            // the list contains. Since we can't slice out an empty sublist in Java, we must check
            // if we've reached the end and clear the fnames list manually.
            if (cnt == fnames.size()) {
                fnames.clear();
            } else {
                fnames = fnames.subList(cnt, fnames.size());
            }
            mCon.publishProgress(String.format(
                    AnkiDroidApp.getAppResources().getString(R.string.sync_media_downloaded_count),
                    mDownloadCount));
        } catch (IOException e) {
            Timber.e(e, "Error downloading media files");
            throw new RuntimeException(e);
        } catch (UnknownHttpResponseException e) {
            Timber.e(e, "Error downloading media files");
            throw new RuntimeException(e);
        }
    }
}