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.trenako.results.RollingStockResults.java

/**
 * Creates a new {@code RollingStockResults}.
 *
 * @param results the result items//from   www  .ja  va2s .c o  m
 * @param range   the result range
 */
public RollingStockResults(List<RollingStock> results, SearchCriteria criteria, RangeRequest range) {

    int size = results.size() > range.getSize() ? range.getSize() : results.size();

    this.results = results.subList(0, size);
    this.criteria = criteria;

    if (!isEmpty()) {
        final RollingStock minRs = results.get(0);
        final RollingStock maxRs = results.get(size - 1);

        Object since, max;
        if (range.getDirection().equals("desc")) {
            since = safeGetProperty(maxRs, range.getSortProperty());
            max = safeGetProperty(minRs, range.getSortProperty());
        } else {
            since = safeGetProperty(minRs, range.getSortProperty());
            max = safeGetProperty(maxRs, range.getSortProperty());
        }

        this.hasPrevious = range.getSince() != null;
        this.hasNext = results.size() > range.getSize();

        this.range = new SearchRange(range.getSize(), range.getSort(), since, max);
    } else {
        this.range = null;
        this.hasPrevious = false;
        this.hasNext = false;
    }
}

From source file:org.wallerlab.yoink.adaptive.smooth.SCMPWeightFactors.java

private Map<List<Integer>, Double> getWeightForSelectedPartitioningConfiguration(int partitionNumber,
        double[] sigmas, List<List<Integer>> qmSets) {
    Map<List<Integer>, Double> sortedSigmaIndexMap = MapSorter.sortByValue(sigmaIndexMap);
    List<List<Integer>> sortedIndices = new ArrayList<List<Integer>>(sortedSigmaIndexMap.keySet());
    List<Double> sortedSigmas = new ArrayList<Double>(sortedSigmaIndexMap.values());
    double sum_sigmas = 0;
    List<Double> subSigmas = sortedSigmas.subList(sortedSigmas.size() - partitionNumber, sortedSigmas.size());
    List<List<Integer>> subIndices = sortedIndices.subList(sortedSigmas.size() - partitionNumber,
            sortedSigmas.size());//ww  w .j  a va2s . com
    for (int num = 0; num < subSigmas.size(); num++) {
        double sigma = subSigmas.get(num);
        sigmas[num] = sigma;
        List<Integer> qmSet = subIndices.get(num);
        qmSets.add(qmSet);
        sum_sigmas += sigma;
    }
    Map<List<Integer>, Double> molecularIndicesAndWeightFactor = new HashMap<List<Integer>, Double>();
    for (int i = 0; i < sigmas.length; i++) {
        sigmas[i] = sigmas[i] / sum_sigmas;
        molecularIndicesAndWeightFactor.put(qmSets.get(i), sigmas[i]);
    }
    return molecularIndicesAndWeightFactor;
}

From source file:com.temenos.useragent.generic.mediatype.JsonEntityHandler.java

