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.springframework.cloud.consul.bus.EventService.java

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

From source file:io.yields.plugins.kpi.KPIReportProjectAction.java

public List<KPIReport> getKPIReportsForDetail() {

    List<KPIReport> kpiReports = getKPIReports();
    if (kpiReports.size() > config.getDetailSize()) {
        kpiReports = kpiReports.subList(kpiReports.size() - config.getDetailSize(), kpiReports.size());
    }/*from   www. java 2 s  . c om*/

    return kpiReports;
}

From source file:com.app.inventario.logica.FamiliaLogicaImpl.java

@Transactional(readOnly = true)
public jqGridModel obtenerListaTodos(int numeroPagina, int numeroFilas, String ordenarPor, String ordenarAsc)
        throws Exception {
    modelo = new jqGridModel<Familia>();
    int primerResultado = numeroFilas * (numeroPagina - 1);
    List<Familia> familias = null;
    try {//from  www. j ava2s . c om
        familias = familiaDAO.obtenerTodosAGrid(ordenarPor, ordenarAsc);
        modelo.setPage(numeroPagina);
        modelo.setTotal((int) Math.ceil((double) familias.size() / (double) numeroFilas));
        modelo.setRecords(familias.size());
        modelo.setRows(familias.subList(primerResultado,
                numeroFilas > familias.size() ? familias.size() : numeroFilas));
        return modelo;
    } catch (HibernateException he) {
        Logger.getLogger(UsuarioLogicaImpl.class.getName()).log(Level.SEVERE, null, he);
        throw he;
    }
}

From source file:com.dianping.lion.dao.ibatis.ConfigReleaseIbatisDao.java

@Override
public void createConfigInstSnapshots(List<ConfigInstanceSnapshot> configInstSnapshots) {
    int batchSize = 20;
    int snapshotSize = configInstSnapshots.size();
    for (int fromIndex = 0; fromIndex < snapshotSize;) {
        int toIndex = fromIndex + batchSize <= snapshotSize ? fromIndex + batchSize : snapshotSize;
        List<ConfigInstanceSnapshot> batchList = configInstSnapshots.subList(fromIndex, toIndex);
        getSqlMapClientTemplate().insert("ConfigRelease.insertConfigInstSnapshots", batchList);
        fromIndex = toIndex;/*from w ww  . j a  v  a  2  s.  com*/
    }
}

From source file:se.vgregion.portal.sitenavigation.controller.SiteNavigationViewController.java

/**
 * The default render method. Load the correct {@link NavigationItem}s and add as request attributes.
 *
 * @param request  the request//from  w  w w  . java 2  s.  c o m
 * @param response the response
 * @param model    the model
 * @return the view
 */
@RenderMapping()
public String showNavigation(RenderRequest request, RenderResponse response, final ModelMap model) {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long scopeGroupId = themeDisplay.getScopeGroupId();
    long companyId = themeDisplay.getCompanyId();
    Locale locale = themeDisplay.getLocale();
    boolean isSignedIn = themeDisplay.isSignedIn();
    Layout layout = themeDisplay.getLayout();
    boolean isPrivateLayout = layout.isPrivateLayout();

    HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(request);

    List<NavigationItem> navigationItems = NavigationUtil.getGroupNavigationItems(scopeGroupId, isSignedIn,
            layout, isPrivateLayout, httpServletRequest, locale, themeDisplay.getPermissionChecker(),
            NavigationConstants.NAVIGATION_DEPTH_DEFAULT);

    navigationItems = navigationItems.subList(1, navigationItems.size());
    navigationItems = populateNavigationCustomFields(navigationItems);

    model.addAttribute("navigationItems", navigationItems);

    return "view";
}

From source file:com.naver.jr.study.bo.sesame.SesameBOImpl.java

@Override
public List<SesameStep> getMainThemeList() {
    List<SesameStep> sesameStepList = sesameDAO.selectMainThemeList();
    Collections.shuffle(sesameStepList);

    if (CollectionUtils.isNotEmpty(sesameStepList) && sesameStepList.size() >= 3) {
        sesameStepList = sesameStepList.subList(0, 3);
    }//w w w .j ava  2 s  . c  o m

    return sesameStepList;
}

From source file:de.whs.poodle.controllers.instructor.InstructorStartController.java

