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:hudson.Functions.java

/**
 * Returns a sub-list if the given list is bigger than the specified 'maxSize'
 *//*  w w  w.j ava  2s  .  c  o m*/
public static <T> List<T> subList(List<T> base, int maxSize) {
    if (maxSize < base.size())
        return base.subList(0, maxSize);
    else
        return base;
}

From source file:edu.toronto.cs.phenotips.hpoa.PhenotypeMappingScriptService.java

public List<SearchResult> getDifferentialPhenotypes(Collection<String> phenotypes, int limit) {
    List<SearchResult> results = this.predictor.getDifferentialPhenotypes(phenotypes);
    if (limit < results.size()) {
        return results.subList(0, limit);
    }/*w  ww.j  a v  a  2  s .  c o  m*/
    return results;
}

From source file:ch.ksfx.web.components.SeriesBrowserLayout.java

public void onSuccessFromSeriesNameSearchForm() {
    filteredSeriesNames = new ArrayList<String>();
    openNodes = new ArrayList<String>();

    if (seriesNameSearch != null && seriesNameSearch.length() >= 3) {
        List<TimeSeries> timeSeries = timeSeriesDAO.searchTimeSeries(seriesNameSearch, 100);

        for (TimeSeries ts : timeSeries) {
            String locator = ts.getLocator();
            String[] parts = locator.split("-");

            for (Integer i = 0; i < parts.length; i++) {
                List<String> listParts = Arrays.asList(parts);
                List<String> subParts = listParts.subList(0, i + 1);

                String locatorPart = StringUtils.join(subParts, "-");

                onOpenNode(locatorPart);
            }//from w w w  .j a  v  a 2s  .c om

            filteredSeriesNames.add(ts.getName());
        }
    }
}

From source file:com.twitter.aurora.scheduler.storage.backup.StorageBackupTest.java

@Test
public void testOldBackupsDeleted() {
    Snapshot snapshot = makeSnapshot();//  ww w .  j a v  a 2 s  .  c om
    expect(delegate.createSnapshot()).andReturn(snapshot).times(MAX_BACKUPS + 1);

    control.replay();

    ImmutableList.Builder<String> nameBuilder = ImmutableList.builder();
    for (int i = 0; i < MAX_BACKUPS; i++) {
        clock.advance(Amount.of(INTERVAL.as(Time.MILLISECONDS), Time.MILLISECONDS));
        assertEquals(snapshot, storageBackup.createSnapshot());
        nameBuilder.add(storageBackup.createBackupName());
        assertBackupCount(i + 1);
        assertEquals(i + 1, storageBackup.getSuccesses().get());
    }

    clock.advance(Amount.of(INTERVAL.as(Time.MILLISECONDS), Time.MILLISECONDS));
    assertEquals(snapshot, storageBackup.createSnapshot());
    nameBuilder.add(storageBackup.createBackupName());
    assertBackupCount(MAX_BACKUPS);
    assertEquals(MAX_BACKUPS + 1, storageBackup.getSuccesses().get());
    List<String> backupNames = nameBuilder.build();
    assertEquals(ImmutableSet.copyOf(backupNames.subList(1, backupNames.size())),
            FluentIterable.from(ImmutableList.copyOf(config.getDir().listFiles()))
                    .transform(StorageBackupImpl.FILE_NAME).toSet());
}

From source file:com.fujitsu.dc.core.odata.DcExpressionParser.java

private static void methodCall(List<Token> tokens, List<Token> rt, int i, String methodName, int k, int start,
        List<CommonExpression> methodArguments, int j) {
    List<Token> tokensIncludingParens = tokens.subList(k, j + 1);
    List<Token> tokensInsideParens = tokens.subList(start + 1, j);
    CommonExpression expressionInsideParens = readExpression(tokensInsideParens);
    methodArguments.add(expressionInsideParens);

    // method call expression: replace t mn ( t t , t t ) t with t et t
    CommonExpression methodCall = methodCall(methodName, methodArguments);

    ExpressionToken et = new ExpressionToken(methodCall, tokensIncludingParens);
    rt.subList(rt.size() - (i - k), rt.size()).clear();
    rt.add(et);/*from w w  w .  jav  a  2 s. co  m*/
}

From source file:edu.uci.ics.asterix.optimizer.rules.IntroduceSecondaryIndexInsertDeleteRule.java