@Override
public int getCount(String fqPropertyName) {
    List<String> pathParts = Arrays.asList(flattenPropertyName(fqPropertyName));
    Optional<JSONObject> parent = navigateJsonObjectforPropertyPath(Optional.ofNullable(jsonObject),
            pathParts.subList(0, pathParts.size() - 1), fqPropertyName, false);
    String lastPathPart = pathParts.get(pathParts.size() - 1);
    if (parent.isPresent() && parent.get().optJSONArray(lastPathPart) != null) {
        return parent.get().optJSONArray(lastPathPart).length();
    }//from   www  .  ja  v  a2s.c  om
    return 0;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.weka.util.WekaUtils.java

/**
 *
 * Feature selection using Weka.// ww w  .j a v  a2 s.c o  m
 *
 * @param trainData
 *            training data
 * @param featureSearcher
 * @param attributeEvaluator
 * @return a feature selector
 * @throws Exception
 */
public static AttributeSelection singleLabelAttributeSelection(Instances trainData,
        List<String> featureSearcher, List<String> attributeEvaluator) throws Exception {
    AttributeSelection selector = new AttributeSelection();

    // Get feature searcher
    ASSearch search = ASSearch.forName(featureSearcher.get(0),
            featureSearcher.subList(1, featureSearcher.size()).toArray(new String[0]));
    // Get attribute evaluator
    ASEvaluation evaluation = ASEvaluation.forName(attributeEvaluator.get(0),
            attributeEvaluator.subList(1, attributeEvaluator.size()).toArray(new String[0]));

    selector.setSearch(search);
    selector.setEvaluator(evaluation);
    selector.SelectAttributes(trainData);

    return selector;
}

From source file:gov.nih.nci.firebird.service.registration.AbstractPdfForm1572Generator.java

private String getTruncatedFieldValue(int maximumLinesInField, List<String> lines) {
    StringBuilder sb = new StringBuilder();
    sb.append(Joiner.on(NEWLINE).join(lines.subList(0, maximumLinesInField)));
    sb.append(NEWLINE);//from w  w  w.ja v  a  2 s  . c  om
    sb.append(resources.getString("form1572.see_attached"));
    return sb.toString();
}

From source file:it.zielke.a2pdf.Anki2PDF.java

private List<String> reorderPages(List<String> sideContent) {
    LinkedList<String> ret = new LinkedList<String>();
    int rowsize = settings.getRowSize();
    for (int i = 0; i < sideContent.size(); i += rowsize) {
        List<String> tmp = sideContent.subList(i, Math.min(i + rowsize, sideContent.size()));
        Collections.reverse(tmp);
        ret.addAll(tmp);/*from  w w w. j av a2  s  .com*/
    }
    return ret;
}

From source file:org.easit.core.controllers.twitter.TwitterMessageController.java

@RequestMapping(value = "/twitter/messages", method = RequestMethod.GET)
public String inbox(Model model, String offset) throws Exception {
    int listSize = 0;
    int int_offset = 0;
    if (offset != null) {
        int_offset = Integer.valueOf(offset);
    }// www  .  ja  v a2  s.c o  m

    int fromIndex = int_offset;
    int toIndex = fromIndex + PSMetadata.TWITTER_LIMIT_RESULT;

    List<DirectMessage> messages = twitter.directMessageOperations().getDirectMessagesReceived();
    toIndex = Math.min(toIndex, messages.size());

    listSize = messages.size();
    model.addAttribute("directMessages", messages.subList(fromIndex, toIndex));
    model.addAttribute("dmListType", "Received");
    model.addAttribute("messageForm", new MessageForm());
    model.addAttribute("offset", int_offset);
    model.addAttribute("pageSize", listSize);
    return "twitter/messages";
}

From source file:com.temenos.useragent.generic.mediatype.JsonEntityHandler.java

@Override
public void remove(String fqPropertyName) {
    List<String> pathParts = Arrays.asList(flattenPropertyName(fqPropertyName));
    Optional<JSONObject> parent = navigateJsonObjectforPropertyPath(Optional.ofNullable(jsonObject),
            pathParts.subList(0, pathParts.size() - 1), fqPropertyName, false);
    String lastPathPart = pathParts.get(pathParts.size() - 1);
    if (parent.isPresent()) {
        if (isPropertyNameWithIndex(lastPathPart)) {
            JSONArray jsonArr = parent.get().optJSONArray(extractPropertyName(lastPathPart));
            if (jsonArr != null) {
                jsonArr.remove(extractIndex(lastPathPart));
            }//from  ww w. java  2 s . c  o m
        } else {
            parent.get().remove(lastPathPart);
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.searchengine.AutoCompleteWords.java

/**
 * Package-access. Use SearchQueryUtils.parseForAutoComplete() to create an
 * instance./*  www .  j av a2 s  . co m*/
 */
AutoCompleteWords(String searchTerm, String delimiterPattern) {
    this.searchTerm = (searchTerm == null) ? "" : searchTerm;
    this.delimiterPattern = delimiterPattern;

    List<String> termWords = figureTermWords();
    if (termWords.isEmpty() || this.searchTerm.matches(".*" + delimiterPattern)) {
        this.completeWords = termWords;
        this.partialWord = null;
    } else {
        this.completeWords = termWords.subList(0, termWords.size() - 1);
        this.partialWord = termWords.get(termWords.size() - 1);
    }

}

From source file:com.github.cchacin.cucumber.steps.DatabaseSteps.java

void insert(final String tableName, final DataTable data) {
    final List<DataTableRow> rows = data.getGherkinRows();
    final List<String> columns = rows.get(0).getCells();

    final List<Operation> operations = new ArrayList<>();

    for (DataTableRow row : rows.subList(1, rows.size())) {
        final Insert.Builder builder = Insert.into(tableName);
        builder.columns(columns.toArray(new String[columns.size()]));
        builder.values(row.getCells().toArray(new String[row.getCells().size()]));
        operations.add(builder.build());
    }//w ww  .j a v a 2  s . co  m

    this.apply(sequenceOf(operations));
}