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.fujitsu.dc.core.odata.DcExpressionParser.java

private static CommonExpression processBinaryExpression(List<Token> tokens, String op,
        Func2<CommonExpression, CommonExpression, CommonExpression> fn) {

    int ts = tokens.size();
    for (int i = 0; i < ts; i++) {
        Token t = tokens.get(i);/*  ww  w  . j ava2s  .  com*/
        if (i < ts - 2 && t.type == TokenType.WHITESPACE && tokens.get(i + 2).type == TokenType.WHITESPACE
                && tokens.get(i + 1).type == TokenType.WORD && tokens.get(i + 1).value.equals(op)) {
            CommonExpression lhs = readExpression(tokens.subList(0, i));
            CommonExpression rhs = readExpression(tokens.subList(i + BINARY_EXPRESSION_CONSTANT, ts));
            return fn.apply(lhs, rhs);
        }
    }
    return null;
}

From source file:br.com.ingenieux.mojo.beanstalk.AbstractNeedsEnvironmentMojo.java

protected ConfigurationOptionSetting[] introspectOptionSettings() {
    Set<ConfigurationOptionSetting> configOptionSetting = new TreeSet<ConfigurationOptionSetting>(
            COS_COMPARATOR);//from  w w  w. ja  v a  2  s  .  c o m

    Properties properties = new Properties();

    if (null != project) {
        for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
            if (("" + entry.getKey()).startsWith("beanstalk")) {
                properties.put(entry.getKey(), entry.getValue());
            }
        }
    }

    for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
        if (("" + entry.getKey()).startsWith("beanstalk")) {
            properties.put(entry.getKey(), entry.getValue());
        }
    }

    for (Object o : properties.keySet()) {
        String k = "" + o;

        if (k.startsWith("beanstalk.env.aws.")) {
            String realKey = k.substring("beanstalk.env.".length());
            String v = "" + properties.get(k);
            List<String> elements = new ArrayList<String>(Arrays.asList(realKey.split("\\.")));

            String namespace = StringUtils.join(elements.subList(0, -1 + elements.size()), ":");
            String optionName = elements.get(-1 + elements.size());

            getLog().info("importing " + k + " as " + namespace + ":" + optionName + "=" + v);

            configOptionSetting.add(new ConfigurationOptionSetting().withNamespace(namespace)
                    .withOptionName(optionName).withValue(v));
        } else if (COMMON_PARAMETERS.containsKey(k)) {
            String v = "" + properties.get(k);
            String namespace = COMMON_PARAMETERS.get(k).getNamespace();
            String optionName = COMMON_PARAMETERS.get(k).getOptionName();

            getLog().info("Found alias " + k + " for " + namespace + ":" + optionName + "(value=" + v + ")");

            configOptionSetting.add(new ConfigurationOptionSetting().withNamespace(namespace)
                    .withOptionName(optionName).withValue(v));
        }
    }

    return (ConfigurationOptionSetting[]) configOptionSetting
            .toArray(new ConfigurationOptionSetting[configOptionSetting.size()]);
}

From source file:de.micromata.genome.gwiki.plugin.blog_1_0.GWikiBlogActionBean.java