public static ARecordType createEnforcedType(ARecordType initialType, Index index)
        throws AsterixException, AlgebricksException {
    ARecordType enforcedType = initialType;
    for (int i = 0; i < index.getKeyFieldNames().size(); i++) {
        try {//  w w  w .  j a v a  2 s  . c om
            Stack<Pair<ARecordType, String>> nestedTypeStack = new Stack<Pair<ARecordType, String>>();
            List<String> splits = index.getKeyFieldNames().get(i);
            ARecordType nestedFieldType = enforcedType;
            boolean openRecords = false;
            String bridgeName = nestedFieldType.getTypeName();
            int j;
            //Build the stack for the enforced type
            for (j = 1; j < splits.size(); j++) {
                nestedTypeStack.push(new Pair<ARecordType, String>(nestedFieldType, splits.get(j - 1)));
                bridgeName = nestedFieldType.getTypeName();
                nestedFieldType = (ARecordType) enforcedType.getSubFieldType(splits.subList(0, j));
                if (nestedFieldType == null) {
                    openRecords = true;
                    break;
                }
            }
            if (openRecords == true) {
                //create the smallest record
                enforcedType = new ARecordType(splits.get(splits.size() - 2),
                        new String[] { splits.get(splits.size() - 1) },
                        new IAType[] { AUnionType.createNullableType(index.getKeyFieldTypes().get(i)) }, true);
                //create the open part of the nested field
                for (int k = splits.size() - 3; k > (j - 2); k--) {
                    enforcedType = new ARecordType(splits.get(k), new String[] { splits.get(k + 1) },
                            new IAType[] { AUnionType.createNullableType(enforcedType) }, true);
                }
                //Bridge the gap
                Pair<ARecordType, String> gapPair = nestedTypeStack.pop();
                ARecordType parent = gapPair.first;

                IAType[] parentFieldTypes = ArrayUtils.addAll(parent.getFieldTypes().clone(),
                        new IAType[] { AUnionType.createNullableType(enforcedType) });
                enforcedType = new ARecordType(bridgeName,
                        ArrayUtils.addAll(parent.getFieldNames(), enforcedType.getTypeName()), parentFieldTypes,
                        true);

            } else {
                //Schema is closed all the way to the field
                //enforced fields are either null or strongly typed
                enforcedType = new ARecordType(nestedFieldType.getTypeName(),
                        ArrayUtils.addAll(nestedFieldType.getFieldNames(), splits.get(splits.size() - 1)),
                        ArrayUtils.addAll(nestedFieldType.getFieldTypes(),
                                AUnionType.createNullableType(index.getKeyFieldTypes().get(i))),
                        nestedFieldType.isOpen());
            }

            //Create the enforcedtype for the nested fields in the schema, from the ground up
            if (nestedTypeStack.size() > 0) {
                while (!nestedTypeStack.isEmpty()) {
                    Pair<ARecordType, String> nestedTypePair = nestedTypeStack.pop();
                    ARecordType nestedRecType = nestedTypePair.first;
                    IAType[] nestedRecTypeFieldTypes = nestedRecType.getFieldTypes().clone();
                    nestedRecTypeFieldTypes[nestedRecType
                            .findFieldPosition(nestedTypePair.second)] = enforcedType;
                    enforcedType = new ARecordType(nestedRecType.getTypeName(), nestedRecType.getFieldNames(),
                            nestedRecTypeFieldTypes, nestedRecType.isOpen());
                }
            }

        } catch (AsterixException e) {
            throw new AlgebricksException(
                    "Cannot enforce typed fields " + StringUtils.join(index.getKeyFieldNames()), e);
        } catch (IOException e) {
            throw new AsterixException(e);
        }
    }
    return enforcedType;
}

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

private String getFieldOverflowValue(int maximumLinesInField, List<String> lines) {
    return Joiner.on(NEWLINE).join(lines.subList(maximumLinesInField, lines.size()));
}

From source file:com.linuxbox.enkive.web.WebPageInfo.java

public List<?> getSubList(List<?> list) {
    List<?> subList;/*from   w w  w . j  a  v a 2s  .c  o  m*/
    if (((getPagePos() - 1) * getPageSize()) + getPageSize() < list.size())
        subList = list.subList(((getPagePos() - 1) * getPageSize()), ((getPagePos()) * getPageSize()));
    else
        subList = list.subList(((getPagePos() - 1) * getPageSize()), list.size());

    return subList;
}

From source file:backtype.storm.utils.VersionedStore.java

public void cleanup(int versionsToKeep) throws IOException {
    List<Long> versions = getAllVersions();
    if (versionsToKeep >= 0) {
        versions = versions.subList(0, Math.min(versions.size(), versionsToKeep));
    }//  w  w  w . ja  v a 2s. c o  m
    HashSet<Long> keepers = new HashSet<Long>(versions);

    for (String p : listDir(_root)) {
        Long v = parseVersion(p);
        if (v != null && !keepers.contains(v)) {
            deleteVersion(v);
        }
    }
}

From source file:com.baidu.rigel.biplatform.ma.resource.utils.DataModelUtils.java

/**
 * /*from  w w  w . jav  a 2 s. c  o  m*/
 * @param columnBasedData
 * @param needLimit
 * @param limitSize
 * @return
 */
private static List<List<CellData>> getColumnBasedDataCut(List<List<CellData>> columnBasedData,
        boolean needLimit, int limitSize) {
    if (!needLimit) {
        return columnBasedData;
    }

    List<List<CellData>> result = new ArrayList<List<CellData>>();

    for (List<CellData> currList : columnBasedData) {
        if (currList.size() > limitSize) {
            currList = currList.subList(0, limitSize);
        }
        if (needLimit && limitSize > 0 && result.size() >= limitSize) {
            break;
        }
        result.add(currList);

    }
    return result;
}