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:de.tudarmstadt.ukp.dkpro.core.ngrams.util.CharacterNGramStringIterable.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), ""));
    }//www.ja v  a  2  s.c o  m

    return nGrams;
}

From source file:org.jtalks.common.security.acl.ExtendedMutableAclTest.java

@Test(dataProvider = "extendedMutableAclAndWrappedMock")
public void testDeleteList(ExtendedMutableAcl extendedMutableAcl, MutableAcl wrappedMock) throws Exception {
    List<AccessControlEntry> entries = createEntries(wrappedMock);
    when(wrappedMock.getEntries()).thenReturn(entries);

    extendedMutableAcl.delete(entries.subList(1, 3));
    verify(wrappedMock).deleteAce(1);/* w w w.j  a  v  a 2  s. c  om*/
    verify(wrappedMock).deleteAce(2);
}

From source file:edu.cornell.mannlib.ld4lindexing.documents.AgentDocument.java

private void addNameFields(SolrDocument doc) {
    List<? extends Object> names = values.get("names");
    doc.addFieldValue("title_display", names.get(0));
    if (names.size() > 1) {
        doc.addFieldValues("alt_names_t", names.subList(1, names.size()));
    }//from w  w  w . ja v  a 2s .c o m
}

From source file:com.turn.griffin.GriffinModule.java

public String multiConcat(List<String> pathElements) {
    String fullConcatName = pathElements.get(0);
    for (String name : pathElements.subList(1, pathElements.size())) {
        fullConcatName = FilenameUtils.concat(fullConcatName, name);
    }//from  ww w.  j  a  va 2s .  co m
    return fullConcatName;
}

From source file:com.graphaware.reco.generic.result.Recommendations.java

/**
 * Get a list of recommendation ordered by decreasing score (relevance).
 *
 * @param limit the maximum number of recommendations to get.
 * @return list of recommendations paired with their composite scores, ordered by decreasing relevance.
 *//*from   w w w  . j a va  2  s .  c o m*/
public List<Recommendation<OUT>> get(int limit) {
    List<Recommendation<OUT>> result = new LinkedList<>(scoredItems.values());

    Collections.sort(result, Collections.reverseOrder());

    return result.subList(0, Math.min(limit, result.size()));
}

From source file:eu.europeana.sounds.vocabulary.genres.music.OnbMimoMappingTest.java

/**
 * This method extracts mapping IDs in form <EuropeanaId_matchLink> for given input CSV file. 
 * @param filePath// ww  w.j  av a 2s.co m
 * @param enrichedIds
 * @param mapIdToLine
 * @return header line
 * @throws IOException
 */
private String extractMappingIds(String filePath, List<String> enrichedIds, Map<String, String> mapIdToLine)
        throws IOException {

    File enrichedFile = new File(filePath);
    List<String> instrumentLines = FileUtils.readLines(enrichedFile);
    for (String instrumentLine : instrumentLines.subList(1, instrumentLines.size())) {
        String[] instrumentsArr = instrumentLine.split(CSV_LINE_DELIMITER);
        noteEnrichedId(instrumentsArr, instrumentLine, enrichedIds, mapIdToLine, EUROPEANA_ID_COL_POS,
                EXACT_MATCH_COL_POS);
        noteEnrichedId(instrumentsArr, instrumentLine, enrichedIds, mapIdToLine, EUROPEANA_ID_COL_POS,
                BROAD_MATCH_COL_POS);
    }
    return instrumentLines.get(0);
}

From source file:org.jspringbot.keyword.expression.ELRunKeywordIf.java

@Override
public Object execute(final Object[] params) throws Exception {
    if (!Boolean.class.isInstance(params[0])) {
        throw new IllegalArgumentException("Expecting condition with boolean result on first argument.");
    }// ww  w . j  ava  2s. c o m

    if ((Boolean) params[0]) {
        List<Object> items = Arrays.asList(params);

        if (items.size() <= 2) {
            return ELRunKeyword.runKeyword(String.valueOf(params[1]));
        } else {
            return ELRunKeyword.runKeyword(String.valueOf(params[1]), items.subList(2, items.size()));
        }
    }

    return null;
}

From source file:org.openlmis.fulfillment.service.request.RequestParameters.java

/**
 * Split this request parameters into two smaller chunks.
 *///www . jav a2s  . co m
public Pair<RequestParameters, RequestParameters> split() {
    if (params.isEmpty()) {
        return Pair.of(this, null);
    }

    Set<Entry<String, List<String>>> entries = params.entrySet();

    if (entries.stream().noneMatch(entry -> entry.getValue().size() > 1)) {
        return Pair.of(this, null);
    }

    Map.Entry<String, List<String>> max = entries.iterator().next();
    for (Map.Entry<String, List<String>> entry : entries) {
        if (entry.getValue().size() > max.getValue().size()) {
            max = entry;
        }
    }

    RequestParameters left = init().setAll(this);
    RequestParameters right = init().setAll(this);

    left.params.remove(max.getKey());
    right.params.remove(max.getKey());

    List<String> list = max.getValue();
    int chunkSize = list.size() / 2;
    int leftOver = list.size() % 2;

    List<String> leftCollection = list.subList(0, chunkSize + leftOver);
    List<String> rightCollection = list.subList(chunkSize + leftOver, list.size());

    left.set(max.getKey(), leftCollection);
    right.set(max.getKey(), rightCollection);

    return Pair.of(left, right);
}

From source file:com.logsniffer.model.file.RollingLogsSourceDynamicLiveName.java

@Override
public List<Log> getLogs() throws IOException {
    final List<Log> logs = super.getLogs();
    if (!logs.isEmpty()) {
        Collections.sort(logs, getPastLogsType().getPastComparatorForLogs());
        final Log liveLog = logs.get(0);
        final List<Log> pastLogs = logs.subList(1, logs.size());
        logger.debug("Exposing rolling log with dynamic live file {} and rolled over files: {}", liveLog,
                pastLogs);/*from  w  w w .j  a va2s. c  o m*/
        final List<Log> rolledLog = new ArrayList<>();
        rolledLog.add(new DailyRollingLog(liveLog.getName(), getName(), liveLog, pastLogs));
        return rolledLog;
    } else {
        return new ArrayList<>();
    }
}

From source file:net.sf.clickclick.examples.page.repeat.EditTableRepeaterPage.java

public List<Customer> getTopCustomers() {
    List<Customer> customers = getCustomerService().getCustomers();
    int size = Math.min(5, customers.size());
    return customers.subList(0, size);
}