public void renderBlogs() {
    // wikiContext.append("Blogs here");
    String part = "MainPage";
    Date lastDay = null;/*www . ja v a 2  s.  c  om*/
    SimpleDateFormat dayFormat = new SimpleDateFormat(dayHeadFormatPattern, userLocale);
    List<GWikiElementInfo> bel = shownBlogEntries;
    if (pageOffset < 0) {
        pageOffset = 0;
    }
    if (pageOffset > 0) {
        if (bel.size() > pageOffset) {
            bel = bel.subList(pageOffset, bel.size());
        } else {
            bel = Collections.emptyList();
        }
    }
    if (bel.size() > pageSize) {
        bel = bel.subList(0, Math.min(bel.size(), pageSize));
    }

    String thisPl = wikiContext.localUrl(this.blogPageId);
    wikiContext.append("<div class=\"blogPageScroll\">");
    if (pageOffset > 0) {
        int prevPO = Math.min(pageOffset - pageSize, 0);
        wikiContext.append("<a href=\"" + thisPl + "?pageOffset=" + prevPO + "\">")
                .append(esc(translate("gwiki.blog.page.prevPage"))).append("</a>&nbsp;");
    }
    if (pageOffset + pageSize < shownBlogEntries.size()) {
        wikiContext.append("<a href=\"" + thisPl + "?pageOffset=" + (pageOffset + pageSize));
        if (StringUtils.isNotEmpty(blogCategory) == true) {
            wikiContext.append("&blogCategory=" + Converter.encodeUrlParam(blogCategory));
        }
        wikiContext.append("\">").append(esc(translate("gwiki.blog.page.nextPage"))).append("</a>&nbsp;");
    }
    wikiContext.append("</div>\n");

    renderBlogCatHeader();

    for (GWikiElementInfo ei : bel) {
        GWikiElement el = wikiContext.getWikiWeb().findElement(ei.getId());
        if (ei.isViewable() == false) {
            continue;
        }
        GWikiArtefakt<?> art = null;
        if (StringUtils.isNotEmpty(part) == true) {
            art = el.getPart(part);
        } else {
            art = el.getMainPart();
        }
        if ((art instanceof GWikiExecutableArtefakt<?>) == false || art instanceof GWikiAttachment) {
            continue;
        }
        Date cday = CalendarControl.toFullDay(el.getElementInfo().getCreatedAt(), userTimeZone);

        if (ObjectUtils.equals(lastDay, cday) == false) {
            wikiContext.append("<h1 class=\"BlogDayHead\">").append(esc(dayFormat.format(cday)))
                    .append("</h1>");
        }
        lastDay = cday;
        GWikiExecutableArtefakt<?> exec = (GWikiExecutableArtefakt<?>) art;
        renderBlockEntry(el, exec);
        GWikiContext.setCurrent(wikiContext);
    }

}

From source file:gov.nih.nci.caarray.util.CaArrayHibernateHelperImpl.java

/**
 * {@inheritDoc}/*from   w ww .ja  v  a2s .c  o  m*/
 */
public String buildInClauses(List<? extends Serializable> items, String columnName,
        Map<String, List<? extends Serializable>> blocks) {
    StringBuffer inClause = new StringBuffer();
    int startIndex = blocks.size();
    for (int i = 0; i < items.size(); i += CsmEnabledHibernateHelper.MAX_IN_CLAUSE_LENGTH) {
        List<? extends Serializable> block = items.subList(i,
                Math.min(items.size(), i + CsmEnabledHibernateHelper.MAX_IN_CLAUSE_LENGTH));
        int paramNameIndex = startIndex + (i / CsmEnabledHibernateHelper.MAX_IN_CLAUSE_LENGTH);
        String paramName = "block" + paramNameIndex;
        if (inClause.length() > 0) {
            inClause.append(" or");
        }
        inClause.append(" " + columnName + " in (:" + paramName + ")");
        blocks.put(paramName, block);
    }
    return inClause.toString();
}

From source file:com.firewallid.termcloud.TermCloud.java

public void saveTermCloudAll(JavaPairRDD<String, List<Tuple2<String, Double>>> doc, String fileNamePrefix)
        throws IOException {
    List<Tuple2<String, List<Tuple2<String, Double>>>> collectDoc = doc.collect();

    if (collectDoc.isEmpty()) {
        return;// w  w  w  . j  a v a2 s  .c o m
    }

    /* Reduced feature-value list */
    List<Tuple2<String, Double>> featureValueList = collectDoc.parallelStream()
            .map(titleFeatures -> titleFeatures._2).reduce((featureValueList1, featureValueList2) -> {
                List<Tuple2<String, Double>> combineList = FIUtils.combineList(featureValueList1,
                        featureValueList2);

                List<Tuple2<String, Double>> collect = combineList.parallelStream()
                        .collect(Collectors
                                .groupingBy(t -> t._1, Collectors.mapping(t -> t._2, Collectors.toList())))
                        .entrySet().parallelStream()
                        .map(t -> new Tuple2<String, Double>(t.getKey(),
                                t.getValue().parallelStream().mapToDouble(Double::doubleValue).sum()))
                        .collect(Collectors.toList());

                return collect;
            }).get();

    /* Sorting */
    List<Tuple2<String, Double>> featureValueListSorted = FIUtils.sortDescTupleListByValue(featureValueList);

    /* Top N */
    List<Tuple2<String, Double>> featureValueListTopN;
    if (featureValueListSorted.size() <= conf.getInt(TOPN, 100)) {
        featureValueListTopN = new ArrayList<>(featureValueListSorted);
    } else {
        featureValueListTopN = new ArrayList<>(featureValueListSorted.subList(0, conf.getInt(TOPN, 100)));
    }

    /* Text for file. One line, one feature-value pair */
    String featureValueText = featureValueListTopN.parallelStream()
            .map(feature -> feature._1 + StringEscapeUtils.unescapeJava(conf.get(LINE_DELIMITER)) + feature._2)
            .collect(Collectors.joining(System.lineSeparator()));

    /* Save to file */
    FIFile.writeStringToHDFSFile(FIFile.generateFullPath(conf.get(TERMCLOUD_FOLDER),
            createFileNameTermCloud(fileNamePrefix, conf.get(ALLNAME))), featureValueText);
}