private List<AbstractExercise> getLatestChanges(int instructorId) {
    /* load the latest changes for exercises and mcQuestions and
     * then merge both into a List<AbstractExercise> .*/
    List<Exercise> exercises = exerciseRepo.getLatestExercises(instructorId, CHANGES_MAX);
    List<McQuestion> mcQuestions = mcQuestionRepo.getLatest(instructorId, CHANGES_MAX);

    // merge//www  . ja v  a  2 s  .  c  o  m
    List<AbstractExercise> allExercises = new ArrayList<>();
    allExercises.addAll(exercises);
    allExercises.addAll(mcQuestions);

    // sort
    allExercises.sort((a, b) -> b.getCreatedAt().compareTo(a.getCreatedAt()));

    // trim list to CHANGES_MAX
    if (allExercises.size() > CHANGES_MAX)
        allExercises = allExercises.subList(0, CHANGES_MAX - 1);

    return allExercises;
}

From source file:pl.edu.icm.coansys.deduplication.document.DuplicateWorkDetectReduceService.java

/**
 * Splits the passed documents into smaller parts. The documents are divided into smaller packs according to the generated keys.
 * The keys are generated by using the {@link WorkKeyGenerator.generateKey(doc, level)} method.
 *///  ww  w .j av a2  s. c  o  m
Map<Text, List<DocumentProtos.DocumentMetadata>> splitDocuments(Text key,
        List<DocumentProtos.DocumentMetadata> documents, int level) {

    // check if set was forced to split; if yes, keep the suffix
    String keyStr = key.toString();
    String suffix = "";
    if (keyStr.contains("-")) {
        String[] parts = keyStr.split("-");
        suffix = parts[1];
    }

    Map<Text, List<DocumentProtos.DocumentMetadata>> splitDocuments = Maps.newHashMap();
    for (DocumentProtos.DocumentMetadata doc : documents) {
        String newKeyStr = keyGen.generateKey(doc, level);
        if (!suffix.isEmpty()) {
            newKeyStr = newKeyStr + "-" + suffix;
        }
        Text newKey = new Text(newKeyStr);
        List<DocumentProtos.DocumentMetadata> list = splitDocuments.get(newKey);
        if (list == null) {
            list = Lists.newArrayList();
            splitDocuments.put(newKey, list);
        }
        list.add(doc);
    }

    if (level > maxSplitLevel && splitDocuments.size() == 1) {
        //force split into 2 parts
        Text commonKey = splitDocuments.keySet().iterator().next();
        String commonKeyStr = commonKey.toString();
        if (!commonKeyStr.contains("-")) {
            commonKeyStr += "-";
        }
        Text firstKey = new Text(commonKeyStr + "0");
        Text secondKey = new Text(commonKeyStr + "1");
        List<DocumentProtos.DocumentMetadata> fullList = splitDocuments.get(commonKey);
        int items = fullList.size();
        List<DocumentProtos.DocumentMetadata> firstHalf = fullList.subList(0, items / 2);
        List<DocumentProtos.DocumentMetadata> secondHalf = fullList.subList(items / 2, items);
        splitDocuments.clear();
        splitDocuments.put(firstKey, firstHalf);
        splitDocuments.put(secondKey, secondHalf);
    }

    return splitDocuments;
}

From source file:com.google.gdocsfs.GoogleDocs.java

public GoogleDocs(String username, String password) throws IOException, ServiceException {
    service = new DocsService("gdocsfs");
    service.setUserCredentials(username, password);
    URL documentListFeedUrl = new URL(DOCUMENTS_URL);

    DocumentListFeed feed = service.getFeed(documentListFeedUrl, DocumentListFeed.class);
    List<DocumentListEntry> entries = feed.getEntries();

    log.info(username + " has " + entries.size() + " documents");
    root = new Folder("");
    root.setLastUpdated(System.currentTimeMillis());
    for (DocumentListEntry entry : entries.subList(0, 1)) {
        root.addDocument(new Document(this, entry));
    }//from  www . ja v a  2 s  .c  om

    log.info("ready to use");
}

From source file:hudson.widgets.HistoryWidget.java

/**
 * The records to be rendered this time.
 *///from www  .  j av a 2  s  .c  om
public Iterable<HistoryPageEntry<T>> getRenderList() {
    if (trimmed) {
        List<HistoryPageEntry<T>> pageEntries = toPageEntries(baseList);
        if (pageEntries.size() > THRESHOLD) {
            return updateFirstTransientBuildKey(pageEntries.subList(0, THRESHOLD));
        } else {
            trimmed = false;
            return updateFirstTransientBuildKey(pageEntries);
        }
    } else {
        // to prevent baseList's concrete type from getting picked up by <j:forEach> in view
        return updateFirstTransientBuildKey(toPageEntries(baseList));
    }
}