From source file:net.ripe.ipresource.etree.NestedIntervalMap.java

private List<InternalNode<K, V>> internalFindAllLessSpecific(K range) {
    List<InternalNode<K, V>> result = internalFindExactAndAllLessSpecific(range);
    if (result.isEmpty()) {
        return result;
    }/*from  w  w  w.j  av  a2 s . c om*/
    InternalNode<K, V> last = result.get(result.size() - 1);
    if (last.getKey().equals(range)) {
        return result.subList(0, result.size() - 1);
    } else {
        return result;
    }
}

From source file:ch.oakmountain.tpa.solver.MacroscopicTopology.java

protected List<List<SystemNode>> getRoutes(List<List<SystemNode>> routes, SystemNode from, SystemNode to) {
    List<List<SystemNode>> routesFound = new LinkedList<List<SystemNode>>();
    for (List<SystemNode> route : routes) {
        int fromIndex = route.indexOf(from);
        int toIndex = route.indexOf(to);
        if (fromIndex >= 0 && toIndex >= 0 && toIndex > fromIndex) {
            routesFound.add(route.subList(fromIndex, toIndex + 1));
        }//from  w ww .j  a  v a 2  s  .  c  om
    }
    return removeDuplicateRoutes(routesFound);
}

From source file:org.kew.rmf.matchconf.web.CustomMatcherController.java

@RequestMapping(value = "/{configType}_configs/{configName}/matchers", produces = "text/html")
public String list(@PathVariable("configType") String configType, @PathVariable("configName") String configName,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
    uiModel.addAttribute("availableItems", LibraryScanner.availableItems());
    List<Matcher> matchers = Configuration.findConfigurationsByNameEquals(configName).getSingleResult()
            .getMatchers();/* www. j  ava 2 s. c o  m*/
    if (page != null || size != null) {
        int sizeNo = Math.min(size == null ? 10 : size.intValue(), matchers.size());
        final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
        uiModel.addAttribute("matchers", matchers.subList(firstResult, sizeNo));
        float nrOfPages = (float) Matcher.countMatchers() / sizeNo;
        uiModel.addAttribute("maxPages",
                (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
    } else {
        uiModel.addAttribute("matchers", matchers);
    }
    uiModel.addAttribute("configName", configName);
    return "config_matchers/list";
}

From source file:org.kew.rmf.matchconf.web.CustomReporterController.java

@RequestMapping(value = "/{configType}_configs/{configName}/reporters", produces = "text/html")
public String list(@PathVariable("configType") String configType, @PathVariable("configName") String configName,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
    uiModel.addAttribute("availableItems", LibraryScanner.availableItems());
    List<Reporter> reporters = Configuration.findConfigurationsByNameEquals(configName).getSingleResult()
            .getReporters();/*from  w  w  w.  j  a va  2s  .  c  om*/
    if (page != null || size != null) {
        int sizeNo = Math.min(size == null ? 10 : size.intValue(), reporters.size());
        final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
        uiModel.addAttribute("reporters", reporters.subList(firstResult, sizeNo));
        float nrOfPages = (float) reporters.size() / sizeNo;
        uiModel.addAttribute("maxPages",
                (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
    } else {
        uiModel.addAttribute("reporters", reporters);
    }
    uiModel.addAttribute("configName", configName);
    return "config_reporters/list";
}